From 17afa16e33e934c7e73a95fca768444fe0b0ad43 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 23 Oct 2024 15:18:11 -0600 Subject: [PATCH 1/9] local.js: Move watch paths out of local config file --- .vitepress/config.js | 13 ++++++++++++- .vitepress/local.js.dist | 9 --------- README.md | 14 ++++++++++++++ lib/data/doveadm.data.js | 7 +++---- lib/data/event_categories.data.js | 7 +++---- lib/data/event_reasons.data.js | 7 +++---- lib/data/events.data.js | 7 +++---- lib/data/lua.data.js | 7 +++---- lib/data/settings.data.js | 7 +++---- lib/utility.js | 24 ++++++++---------------- 10 files changed, 52 insertions(+), 50 deletions(-) diff --git a/.vitepress/config.js b/.vitepress/config.js index b9f6082e0..6882328a7 100644 --- a/.vitepress/config.js +++ b/.vitepress/config.js @@ -12,6 +12,14 @@ const base = '/2.4' // processing will begin before Dovecot link markup is enabled await initDovecotMd(base) +export const dovecotConfig = { + watch_paths: [ + 'docs/**/*.md', + 'docs/**/*.inc', + 'data/**/*' + ] +} + export default defineConfig({ title: "Dovecot CE", description: "Dovecot CE Documentation", @@ -103,7 +111,10 @@ export default defineConfig({ gitrev: { align: 'right', hash: gitCommitInfo().shortHash, - } + }, + + /* Dovecot config. */ + dovecot: dovecotConfig, }, markdown: { diff --git a/.vitepress/local.js.dist b/.vitepress/local.js.dist index a43e56659..d2c668a37 100644 --- a/.vitepress/local.js.dist +++ b/.vitepress/local.js.dist @@ -13,15 +13,6 @@ export const data_paths = { // doveadm: '../data/doveadm.js', } -// A listing of files to watch to refresh data loaders in dev mode. -// See: https://vitepress.dev/guide/data-loading#data-from-local-files -// Paths are relative to project base. -// -// Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax -// -// Default: [ 'docs/**/*.md', 'docs/**/*.inc', 'data/**/*' ] -export const watch_paths = [] - // A listing of paths containing man files. // Paths are relative to project base. // diff --git a/README.md b/README.md index 18a6b4c34..809af4f6a 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,20 @@ The data files live in the base `/data` directory. Each file attempts to be self-documenting, but they are all essentially large JSON objects. Developers should need to know basically no JavaScript to be able to edit the files. +### Dovecot VitePress Configuration + +Additional configuration options required for VitePress static generation are +defined using the `dovecot` object in the `themeConfig` VitePress +configuration setting. + +#### watch_paths + +An array of file patterns to watch to refresh data loaders in dev mode. +See: https://vitepress.dev/guide/data-loading#data-from-local-files +Paths are relative to project base. + +Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax + ### Dovecot Markdown Extensions Markdown has been extended to allow various Dovecot-specific tasks to be diff --git a/lib/data/doveadm.data.js b/lib/data/doveadm.data.js index c76fd5e93..1c54c7e47 100644 --- a/lib/data/doveadm.data.js +++ b/lib/data/doveadm.data.js @@ -1,6 +1,6 @@ import { doveadm_arg_types, doveadm_flag_types, getDoveadmCmdLine } from '../doveadm.js' import { getVitepressMd } from '../markdown.js' -import { loadData, normalizeArrayData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js' import slugify from '@sindresorhus/slugify' const doveadm_userargs = { @@ -147,11 +147,10 @@ async function normalizeDoveadm(doveadm) { } } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { return await normalizeDoveadm( structuredClone((await loadData('doveadm')).doveadm) ) } -} +}) diff --git a/lib/data/event_categories.data.js b/lib/data/event_categories.data.js index 4e009ab4f..37edcb12a 100644 --- a/lib/data/event_categories.data.js +++ b/lib/data/event_categories.data.js @@ -1,5 +1,5 @@ import { getVitepressMd } from '../markdown.js' -import { loadData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData } from '../utility.js' async function normalizeEventCategories(categories) { const md = await getVitepressMd() @@ -11,11 +11,10 @@ async function normalizeEventCategories(categories) { return categories } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { return await normalizeEventCategories( structuredClone((await loadData('event_categories')).categories) ) } -} +}) diff --git a/lib/data/event_reasons.data.js b/lib/data/event_reasons.data.js index 9ddd930ac..5f3cdb11f 100644 --- a/lib/data/event_reasons.data.js +++ b/lib/data/event_reasons.data.js @@ -1,5 +1,5 @@ import { getVitepressMd } from '../markdown.js' -import { loadData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData } from '../utility.js' async function normalizeEventReasons(reasons) { const md = await getVitepressMd() @@ -11,11 +11,10 @@ async function normalizeEventReasons(reasons) { return reasons } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { return await normalizeEventReasons( structuredClone((await loadData('event_reasons')).reasons) ) } -} +}) diff --git a/lib/data/events.data.js b/lib/data/events.data.js index 82696b976..e3446f255 100644 --- a/lib/data/events.data.js +++ b/lib/data/events.data.js @@ -1,4 +1,4 @@ -import { loadData, normalizeArrayData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js' import { getVitepressMd } from '../markdown.js' /* Take the events list and normalize entries and process inheritance. */ @@ -124,8 +124,7 @@ async function normalizeEvents(events, global_inherits, inherits) { return events } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { const data = await loadData('events') return await normalizeEvents( @@ -134,4 +133,4 @@ export default { structuredClone(data.inherits) ) } -} +}) diff --git a/lib/data/lua.data.js b/lib/data/lua.data.js index 9490c5c87..363982f5f 100644 --- a/lib/data/lua.data.js +++ b/lib/data/lua.data.js @@ -1,5 +1,5 @@ import { getVitepressMd } from '../markdown.js' -import { loadData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData } from '../utility.js' async function normalizeLuaConstants(lua) { const md = await getVitepressMd() @@ -62,8 +62,7 @@ async function normalizeLuaVariables(lua) { return out } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { const data = await(loadData('lua')) @@ -73,4 +72,4 @@ export default { variables: await normalizeLuaVariables(data.lua_variables) } } -} +}) diff --git a/lib/data/settings.data.js b/lib/data/settings.data.js index 9311ee2a4..7df26c155 100644 --- a/lib/data/settings.data.js +++ b/lib/data/settings.data.js @@ -1,4 +1,4 @@ -import { loadData, normalizeArrayData, watchFiles } from '../utility.js' +import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js' import { getVitepressMd } from '../markdown.js' async function normalizeSettings(settings) { @@ -69,11 +69,10 @@ async function normalizeSettings(settings) { return data } -export default { - watch: await watchFiles(), +export default addWatchPaths({ async load() { return await normalizeSettings( structuredClone((await loadData('settings')).settings) ) } -} +}) diff --git a/lib/utility.js b/lib/utility.js index dbb5d10cf..997f199b2 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -66,26 +66,18 @@ export async function loadData(id) { } } -export async function watchFiles() { - /* Check for config override file. */ - const lconf = await loadLocalConf() - - return lconf?.watch_paths ?? - [ 'docs/**/*.md', 'docs/**/*.inc', 'data/**/*' ] -} +export function dovecotSetting(name) { + const setting = globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.[name] -export async function manFiles() { - /* Check for config override file. */ - const lconf = await loadLocalConf() + if (setting === undefined) { + throw new Error("Missing '" + name + "' setting") + } - return lconf?.man_paths ?? - [ 'docs/core/man/*.[[:digit:]].md' ] + return setting } -export async function manIncludes() { - const lconf = await loadLocalConf() - return lconf?.man_includes ?? - [ 'docs/core/man/include/*.inc' ] +export function addWatchPaths(obj) { + return { ...obj, ...{ watch: dovecotSetting('watch_paths') } } } export async function pluginFiles() { From cb963a82773249868c2b056ac63b9124cf35b514 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 28 Oct 2024 14:20:02 -0600 Subject: [PATCH 2/9] config.js: Move gitrev config into dovecot config namespace Since this is also Dovecot-specifc config, store in the same main namespace we will use for all other Dovecot specific config. --- .github/actions/spelling/expect.txt | 2 +- .vitepress/config.js | 10 ++++------ .vitepress/theme/DovecotLayout.vue | 4 ++-- README.md | 13 +++++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index d8176990d..75aedc35c 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -92,7 +92,6 @@ cnf cnrilrgfclra codahale codinghorror -coi CONDSTORE convertpw copybox @@ -247,6 +246,7 @@ gethosterror getmail getscript gitlab +gitrev Gluster gmatch gno diff --git a/.vitepress/config.js b/.vitepress/config.js index 6882328a7..92a97f646 100644 --- a/.vitepress/config.js +++ b/.vitepress/config.js @@ -13,6 +13,10 @@ const base = '/2.4' await initDovecotMd(base) export const dovecotConfig = { + gitrev: { + align: 'right', + hash: gitCommitInfo().shortHash, + }, watch_paths: [ 'docs/**/*.md', 'docs/**/*.inc', @@ -107,12 +111,6 @@ export default defineConfig({ { icon: 'github', link: 'https://github.com/dovecot/' }, ], - /* Dovecot specific config: return gitrev for this build. */ - gitrev: { - align: 'right', - hash: gitCommitInfo().shortHash, - }, - /* Dovecot config. */ dovecot: dovecotConfig, }, diff --git a/.vitepress/theme/DovecotLayout.vue b/.vitepress/theme/DovecotLayout.vue index c8d501309..9e7f603ca 100644 --- a/.vitepress/theme/DovecotLayout.vue +++ b/.vitepress/theme/DovecotLayout.vue @@ -10,9 +10,9 @@ const { Layout } = DefaultTheme