Revision: {{ theme.gitrev.hash }}
+Revision: {{ theme.dovecot.gitrev.hash }}
'
+ resolveURL('core/summaries/' + page + '.html#' + env.inner) +
+ '">'
case 'link':
let url = '#'
@@ -219,28 +198,31 @@ function dovecot_markdown(md, opts) {
hash = parts[2] ? parts[2] : false;
env.args = parts[3] ? parts[3] : 1;
+ initManFiles()
+
if (!opts.man.includes(env.inner)) {
handle_error('man link missing: ' + env.inner)
return ''
}
return ''
+ resolveURL('core/man/' + env.inner + '.' + env.args) +
+ '.html' + (hash ? '#' + hash : '') + '">'
case 'plugin':
env.inner = parts[1]
env.args = parts[2] ? parts[2] : undefined
const plugin = env.inner.replaceAll('-', '_')
+ initPluginFiles()
+
if (!opts.plugins.includes(plugin)) {
handle_error('plugin link missing: ' + env.inner)
return ''
}
return ''
+ resolveURL('core/plugins/' + plugin + '.html') + '">'
case 'removed':
env.args = parts[1]
@@ -292,10 +274,11 @@ function dovecot_markdown(md, opts) {
}
return ''
+ resolveURL('core/settings/variables.html' + hash) + '">'
default:
+ initMarkdownExtend()
+
return handle_default(mode,
opts.markdown?.open?.(mode, parts, opts, env))
}
@@ -409,7 +392,7 @@ function dovecot_markdown(md, opts) {
}
links[k] = {
- url: resolveURL(rewrites[f].substring(0, rewrites[f].lastIndexOf('.')) + '.html', opts.base)
+ url: resolveURL(rewrites[f].substring(0, rewrites[f].lastIndexOf('.')) + '.html')
}
if ((typeof v) == 'object') {
@@ -426,8 +409,46 @@ function dovecot_markdown(md, opts) {
opts.dovecotlinks = { ...links, ...opts.linkoverrides }
}
+ function initManFiles() {
+ if (!opts.man) {
+ opts.man = dovecotSetting('man_paths').flatMap((x) => {
+ return fg.sync(x).map((y) => {
+ const str = path.basename(y)
+ return str.substring(0, str.indexOf('.'))
+ })
+ })
+ }
+ }
+
+ function initMarkdownExtend() {
+ if (!opts.markdown) {
+ opts.markdown = dovecotSetting('markdown_extend') ?? {}
+ }
+ }
+
+ function initPluginFiles() {
+ if (!opts.plugins) {
+ opts.plugins = dovecotSetting('plugin_paths').flatMap((x) =>
+ fg.sync(x).map((y) => path.basename(y, '.md'))
+ )
+ }
+ }
+
+ function resolveURL(url) {
+ if (!('url_rewrite' in opts)) {
+ opts.url_rewrite = dovecotSetting('url_rewrite')
+ }
+
+ const new_url =
+ (opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
+ '/' + url
+ return (opts.url_rewrite) ? opts.url_rewrite(new_url) : new_url
+ }
+
md.inline.ruler.after('emphasis', 'dovecot_brackets', process_brackets)
md.renderer.rules.dovecot_open = dovecot_open
md.renderer.rules.dovecot_body = dovecot_body
md.renderer.rules.dovecot_close = dovecot_close
+
+ opts.resolveURL = resolveURL
}
diff --git a/lib/utility.js b/lib/utility.js
index dbb5d10cf..185f5385d 100644
--- a/lib/utility.js
+++ b/lib/utility.js
@@ -9,8 +9,6 @@ import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-const local_conf_path = __dirname + '/../.vitepress/local.js'
-
export function normalizeArrayData(data, keys) {
for (const [k, v] of Object.entries(data)) {
if (v) {
@@ -28,35 +26,9 @@ export function normalizeArrayData(data, keys) {
return data
}
-let local_conf = null
-async function loadLocalConf() {
- if (local_conf === null) {
- if (fs.existsSync(local_conf_path)) {
- local_conf = await import(local_conf_path)
- } else {
- local_conf = false
- }
- }
-
- return local_conf
-}
-
-export async function markdownExtension() {
- const lconf = await loadLocalConf()
-
- return {
- ...{
- markdown: lconf.markdown_extend ?? {},
- },
- ...(lconf.markdown_extend?.init?.() ?? {})
- }
-}
-
export async function loadData(id) {
- /* Check for config override file. */
- const lconf = await loadLocalConf()
- const path = lconf?.data_paths?.[id] ??
- ('../data/' + id + '.js')
+ const path = globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.data_paths?.[id]
+ ?? ('../data/' + id + '.js')
try {
return await import(__dirname + '/' + path)
@@ -66,34 +38,31 @@ export async function loadData(id) {
}
}
-export async function watchFiles() {
- /* Check for config override file. */
- const lconf = await loadLocalConf()
+function _dovecotSetting(name, setting) {
+ if (setting === undefined) {
+ throw new Error("Missing '" + name + "' setting")
+ }
- return lconf?.watch_paths ??
- [ 'docs/**/*.md', 'docs/**/*.inc', 'data/**/*' ]
+ return setting
}
-export async function manFiles() {
- /* Check for config override file. */
- const lconf = await loadLocalConf()
-
- return lconf?.man_paths ??
- [ 'docs/core/man/*.[[:digit:]].md' ]
+/* Bootstrap the configuration by reading the .vitepress/config.js file. */
+export async function dovecotSettingBootstrap(name) {
+ return _dovecotSetting(
+ name,
+ (await import(process.cwd() + '/.vitepress/config.js')).dovecotConfig?.[name]
+ )
}
-export async function manIncludes() {
- const lconf = await loadLocalConf()
- return lconf?.man_includes ??
- [ 'docs/core/man/include/*.inc' ]
+export function dovecotSetting(name) {
+ return _dovecotSetting(
+ name,
+ globalThis.VITEPRESS_CONFIG.userConfig.themeConfig.dovecot?.[name]
+ )
}
-export async function pluginFiles() {
- /* Check for config override file. */
- const lconf = await loadLocalConf()
-
- return lconf?.plugin_paths ??
- [ 'docs/core/plugins/*.md' ]
+export function addWatchPaths(obj) {
+ return { ...obj, ...{ watch: dovecotSetting('watch_paths') } }
}
export function getExcludes(srcDirs = [ 'docs' ]) {
@@ -124,7 +93,3 @@ export function frontmatterIter(files, callback) {
}
}
}
-
-export function resolveURL(url, base) {
- return (base.endsWith('/') ? base.slice(0, -1) : base) + '/' + url
-}
diff --git a/util/generate_man.js b/util/generate_man.js
index a9e566775..dcf3ebd3b 100755
--- a/util/generate_man.js
+++ b/util/generate_man.js
@@ -14,7 +14,7 @@ import matter from 'gray-matter'
import pdc from 'pdc'
import path from 'path'
import { VFile } from 'vfile'
-import { manFiles, manIncludes } from '../lib/utility.js'
+import { dovecotSettingBootstrap } from '../lib/utility.js'
import remarkDeflist from 'remark-definition-list'
import remarkMan from 'remark-man'
import remarkParse from 'remark-parse'
@@ -43,7 +43,6 @@ program
const debug = program.opts().debug
-
const doInclude = (content, includes, f) => {
const result = content.replace(includesRE, (m, m1) => {
if (!m1.length) return m
@@ -126,8 +125,10 @@ const main = async (component, outPath) => {
}
/* Generate list of man files. */
- const files = (await manFiles()).flatMap((x) => fg.sync(x))
- const includes = (await manIncludes()).flatMap((x) => fg.sync(x))
+ const files = (await dovecotSettingBootstrap('man_paths'))
+ .flatMap((x) => fg.sync(x))
+ const includes = (await dovecotSettingBootstrap('man_includes'))
+ .flatMap((x) => fg.sync(x))
/* Get hash of last git commit. */
const gitHash = gitCommitInfo().shortHash