Skip to content

Commit

Permalink
fix(plugin-blog): ensure all locale exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jan 7, 2025
1 parent ab0cb0e commit 57bf3dd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/blog/plugin-blog/src/node/getPagesMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import type { App, Page } from 'vuepress/core'
export type PagesMap = Record<string, Page[]>

export const getPageMap = (
{ pages }: App,
app: App,
filter: (page: Page) => boolean,
): PagesMap => {
const pagesMap: PagesMap = {}
const pagesMap: PagesMap = {
'/': [],
...Object.fromEntries(
Object.keys(app.siteData.locales).map((localePath) => [localePath, []]),
),
}

pages
app.pages
.filter(
(page) =>
filter(page) &&
// filter 404
page.path.substring(page.pathLocale.length - 1) !== '/404.html',
)
.forEach((page) => {
;(pagesMap[page.pathLocale] ??= []).push(page)
pagesMap[page.pathLocale].push(page)
})

return pagesMap
Expand Down

0 comments on commit 57bf3dd

Please sign in to comment.