Skip to content

Commit

Permalink
tweak: Further code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jan 30, 2024
1 parent 4cd25b5 commit 856bdab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
44 changes: 22 additions & 22 deletions src/.vuepress/utils/pageCache.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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("<!-- more -->") ? page.contentRendered.split("<!-- more -->")[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("<!-- more -->") ? page.contentRendered.split("<!-- more -->")[0] : null
}))
.filter(page => !options.requireExcerpt || !!page.excerpt)

await app.writeTemp(`${name}.js`, `export const ${name} = ${JSON.stringify(pages)}`)
}
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)}`)
}

0 comments on commit 856bdab

Please sign in to comment.