Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
.idea/
.pnpm-debug*
.eslintcache
vite-plugin-pages-*.tgz
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ interface PageOptions {
baseRoute: string
/**
* Page file pattern.
* @example `**\/*.page.vue`
* @example `**\/*.{page,layout}.*`
*/
filePattern?: string
/**
* Function to clean or process the route by removing unnecessary parts.
* @example (route) => route.replace(/.(page|layout)$/, '')
*/
cleanRoute?: (route:string, path:string)=>string
}
```

Expand Down Expand Up @@ -246,6 +251,8 @@ export default {
{ dir: 'src/features/**/pages', baseRoute: 'features' },
// with custom file pattern
{ dir: 'src/admin/pages', baseRoute: 'admin', filePattern: '**/*.page.*' },
// with custom file pattern and clean route
{ dir: 'src/custom/pages', baseRoute: 'custom', filePattern: '**/*.{page,layout}.*', cleanRoute: (route) => route.replace(/.(page|layout)$/, '') },
],
}),
],
Expand Down
3 changes: 2 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class PageContext {

async addPage(path: string | string[], pageDir: PageOptions) {
debug.pages('add', path)
const cleanRoute = pageDir.cleanRoute || ((route:string)=>route);
for (const p of toArray(path)) {
const pageDirPath = slash(resolve(this.root, pageDir.dir))
const extension = this.options.extensions.find(ext => p.endsWith(`.${ext}`))
Expand All @@ -83,7 +84,7 @@ export class PageContext {
const route = slash(join(pageDir.baseRoute, p.replace(`${pageDirPath}/`, '').replace(`.${extension}`, '')))
this._pageRouteMap.set(p, {
path: p,
route,
route: cleanRoute(route, p),
})
await this.options.resolver.hmr?.added?.(this, p)
}
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ export interface PageOptions {
filePatern?: string
/**
* Page file pattern.
* @example `**\/*.page.vue`
* @example `**\/*.{page,layout}.*`
*/
filePattern?: string
/**
* Function to clean or process the route by removing unnecessary parts.
* @example (route) => route.replace(/.(page|layout)$/, '')
*/
cleanRoute?: (route:string, path:string)=>string
}

export interface PageResolver {
Expand Down