diff --git a/lib/data/auth_databases.data.js b/lib/data/auth_databases.data.js index f54b19c30..b123c1d03 100644 --- a/lib/data/auth_databases.data.js +++ b/lib/data/auth_databases.data.js @@ -1,10 +1,9 @@ -import { createContentLoader } from 'vitepress' +import { createContentLoader } from '../utility.js' -export default createContentLoader('docs/core/config/auth/databases/*.md', { +export default createContentLoader('**/core/config/auth/databases/!(index|overview).md', { includeSrc: false, transform(raw) { return raw - .filter(({ url }) => !url.endsWith('index.html') && !url.endsWith('overview.html') && !url.endsWith('/')) .map(({ url, frontmatter }) => { return { title: frontmatter.title || url.split('/').pop().replace('.html', ''), diff --git a/lib/utility.js b/lib/utility.js index 1caf116e9..db7fe3d27 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -5,6 +5,7 @@ import fs from 'fs' import matter from 'gray-matter' import { dirname } from 'path' import { fileURLToPath } from 'url' +import { createContentLoader as vpCreateContentLoader } from 'vitepress' import { logger } from './logger.js' const __filename = fileURLToPath(import.meta.url) @@ -71,6 +72,31 @@ export function addWatchPaths(obj) { return { ...obj, ...{ watch: dovecotSetting('watch_paths') } } } +export function createContentLoader(pattern, options = {}) { + const { transform, ...rest } = options + + return vpCreateContentLoader(pattern, { + ...rest, + transform(raw) { + const rewrites = globalThis.VITEPRESS_CONFIG?.rewrites?.map + const cleanUrls = globalThis.VITEPRESS_CONFIG?.cleanUrls + + const data = rewrites + ? raw.map((item) => { + const src = (item.url.slice(1).replace(/\.html$/, '').replace(/\/$/, '/index') || 'index') + '.md' + const rewritten = rewrites[src] + if (rewritten) { + item.url = '/' + rewritten.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, cleanUrls ? '' : '.html') + } + return item + }) + : raw + + return transform ? transform(data) : data + } + }) +} + export function getExcludes(srcDirs = [ 'docs' ]) { const excludes = []