Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 86f31ad

Browse files
author
Je
committed
chore: update pageModules when new page added
1 parent 2b345a0 commit 86f31ad

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

project.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export default class Project {
437437

438438
for await (const { path: p } of walk(pagesDir, walkOptions)) {
439439
const rp = path.resolve(util.trimPrefix(p, pagesDir)) || '/'
440-
const pagePath = rp.replace(reModuleExt, '').replace(/\s+/g, '-').replace(/\/?index$/i, '/')
440+
const pagePath = rp.replace(reModuleExt, '').replace(/\s+/g, '-').replace(/\/index$/i, '') || '/'
441441
this.#pageModules.set(pagePath, {
442442
moduleId: './pages' + rp.replace(reModuleExt, '') + '.js',
443443
rendered: new Map()
@@ -518,9 +518,15 @@ export default class Project {
518518
this._clearPageRenderCache()
519519
} else if (moduleId.startsWith('./pages/')) {
520520
if (removed) {
521-
this._removePageModule(moduleId)
521+
this._removePageModuleById(moduleId)
522522
} else {
523-
this._clearPageRenderCache(moduleId)
523+
if (this.#pageModules.has(moduleId)) {
524+
this._clearPageRenderCache(moduleId)
525+
} else {
526+
const pagePath = util.trimPrefix(moduleId, './pages').replace(reModuleExt, '').replace(/\s+/g, '-').replace(/\/index$/i, '') || '/'
527+
console.log(">", pagePath)
528+
this.#pageModules.set(pagePath, { moduleId, rendered: new Map() })
529+
}
524530
}
525531
}
526532
this._createMainModule()
@@ -564,7 +570,7 @@ export default class Project {
564570
}
565571
}
566572

567-
private _removePageModule(moduleId: string) {
573+
private _removePageModuleById(moduleId: string) {
568574
let pagePath = ''
569575
for (const [p, pm] of this.#pageModules.entries()) {
570576
if (pm.moduleId === moduleId) {
@@ -579,7 +585,9 @@ export default class Project {
579585

580586
private _clearPageRenderCache(moduleId?: string) {
581587
for (const [_, p] of this.#pageModules.entries()) {
582-
if (moduleId === undefined || p.moduleId === moduleId) {
588+
if (!moduleId) {
589+
p.rendered.clear()
590+
} else if (p.moduleId == moduleId) {
583591
p.rendered.clear()
584592
break
585593
}

0 commit comments

Comments
 (0)