Skip to content

Commit

Permalink
fix(plugin-blog): override existing page at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 7, 2024
1 parent 0d5810e commit a006959
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions plugins/plugin-blog/src/node/blogPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,27 @@ export const blogPlugin =
app.env.isDebug,
)

const pages = (
await Promise.all(
[...categoryResult.pageOptions, ...typeResult.pageOptions].map(
(pageOptions) => {
if (app.pages.every((page) => page.path !== pageOptions.path))
return createPage(app, pageOptions)

return null
},
),
)
).filter((page): page is Page => page !== null)
await Promise.all(
[...categoryResult.pageOptions, ...typeResult.pageOptions].map(
async (pageOptions) => {
const index = app.pages.findIndex(
(page) => page.path === pageOptions.path,
)

if (index !== -1) {
logger.warn('Overriding existing page:', pageOptions.path)

const index = app.pages.findIndex(
(page) => page.path === pageOptions.path,
)

app.pages.splice(index, 1, await createPage(app, pageOptions))
}

app.pages.push(...pages)
app.pages.push(await createPage(app, pageOptions))
},
),
)

// store data for onPrepared and onWatched
blogPagePaths = [
Expand Down

0 comments on commit a006959

Please sign in to comment.