Skip to content

Commit 63d0208

Browse files
committed
local.js: Move watch paths out of local config file
1 parent ae9996b commit 63d0208

File tree

10 files changed

+49
-49
lines changed

10 files changed

+49
-49
lines changed

.vitepress/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ export default defineConfig({
103103
gitrev: {
104104
align: 'right',
105105
hash: gitCommitInfo().shortHash,
106+
},
107+
108+
/* Dovecot VitePress paths. */
109+
dovecot: {
110+
watch_paths: [
111+
'docs/**/*.md',
112+
'docs/**/*.inc',
113+
'data/**/*'
114+
]
106115
}
107116
},
108117

.vitepress/local.js.dist

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ export const data_paths = {
1313
// doveadm: '../data/doveadm.js',
1414
}
1515

16-
// A listing of files to watch to refresh data loaders in dev mode.
17-
// See: https://vitepress.dev/guide/data-loading#data-from-local-files
18-
// Paths are relative to project base.
19-
//
20-
// Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
21-
//
22-
// Default: [ 'docs/**/*.md', 'docs/**/*.inc', 'data/**/*' ]
23-
export const watch_paths = []
24-
2516
// A listing of paths containing man files.
2617
// Paths are relative to project base.
2718
//

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ The data files live in the base `/data` directory. Each file attempts to be
158158
self-documenting, but they are all essentially large JSON objects. Developers
159159
should need to know basically no JavaScript to be able to edit the files.
160160

161+
### Dovecot VitePress Configuration
162+
163+
Additional configuration options required for VitePress static generation are
164+
defined using the `dovecot` object in the `themeConfig` VitePress
165+
configuration setting.
166+
167+
#### watch_paths
168+
169+
An array of file patterns to watch to refresh data loaders in dev mode.
170+
See: https://vitepress.dev/guide/data-loading#data-from-local-files
171+
Paths are relative to project base.
172+
173+
Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
174+
161175
### Dovecot Markdown Extensions
162176

163177
Markdown has been extended to allow various Dovecot-specific tasks to be

lib/data/doveadm.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { doveadm_arg_types, doveadm_flag_types, getDoveadmCmdLine } from '../doveadm.js'
22
import { getVitepressMd } from '../markdown.js'
3-
import { loadData, normalizeArrayData, watchFiles } from '../utility.js'
3+
import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js'
44
import slugify from '@sindresorhus/slugify'
55

66
const doveadm_userargs = {
@@ -147,11 +147,10 @@ async function normalizeDoveadm(doveadm) {
147147
}
148148
}
149149

150-
export default {
151-
watch: await watchFiles(),
150+
export default addWatchPaths({
152151
async load() {
153152
return await normalizeDoveadm(
154153
structuredClone((await loadData('doveadm')).doveadm)
155154
)
156155
}
157-
}
156+
})

lib/data/event_categories.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getVitepressMd } from '../markdown.js'
2-
import { loadData, watchFiles } from '../utility.js'
2+
import { addWatchPaths, loadData } from '../utility.js'
33

44
async function normalizeEventCategories(categories) {
55
const md = await getVitepressMd()
@@ -11,11 +11,10 @@ async function normalizeEventCategories(categories) {
1111
return categories
1212
}
1313

14-
export default {
15-
watch: await watchFiles(),
14+
export default addWatchPaths({
1615
async load() {
1716
return await normalizeEventCategories(
1817
structuredClone((await loadData('event_categories')).categories)
1918
)
2019
}
21-
}
20+
})

lib/data/event_reasons.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getVitepressMd } from '../markdown.js'
2-
import { loadData, watchFiles } from '../utility.js'
2+
import { addWatchPaths, loadData } from '../utility.js'
33

44
async function normalizeEventReasons(reasons) {
55
const md = await getVitepressMd()
@@ -11,11 +11,10 @@ async function normalizeEventReasons(reasons) {
1111
return reasons
1212
}
1313

14-
export default {
15-
watch: await watchFiles(),
14+
export default addWatchPaths({
1615
async load() {
1716
return await normalizeEventReasons(
1817
structuredClone((await loadData('event_reasons')).reasons)
1918
)
2019
}
21-
}
20+
})

lib/data/events.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loadData, normalizeArrayData, watchFiles } from '../utility.js'
1+
import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js'
22
import { getVitepressMd } from '../markdown.js'
33

44
/* Take the events list and normalize entries and process inheritance. */
@@ -124,8 +124,7 @@ async function normalizeEvents(events, global_inherits, inherits) {
124124
return events
125125
}
126126

127-
export default {
128-
watch: await watchFiles(),
127+
export default addWatchPaths({
129128
async load() {
130129
const data = await loadData('events')
131130
return await normalizeEvents(
@@ -134,4 +133,4 @@ export default {
134133
structuredClone(data.inherits)
135134
)
136135
}
137-
}
136+
})

lib/data/lua.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getVitepressMd } from '../markdown.js'
2-
import { loadData, watchFiles } from '../utility.js'
2+
import { addWatchPaths, loadData } from '../utility.js'
33

44
async function normalizeLuaConstants(lua) {
55
const md = await getVitepressMd()
@@ -62,8 +62,7 @@ async function normalizeLuaVariables(lua) {
6262
return out
6363
}
6464

65-
export default {
66-
watch: await watchFiles(),
65+
export default addWatchPaths({
6766
async load() {
6867
const data = await(loadData('lua'))
6968

@@ -73,4 +72,4 @@ export default {
7372
variables: await normalizeLuaVariables(data.lua_variables)
7473
}
7574
}
76-
}
75+
})

lib/data/settings.data.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loadData, normalizeArrayData, watchFiles } from '../utility.js'
1+
import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js'
22
import { getVitepressMd } from '../markdown.js'
33

44
async function normalizeSettings(settings) {
@@ -69,11 +69,10 @@ async function normalizeSettings(settings) {
6969
return data
7070
}
7171

72-
export default {
73-
watch: await watchFiles(),
72+
export default addWatchPaths({
7473
async load() {
7574
return await normalizeSettings(
7675
structuredClone((await loadData('settings')).settings)
7776
)
7877
}
79-
}
78+
})

lib/utility.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,18 @@ export async function loadData(id) {
6666
}
6767
}
6868

69-
export async function watchFiles() {
70-
/* Check for config override file. */
71-
const lconf = await loadLocalConf()
72-
73-
return lconf?.watch_paths ??
74-
[ 'docs/**/*.md', 'docs/**/*.inc', 'data/**/*' ]
75-
}
69+
export function dovecotSetting(name) {
70+
const setting = globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.[name]
7671

77-
export async function manFiles() {
78-
/* Check for config override file. */
79-
const lconf = await loadLocalConf()
72+
if (setting === undefined) {
73+
throw new Error("Missing '" + name + "' setting")
74+
}
8075

81-
return lconf?.man_paths ??
82-
[ 'docs/core/man/*.[[:digit:]].md' ]
76+
return setting
8377
}
8478

85-
export async function manIncludes() {
86-
const lconf = await loadLocalConf()
87-
return lconf?.man_includes ??
88-
[ 'docs/core/man/include/*.inc' ]
79+
export function addWatchPaths(obj) {
80+
return { ...obj, ...{ watch: dovecotSetting('watch_paths') } }
8981
}
9082

9183
export async function pluginFiles() {

0 commit comments

Comments
 (0)