@ewizardjs/pages-api
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -23,8 +23,9 @@ export interface RootPage { | ||
export interface NormalizeOptions { | ||
pagesJson: Pages; | ||
page: Page; | ||
callback?: (page: Page) => unknown; | ||
parentPath?: string; | ||
settings?: SettingRecordsFragment; | ||
pagesJson: Pages; | ||
page: Page; | ||
callback?: (page: Page) => unknown; | ||
parentPath?: string; | ||
parentDirPath?: string; | ||
settings?: SettingRecordsFragment; | ||
} | ||
export type NormalizePageOptions = Omit<NormalizeOptions, 'page'>; |
@@ -11,2 +11,3 @@ "use strict"; | ||
} | ||
function getPagePath(parentPath, page, isRoot) { | ||
@@ -18,5 +19,11 @@ if (isRoot) { | ||
} | ||
function getPageTemplate(page, pagesPath = 'pages') { | ||
return page.template ?? (0, upath_1.join)(pagesPath, page.id, 'index.vue'); | ||
function getPageTemplate({ template, id }, pagesPath = 'pages', parentDirPath) { | ||
if (template) { | ||
return template; | ||
} | ||
const basePath = parentDirPath ? (0, upath_1.dirname)(parentDirPath) : pagesPath; | ||
return (0, upath_1.join)(basePath, id, 'index.vue'); | ||
} | ||
function getFlatPage(page) { | ||
@@ -32,8 +39,16 @@ const flatPage = [page]; | ||
function normalizePage(options) { | ||
const { pagesJson, page, callback, parentPath = '', settings } = options; | ||
const { pagesJson, page, callback, parentPath = '', settings, parentDirPath } = options; | ||
const { slug, path, children } = page; | ||
const isRoot = pagesJson.root?.id === page.id; | ||
page.slug = page.slug ?? getPageSlug(page, isRoot); | ||
page.path = page.path ?? getPagePath(parentPath, page, isRoot); | ||
page.template = getPageTemplate(page, settings?.path?.pages); | ||
page.children = page.children?.map(child => normalizePage({ pagesJson, page: child, callback, parentPath: page.path, settings })); | ||
page.slug = slug ?? getPageSlug(page, isRoot); | ||
page.path = path ?? getPagePath(parentPath, page, isRoot); | ||
page.template = getPageTemplate(page, settings?.path?.pages, parentDirPath); | ||
if (children) { | ||
const childrenOptions = { | ||
...options, | ||
parentPath: page.path, | ||
parentDirPath: page.template, | ||
}; | ||
page.children = getNormalizedPages(childrenOptions, children); | ||
} | ||
return callback ? callback(page) : page; | ||
@@ -69,2 +84,2 @@ } | ||
} | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ewizardjs/pages-api", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13174
194