Skip to content

Commit ba48b35

Browse files
slusarzcmouse
authored andcommitted
markdown.js: Allow Dovecot markdown generated URLs to be rewritten
1 parent 64e9459 commit ba48b35

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const dovecotConfig = {
3131
plugin_paths: [
3232
'docs/core/plugins/*.md'
3333
],
34+
url_rewrite: false,
3435
watch_paths: [
3536
'docs/**/*.md',
3637
'docs/**/*.inc',

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ Paths are relative to project base.
232232

233233
Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
234234

235+
#### url_rewrite
236+
237+
A callback where Markdown generated URLs can be rewritten.
238+
Function is called the original URL and returns the (modified) URL.
239+
240+
Example: `url_rewrite: (url) => { return url + '.foo' }`
241+
235242
#### watch_paths
236243

237244
An array of file patterns to watch to refresh data loaders in dev mode.

lib/markdown.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,14 @@ function dovecot_markdown(md, opts) {
435435
}
436436

437437
function resolveURL(url) {
438-
return (opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
438+
if (!('url_rewrite' in opts)) {
439+
opts.url_rewrite = dovecotSetting('url_rewrite')
440+
}
441+
442+
const new_url =
443+
(opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
439444
'/' + url
445+
return (opts.url_rewrite) ? opts.url_rewrite(new_url) : new_url
440446
}
441447

442448
md.inline.ruler.after('emphasis', 'dovecot_brackets', process_brackets)

0 commit comments

Comments
 (0)