@@ -3,7 +3,7 @@ import fg from 'fast-glob'
33import deflistPlugin from 'markdown-it-deflist'
44import path from 'path'
55import { createMarkdownRenderer } from 'vitepress'
6- import { dovecotSetting , frontmatterIter , loadData , resolveURL } from './utility.js'
6+ import { dovecotSetting , frontmatterIter , loadData } from './utility.js'
77
88let md_conf = null
99export async function dovecotMdExtend ( md ) {
@@ -174,8 +174,8 @@ function dovecot_markdown(md, opts) {
174174 }
175175
176176 return '<code><a href="' +
177- resolveURL ( 'core/summaries/' + page + '.html#' + env . inner ,
178- opts . base ) + '">'
177+ resolveURL ( 'core/summaries/' + page + '.html#' + env . inner ) +
178+ '">'
179179
180180 case 'link' :
181181 let url = '#'
@@ -206,8 +206,8 @@ function dovecot_markdown(md, opts) {
206206 }
207207
208208 return '<code><a href="' +
209- resolveURL ( 'core/man/' + env . inner + '.' + env . args ,
210- opts . base ) + '.html' + ( hash ? '#' + hash : '' ) + '">'
209+ resolveURL ( 'core/man/' + env . inner + '.' + env . args ) +
210+ '.html' + ( hash ? '#' + hash : '' ) + '">'
211211
212212 case 'plugin' :
213213 env . inner = parts [ 1 ]
@@ -222,8 +222,7 @@ function dovecot_markdown(md, opts) {
222222 }
223223
224224 return '<a href="' +
225- resolveURL ( 'core/plugins/' + plugin + '.html' , opts . base ) +
226- '">'
225+ resolveURL ( 'core/plugins/' + plugin + '.html' ) + '">'
227226
228227 case 'removed' :
229228 env . args = parts [ 1 ]
@@ -275,8 +274,7 @@ function dovecot_markdown(md, opts) {
275274 }
276275
277276 return '<code><a href="' +
278- resolveURL ( 'core/settings/variables.html' + hash ,
279- opts . base ) + '">'
277+ resolveURL ( 'core/settings/variables.html' + hash ) + '">'
280278
281279 default :
282280 initMarkdownExtend ( )
@@ -394,7 +392,7 @@ function dovecot_markdown(md, opts) {
394392 }
395393
396394 links [ k ] = {
397- url : resolveURL ( rewrites [ f ] . substring ( 0 , rewrites [ f ] . lastIndexOf ( '.' ) ) + '.html' , opts . base )
395+ url : resolveURL ( rewrites [ f ] . substring ( 0 , rewrites [ f ] . lastIndexOf ( '.' ) ) + '.html' )
398396 }
399397
400398 if ( ( typeof v ) == 'object' ) {
@@ -436,8 +434,15 @@ function dovecot_markdown(md, opts) {
436434 }
437435 }
438436
437+ function resolveURL ( url ) {
438+ return ( opts . base . endsWith ( '/' ) ? opts . base . slice ( 0 , - 1 ) : opts . base ) +
439+ '/' + url
440+ }
441+
439442 md . inline . ruler . after ( 'emphasis' , 'dovecot_brackets' , process_brackets )
440443 md . renderer . rules . dovecot_open = dovecot_open
441444 md . renderer . rules . dovecot_body = dovecot_body
442445 md . renderer . rules . dovecot_close = dovecot_close
446+
447+ opts . resolveURL = resolveURL
443448}
0 commit comments