From 856bdab22077714cd09242c9c2415daf75f188dd Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Tue, 30 Jan 2024 22:12:05 +0000 Subject: [PATCH] tweak: Further code style improvements --- src/.vuepress/config.ts | 2 +- src/.vuepress/utils/pageCache.ts | 44 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/.vuepress/config.ts b/src/.vuepress/config.ts index c428ffb..f97fd66 100644 --- a/src/.vuepress/config.ts +++ b/src/.vuepress/config.ts @@ -11,7 +11,7 @@ import mittexmath from "markdown-it-texmath" import { googleAnalyticsPlugin } from "@vuepress/plugin-google-analytics" import { registerComponentsPlugin } from "@vuepress/plugin-register-components" import { buildPageCache } from './utils/pageCache' -import { htmlDecode, fixPageHeader, mermaidCodeFencePlugin } from './utils/formatting' +import { fixPageHeader, mermaidCodeFencePlugin } from './utils/formatting' export default defineUserConfig({ lang: 'en-GB', diff --git a/src/.vuepress/utils/pageCache.ts b/src/.vuepress/utils/pageCache.ts index 1c39dca..5a8053e 100644 --- a/src/.vuepress/utils/pageCache.ts +++ b/src/.vuepress/utils/pageCache.ts @@ -1,33 +1,33 @@ import { App } from "vuepress"; interface BuildPageCacheOptions { - reverse?: boolean - includeReadme?: boolean - requireExcerpt?: boolean + reverse?: boolean + includeReadme?: boolean + requireExcerpt?: boolean } const defaultBuildPageCacheOptions: BuildPageCacheOptions = { - reverse: false, - includeReadme: false, - requireExcerpt: true + reverse: false, + includeReadme: false, + requireExcerpt: true } export async function buildPageCache(app: App, name: string, prefix: string, options: BuildPageCacheOptions = {}): Promise { - options = { - ...defaultBuildPageCacheOptions, - ...options - } - - const pages = app.pages - .filter(page => page.filePathRelative?.startsWith(prefix)) - .filter(page => options.includeReadme || page.filePathRelative !== `${prefix}/README.md`) - .map(page => ({ - ...page, - excerpt: page.contentRendered.includes("") ? page.contentRendered.split("")[0] : null - })) - .filter(page => !options.requireExcerpt || !!page.excerpt) + options = { + ...defaultBuildPageCacheOptions, + ...options + } - pages.sort((a, b) => (b.filePathRelative! > a.filePathRelative! ? -1 : 1) * (options.reverse ? -1 : 1)) + const pages = app.pages + .filter(page => page.filePathRelative?.startsWith(prefix)) + .filter(page => options.includeReadme || page.filePathRelative !== `${prefix}/README.md`) + .map(page => ({ + ...page, + excerpt: page.contentRendered.includes("") ? page.contentRendered.split("")[0] : null + })) + .filter(page => !options.requireExcerpt || !!page.excerpt) - await app.writeTemp(`${name}.js`, `export const ${name} = ${JSON.stringify(pages)}`) -} \ No newline at end of file + pages.sort((a, b) => (b.filePathRelative! > a.filePathRelative! ? -1 : 1) * (options.reverse ? -1 : 1)) + + await app.writeTemp(`${name}.js`, `export const ${name} = ${JSON.stringify(pages)}`) +}