@@ -5,20 +5,16 @@ import path from 'path'
5
5
import { createMarkdownRenderer } from 'vitepress'
6
6
import { loadData , loadDovecotLinks , manFiles , pluginFiles , resolveURL } from './utility.js'
7
7
8
- export async function dovecotMdExtend ( md ) {
9
- md . use ( containerPlugin , 'todo' , {
10
- render : function ( tokens , idx ) {
11
- if ( tokens [ idx ] . nesting === 1 ) {
12
- return '<div class="caution custom-block">\n<p class="custom-block-title">⚠️ TODO</p>'
13
- } else {
14
- return '</div>\n'
15
- }
16
- }
17
- } )
18
- md . use ( deflistPlugin )
19
- md . use ( dovecot_markdown , {
8
+ let md_conf = null
9
+ export async function initDovecotMd ( base ) {
10
+ if ( md_conf !== null ) {
11
+ return
12
+ }
13
+
14
+ md_conf = {
15
+ base : base ,
20
16
doveadm : ( await loadData ( 'doveadm' ) ) . doveadm ,
21
- dovecotlinks : await loadDovecotLinks ( ) ,
17
+ dovecotlinks : await loadDovecotLinks ( base ) ,
22
18
events : ( await loadData ( 'events' ) ) . events ,
23
19
man : ( await manFiles ( ) ) . flatMap ( ( x ) => {
24
20
return fg . sync ( x ) . map ( ( y ) => {
@@ -31,18 +27,36 @@ export async function dovecotMdExtend(md) {
31
27
) ,
32
28
settings : ( await loadData ( 'settings' ) ) . settings ,
33
29
updates : ( await loadData ( 'updates' ) ) . updates
30
+ }
31
+ }
32
+
33
+ export function dovecotMdExtend ( md ) {
34
+ md . use ( containerPlugin , 'todo' , {
35
+ render : function ( tokens , idx ) {
36
+ if ( tokens [ idx ] . nesting === 1 ) {
37
+ return '<div class="caution custom-block">\n<p class="custom-block-title">⚠️ TODO</p>'
38
+ } else {
39
+ return '</div>\n'
40
+ }
41
+ }
34
42
} )
43
+ md . use ( deflistPlugin )
44
+
45
+ if ( md_conf === null ) {
46
+ throw new Error ( 'Must call initDovecotMd() before calling this function!' )
47
+ }
48
+ md . use ( dovecot_markdown , md_conf )
35
49
36
50
return md
37
51
}
38
52
39
53
let vitepress_md = null
40
-
41
54
export async function getVitepressMd ( ) {
42
55
if ( vitepress_md === null ) {
43
56
const config = globalThis . VITEPRESS_CONFIG
44
57
45
- vitepress_md = await dovecotMdExtend ( await createMarkdownRenderer (
58
+ await initDovecotMd ( config . site . base )
59
+ vitepress_md = dovecotMdExtend ( await createMarkdownRenderer (
46
60
config . srcDir ,
47
61
config . markdown ,
48
62
config . site . base ,
@@ -173,8 +187,8 @@ function dovecot_markdown(md, opts) {
173
187
}
174
188
175
189
return '<code><a href="' +
176
- resolveURL ( 'core/summaries/' + page + '.html#' + env . inner ) +
177
- '">'
190
+ resolveURL ( 'core/summaries/' + page + '.html#' + env . inner ,
191
+ opts . base ) + '">'
178
192
179
193
case 'link' :
180
194
let url = '#'
@@ -199,8 +213,8 @@ function dovecot_markdown(md, opts) {
199
213
}
200
214
201
215
return '<code><a href="' +
202
- resolveURL ( 'core/man/' + env . inner + '.' + env . args ) +
203
- '.html' + ( hash ? '#' + hash : '' ) + '">'
216
+ resolveURL ( 'core/man/' + env . inner + '.' + env . args ,
217
+ opts . base ) + '.html' + ( hash ? '#' + hash : '' ) + '">'
204
218
205
219
case 'plugin' :
206
220
env . inner = parts [ 1 ]
@@ -212,7 +226,7 @@ function dovecot_markdown(md, opts) {
212
226
213
227
return '<a href="' +
214
228
resolveURL ( 'core/plugins/' + plugin + '.html' +
215
- ( parts [ 2 ] ? '#' + parts [ 2 ] : '' ) ) + '">'
229
+ ( parts [ 2 ] ? '#' + parts [ 2 ] : '' ) , opts . base ) + '">'
216
230
217
231
case 'removed' :
218
232
env . args = parts [ 1 ]
@@ -264,7 +278,8 @@ function dovecot_markdown(md, opts) {
264
278
}
265
279
266
280
return '<code><a href="' +
267
- resolveURL ( 'core/settings/variables.html' + hash ) + '">'
281
+ resolveURL ( 'core/settings/variables.html' + hash ,
282
+ opts . base ) + '">'
268
283
269
284
default :
270
285
throw new Error ( 'Unknown dovecot markdown command: ' + mode )
0 commit comments