mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-19 21:29:41 +02:00
add option for generating pages inside separate folders
This commit is contained in:
parent
4d94180244
commit
c8a2b87b1c
3 changed files with 23 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "codex.docs",
|
"name": "codex.docs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"version": "v2.2.0-rc.12",
|
"version": "v2.2.0-rc.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"codex.docs": "dist/backend/app.js"
|
"codex.docs": "dist/backend/app.js"
|
||||||
|
|
|
@ -73,6 +73,11 @@ export default async function buildStatic(): Promise<void> {
|
||||||
*/
|
*/
|
||||||
async function renderPage(page: Page, isIndex?: boolean): Promise<void> {
|
async function renderPage(page: Page, isIndex?: boolean): Promise<void> {
|
||||||
console.log(`Rendering page ${page.uri}`);
|
console.log(`Rendering page ${page.uri}`);
|
||||||
|
const pageUri = page.uri;
|
||||||
|
|
||||||
|
if (!pageUri) {
|
||||||
|
throw new Error('Page uri is not defined');
|
||||||
|
}
|
||||||
const pageParent = await page.getParent();
|
const pageParent = await page.getParent();
|
||||||
const pageId = page._id;
|
const pageId = page._id;
|
||||||
|
|
||||||
|
@ -98,7 +103,19 @@ export default async function buildStatic(): Promise<void> {
|
||||||
config: appConfig.frontend,
|
config: appConfig.frontend,
|
||||||
});
|
});
|
||||||
|
|
||||||
const filename = (isIndex || page.uri === '') ? 'index.html' : `${page.uri}.html`;
|
let filename: string;
|
||||||
|
|
||||||
|
if (isIndex) {
|
||||||
|
filename = 'index.html';
|
||||||
|
} else if (config?.pagesInsideFolders) { // create folder for each page if pagesInsideFolders is true
|
||||||
|
const pagePath = path.resolve(distPath, pageUri);
|
||||||
|
|
||||||
|
await mkdirp(pagePath);
|
||||||
|
|
||||||
|
filename = path.resolve(pagePath, 'index.html');
|
||||||
|
} else {
|
||||||
|
filename = `${page.uri}.html`;
|
||||||
|
}
|
||||||
|
|
||||||
await fs.writeFile(path.resolve(distPath, filename), result);
|
await fs.writeFile(path.resolve(distPath, filename), result);
|
||||||
console.log(`Page ${page.uri} rendered`);
|
console.log(`Page ${page.uri} rendered`);
|
||||||
|
|
|
@ -90,7 +90,10 @@ const FrontendConfig = z.object({
|
||||||
*/
|
*/
|
||||||
const StaticBuildConfig = z.object({
|
const StaticBuildConfig = z.object({
|
||||||
outputDir: z.string(), // Output directory for static build
|
outputDir: z.string(), // Output directory for static build
|
||||||
overwrite: z.boolean().optional().default(true),
|
overwrite: z.boolean().optional() // Overwrite output directory
|
||||||
|
.default(true),
|
||||||
|
pagesInsideFolders: z.boolean().optional() // Create separate folder for each page
|
||||||
|
.default(true),
|
||||||
indexPage: z.object({
|
indexPage: z.object({
|
||||||
enabled: z.boolean(), // Is index page enabled
|
enabled: z.boolean(), // Is index page enabled
|
||||||
uri: z.string(), // Index page uri
|
uri: z.string(), // Index page uri
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue