Skip to content

Commit 7c44819

Browse files
committed
local.js: Move markdown_extend out of local config file
1 parent 2d95c68 commit 7c44819

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

.vitepress/local.js.dist

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,3 @@
1212
export const data_paths = {
1313
// doveadm: '../data/doveadm.js',
1414
}
15-
16-
// Enable additional labels to support in Dovecot-specific markdown
17-
// processing (i.e. [[xyz,...]]).
18-
export const markdown_extend = {
19-
20-
// Init function. Return value is configuration options to add to markdown
21-
// object.
22-
// init: () => { return {} },
23-
24-
// Opening tag function. Returns opening tag.
25-
// open: (mode, parts, opts, env) => { return '' },
26-
27-
// Body function. Returns body text.
28-
// body: (mode, env) => { return '' },
29-
30-
// Close tag function. Returns closing tag.
31-
// close: (mode, env) => { return '' },
32-
33-
}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ Paths are relative to project base.
175175

176176
Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
177177

178+
#### markdown_extend
179+
180+
An object containing callbacks that enable additional labels to support in
181+
Dovecot-specific markdown processing (i.e. [[xyz,...]]).
182+
183+
##### open
184+
185+
Opening tag function. Returns opening tag.
186+
187+
Example: `open: (mode, parts, opts, env) => { return '' }`
188+
189+
##### body
190+
191+
Body function. Returns body text.
192+
193+
Example: `body: (mode, env) => { return '' }`
194+
195+
##### close
196+
197+
Close tag function. Returns closing tag.
198+
199+
Example: `close: (mode, env) => { return '' }`
200+
178201
#### plugin_paths
179202

180203
A listing of paths containing plugin files.

lib/markdown.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ export async function initDovecotMd(base) {
1212
}
1313

1414
md_conf = {
15-
...{
16-
base: base,
17-
doveadm: (await loadData('doveadm')).doveadm,
18-
events: (await loadData('events')).events,
19-
linkoverrides: (await loadData('links_overrides')).links_overrides,
20-
settings: (await loadData('settings')).settings,
21-
updates: (await loadData('updates')).updates
22-
},
23-
...(await markdownExtension())
15+
base: base,
16+
doveadm: (await loadData('doveadm')).doveadm,
17+
events: (await loadData('events')).events,
18+
linkoverrides: (await loadData('links_overrides')).links_overrides,
19+
settings: (await loadData('settings')).settings,
20+
updates: (await loadData('updates')).updates
2421
}
2522
}
2623

@@ -291,6 +288,8 @@ function dovecot_markdown(md, opts) {
291288
opts.base) + '">'
292289

293290
default:
291+
initMarkdownExtend()
292+
294293
return handle_default(mode,
295294
opts.markdown?.open?.(mode, parts, opts, env))
296295
}
@@ -432,6 +431,12 @@ function dovecot_markdown(md, opts) {
432431
}
433432
}
434433

434+
function initMarkdownExtend() {
435+
if (!opts.markdown) {
436+
opts.markdown = markdownExtension()
437+
}
438+
}
439+
435440
function initPluginFiles() {
436441
if (!opts.plugins) {
437442
opts.plugins = pluginFiles().flatMap((x) =>

lib/utility.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ async function loadLocalConf() {
4141
return local_conf
4242
}
4343

44-
export async function markdownExtension() {
45-
const lconf = await loadLocalConf()
46-
47-
return {
48-
...{
49-
markdown: lconf.markdown_extend ?? {},
50-
},
51-
...(lconf.markdown_extend?.init?.() ?? {})
52-
}
44+
export function markdownExtension() {
45+
return globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.markdown_extend
46+
?? {}
5347
}
5448

5549
export async function loadData(id) {

0 commit comments

Comments
 (0)