1- import { defineConfig } from 'vitepress'
1+ import { defineConfig , HeadConfig } from 'vitepress'
22import markdownItFootnote from 'markdown-it-footnote'
33import { withMermaid } from "vitepress-plugin-mermaid" ;
44import blogSidebar from './theme/blog-sidebar' ;
@@ -12,6 +12,14 @@ const BASE = process.env.VP_BASE || '/'
1212if ( ! path . posix . isAbsolute ( BASE ) ) {
1313 throw new Error ( `Base path '${ BASE } ' must be absolute, check environment variable VP_BASE` ) ;
1414}
15+ const resolveAbsoluteUrl = ( relativeUrl : string ) => {
16+ const domain = process . env . VP_DOMAIN
17+ if ( domain ) {
18+ return new URL ( relativeUrl , domain ) . toString ( )
19+ } else {
20+ return path . posix . resolve ( BASE , relativeUrl )
21+ }
22+ }
1523
1624// https://vitepress.dev/reference/site-config
1725export default withMermaid ( defineConfig ( {
@@ -122,7 +130,12 @@ export default withMermaid(defineConfig({
122130 ` . trim ( ) )
123131 }
124132
125- const hasH1 = / ^ \s * # \s + .+ / m. test ( content )
133+ // we check if the first n(200) characters contain the
134+ // Markdown for h1. note that the same sequence may show
135+ // up regularly in e.g. YAML comments in codeblocks, messing
136+ // with the logic. so we just hope no one uses this so early
137+ // in a document.
138+ const hasH1 = / ^ \s * # \s + .+ / m. test ( content . slice ( 0 , 200 ) )
126139 if ( data . title && ! hasH1 ) {
127140 injectedChunks . unshift ( `# ${ data . title } ` )
128141 }
@@ -137,5 +150,23 @@ export default withMermaid(defineConfig({
137150 }
138151 ]
139152 } ,
140- ignoreDeadLinks : false
153+ ignoreDeadLinks : false ,
154+ transformHead : ( { pageData } ) => {
155+ const title = ( ( ) => {
156+ if ( pageData . frontmatter . title ) {
157+ return `${ pageData . frontmatter . title } | Apeiro Reference Architecture`
158+ } else if ( pageData . title ) {
159+ return `${ pageData . title } | Apeiro Reference Architecture`
160+ } else {
161+ return 'Apeiro Reference Architecture'
162+ }
163+ } ) ( )
164+ const head : HeadConfig [ ] = [
165+ [ 'meta' , { property : 'og:title' , content : title } ] ,
166+ [ 'meta' , { property : 'og:description' , content : pageData . description || '' } ] ,
167+ [ 'meta' , { property : 'og:url' , content : resolveAbsoluteUrl ( pageData . relativePath . replace ( 'index.md' , '' ) . replace ( '.md' , '' ) ) } ] ,
168+ [ 'meta' , { property : 'og:image' , content : resolveAbsoluteUrl ( './img/og-image.png' ) } ] ,
169+ ]
170+ return head
171+ }
141172} ) )
0 commit comments