mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 14:03:33 +09:00
## Description ref #3308 Ability to render Pages with document type equal to `xml` If page with document type xml is created and has path `/sitemap.xml` this page is rendered as sitemap otherwise implicit sitemap.xml is generated. On publish we use following logic for rendering. With doctype === xml - we are rendering XmlNode as is - `Body` rendered as `(props) => props.children`, - all other elements as `() => null` - [x] - sitemap.xml must be excluded from sitemap ## Steps for reproduction ### Example Saas Sitemap with $resource and custom section and headers mixed with XmlNode - App builder https://xml-gen.staging.webstudio.is/builder/d6bcc915-6634-4e2d-9ef1-90e8e3836003?pageId=KrgWBi6ANVxH2BfRbar19 - Published https://saas-sitemapxml-x1g2n.wstd.work/sitemap.xml ### Implicit sitemap - App builder https://xml-gen.staging.webstudio.is/builder/96168940-4fbd-454a-9a03-ba4f2dffbbec - Published https://saas-january-th6m1.wstd.work/sitemap.xml Example with custom section and non XmlNode elements <img width="784" alt="image" src="https://github.com/webstudio-is/webstudio/assets/5077042/47520bf8-bb77-4c0f-b44d-011cf2cf9814"> ### Example Saas without explicit sitemap ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory --------- Co-authored-by: Oleg Isonen <oleg008@gmail.com>
50 lines
1004 B
TypeScript
50 lines
1004 B
TypeScript
import { dirname } from "node:path";
|
|
import {
|
|
access,
|
|
mkdir,
|
|
writeFile,
|
|
constants,
|
|
readFile,
|
|
} from "node:fs/promises";
|
|
|
|
export const isFileExists = async (filePath: string) => {
|
|
try {
|
|
await access(filePath, constants.F_OK);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export const createFileIfNotExists = async (
|
|
filePath: string,
|
|
content?: string
|
|
) => {
|
|
const dir = dirname(filePath);
|
|
|
|
await createFolderIfNotExists(dir);
|
|
|
|
try {
|
|
await access(filePath, constants.F_OK);
|
|
} catch {
|
|
await writeFile(filePath, content || "", "utf8");
|
|
}
|
|
};
|
|
|
|
export const createFolderIfNotExists = async (folderPath: string) => {
|
|
try {
|
|
await access(folderPath, constants.F_OK);
|
|
} catch {
|
|
await mkdir(folderPath, { recursive: true });
|
|
}
|
|
};
|
|
|
|
export const loadJSONFile = async <T>(filePath: string): Promise<T | null> => {
|
|
try {
|
|
const content = await readFile(filePath, "utf8");
|
|
return JSON.parse(content) as T;
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
};
|