Skip to content

Commit

Permalink
Draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 committed Oct 25, 2023
1 parent 1e63832 commit d11c575
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ export default class ParsingOrchestrator {
`The pages directory does not exist, expected directory to be at "${this.paths.pages}".`
);
}
return createFilenameMapping(this.paths.pages, this.getOrCreatePageFile);

const excludeReservedPagesJSFiles = (filename: string) =>
!(filename.includes("_server") || filename.includes("_client"));
return createFilenameMapping(
this.paths.pages,
this.getOrCreatePageFile,
excludeReservedPagesJSFiles
);
}

private getSiteSettings(): SiteSettings | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import upath from "upath";

export default function createFilenameMapping<T>(
dirPath: string,
getMappedValue: (name: string) => T
getMappedValue: (name: string) => T,
fileFilter?: (filename: string) => boolean
): Record<string, T> {
const files = fs.readdirSync(dirPath, "utf-8").filter((filename) => {
const absPath = upath.join(dirPath, filename);
return fs.lstatSync(absPath).isFile();

const isFile = fs.lstatSync(absPath).isFile();
return fileFilter ? isFile && fileFilter(filename) : isFile;
});
return files.reduce((filepathMapping, filename) => {
const name = upath.basename(filename, ".tsx");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PageContext } from "@yext/pages";
import { hydrateRoot } from "react-dom/client";

export { render };

const render = async (pageContext: PageContext<any>) => {
const { Page, pageProps } = pageContext;
const rootElement = document.getElementById("reactele");
if (rootElement) {
hydrateRoot(rootElement, <Page {...pageProps} />);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as ReactDOMServer from "react-dom/server";
import { PageContext } from "@yext/pages";

export { render };

const render = async (pageContext: PageContext<any>) => {
const { Page, pageProps } = pageContext;
const viewHtml = ReactDOMServer.renderToString(<Page {...pageProps} />);
return `<!DOCTYPE html>
<html lang="<!--app-lang-->">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="reactele">${viewHtml}</div>
</body>
</html>`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ describe("aggregates data as expected", () => {
);
});

it("properly populates pageNameToPageState, ignoring sub-directories", () => {
it("properly populates PageState Records, ignoring sub-directories and reserved PagesJS Files", () => {
expect(studioData.pageNameToPageState).toEqual({
basicPage: basicPageState,
});

expect(studioData.pageNameToErrorPageState).toEqual({});
});

it("properly populates siteSettings", () => {
Expand Down

0 comments on commit d11c575

Please sign in to comment.