Skip to content

Commit ce6034f

Browse files
committed
local.js: Move data_paths out of local config file
1 parent 7d82868 commit ce6034f

File tree

5 files changed

+23
-43
lines changed

5 files changed

+23
-43
lines changed

.vitepress/config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import gitCommitInfo from 'git-commit-info'
22
import { defineConfig } from 'vitepress'
33
import { pagefindPlugin } from 'vitepress-plugin-pagefind'
44
import { generateSidebar } from 'vitepress-sidebar'
5-
import { dovecotMdExtend, initDovecotMd } from '../lib/markdown.js'
5+
import { dovecotMdExtend } from '../lib/markdown.js'
66
import { getExcludes } from '../lib/utility.js'
77

88
const base = '/2.4'
99

10-
// Need to bootstrap configuration for Dovecot markdown driver (specifically,
11-
// loading all data files to allow existence checking), or else the markdown
12-
// processing will begin before Dovecot link markup is enabled
13-
await initDovecotMd(base)
14-
1510
export default defineConfig({
1611
title: "Dovecot CE",
1712
description: "Dovecot CE Documentation",
@@ -107,7 +102,7 @@ export default defineConfig({
107102
},
108103

109104
markdown: {
110-
config: (md) => dovecotMdExtend(md),
105+
config: async (md) => await dovecotMdExtend(md),
111106
image: {
112107
lazyLoading: true,
113108
},

.vitepress/local.js.dist

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ should need to know basically no JavaScript to be able to edit the files.
163163
Various paths used for VitePress static generation can be overridden using
164164
the `dovecot` object in the `themeConfig` VitePress configuration setting.
165165

166+
#### data_paths
167+
168+
Allows custom mapping of data sources.
169+
170+
It is used by the VitePress data loaders to determine what data to
171+
load for export.
172+
173+
Keys are data identifiers, Values are location RELATIVE TO `<base>/lib`
174+
DIRECTORY.
175+
166176
#### man_includes
167177

168178
A list of additional paths (other than the `include/` directory of the man

lib/markdown.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,7 @@ import { createMarkdownRenderer } from 'vitepress'
66
import { frontmatterIter, loadData, manFiles, markdownExtension, pluginFiles, resolveURL } from './utility.js'
77

88
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,
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
21-
}
22-
}
23-
24-
export function dovecotMdExtend(md) {
9+
export async function dovecotMdExtend(md) {
2510
md.use(containerPlugin, 'todo', {
2611
render: function(tokens, idx) {
2712
if (tokens[idx].nesting === 1) {
@@ -34,7 +19,14 @@ export function dovecotMdExtend(md) {
3419
md.use(deflistPlugin)
3520

3621
if (md_conf === null) {
37-
throw new Error('Must call initDovecotMd() before calling this function!')
22+
md_conf = {
23+
base: globalThis.VITEPRESS_CONFIG.site.base,
24+
doveadm: (await loadData('doveadm')).doveadm,
25+
events: (await loadData('events')).events,
26+
linkoverrides: (await loadData('links_overrides')).links_overrides,
27+
settings: (await loadData('settings')).settings,
28+
updates: (await loadData('updates')).updates
29+
}
3830
}
3931
md.use(dovecot_markdown, md_conf)
4032

@@ -46,8 +38,7 @@ export async function getVitepressMd() {
4638
if (vitepress_md === null) {
4739
const config = globalThis.VITEPRESS_CONFIG
4840

49-
await initDovecotMd(config.site.base)
50-
vitepress_md = dovecotMdExtend(await createMarkdownRenderer(
41+
vitepress_md = await dovecotMdExtend(await createMarkdownRenderer(
5142
config.srcDir,
5243
config.markdown,
5344
config.site.base,

lib/utility.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ export function markdownExtension() {
4747
}
4848

4949
export async function loadData(id) {
50-
/* Check for config override file. */
51-
const lconf = await loadLocalConf()
52-
const path = lconf?.data_paths?.[id] ??
50+
const path = globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.data_paths?.[id] ??
5351
('../data/' + id + '.js')
5452

5553
try {

0 commit comments

Comments
 (0)