diff --git a/src/core/module.ts b/src/core/module.ts index 1202e7d24..78e292a29 100644 --- a/src/core/module.ts +++ b/src/core/module.ts @@ -92,7 +92,9 @@ export default async function docusModule() { drivers: [ { base: resolve(options.srcDir, $docus.settings.contentDir), + // mount point of driver mountPoint: 'pages', + // List of Nuxt ignore rules ignore: await useNuxtIgnoreList(nuxt) }, { diff --git a/src/core/parser/index.ts b/src/core/parser/index.ts index 95d980765..178c5084a 100644 --- a/src/core/parser/index.ts +++ b/src/core/parser/index.ts @@ -17,6 +17,14 @@ export function initParser(options: Partial = {}) { export function useParser() { return { + /** + * The list of all extensions that have specific parser in Docus + * @returns list of valid extensions + */ + extensions() { + return Object.keys(parsers) + }, + parse: async (file, content) => { const extension = extname(file) const path = '/' + file.replace(new RegExp(`${extension}$`), '') diff --git a/src/core/storage/driver.ts b/src/core/storage/driver.ts index c8f2ab46f..1391d9474 100644 --- a/src/core/storage/driver.ts +++ b/src/core/storage/driver.ts @@ -54,9 +54,20 @@ export const docusDriver = defineDriver((options: DriverOptions) => { const { insert, items } = useDB() const { callHook } = useHooks() - const parser = useParser() const fs = fsDriver(options) + const parser = useParser() + + // validate key based on its extension + const isValidKey = (key: string) => parser.extensions().some(ext => key.endsWith(ext)) + + /** + * parse specific document and insert parsed data into database + * + * @param key document file key + * @param content documnet conent + * @returns parsed object + */ const parseAndInsert = async (key, content) => { const document = await parser.parse(key, content) @@ -115,7 +126,14 @@ export const docusDriver = defineDriver((options: DriverOptions) => { } // retrive contents list - const getKeys = () => fs.getKeys() + const getKeys = async () => { + let keys = await fs.getKeys() + + // filter valid keys + keys = keys.filter(isValidKey) + + return keys + } const hasItem = key => fs.hasItem(key) @@ -175,6 +193,9 @@ export const docusDriver = defineDriver((options: DriverOptions) => { // Watch files and revalidate data const watch = callback => { return fs.watch(async (event, key) => { + // ignore invalid extensions + if (!isValidKey(key)) return + if (event === 'update') { const content = await fs.getItem(key)