Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/__tests__/exportPages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ describe("the browser tab says what the site is called", () => {
expect(body.html).toContain('<meta property="og:title" content="Riverbank Books" />');
});

it("titles a one page site sent the way the editor sends it", async () => {
// The editor posts a page list, and its lone page is called Home. Fixing only the
// sections path left every export made in the editor saying Home in the tab.
const { body } = await exportSite({
pages: [{ slug: HOME_SLUG, title: "Home", sections: kept.sections }],
siteName: "Riverbank Books",
});
expect(body.html).toContain("<title>Riverbank Books</title>");
});

it("still titles each page of a real site with its own name", async () => {
const { body } = await exportSite({ pages: threePages, siteName: "Northgate" });
expect(body.pages[0].html).toContain("<title>Home</title>");
Expand Down
18 changes: 14 additions & 4 deletions src/app/api/export-site/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ export async function POST(req: NextRequest) {
*/
let sitePages: SitePage[];
if (pages === undefined || pages === null) {
// A site of one page is titled by the site's own name. asPages calls it "Home",
// which is right in a nav beside About and Contact, and wrong in the browser tab
// and the share card of a site that has no other page.
sitePages = asPages({ sections: validSections }).map((page) => ({ ...page, title: siteName || page.title }));
sitePages = asPages({ sections: validSections });
} else {
const parsedPages = pagesSchema.safeParse(pages);
if (!parsedPages.success) {
Expand All @@ -227,6 +224,19 @@ export async function POST(req: NextRequest) {
}
}

/**
* A site of one page is titled by the site's own name.
*
* Both the editor and `asPages` call a lone page "Home", which is right in a nav
* beside About and Contact and wrong in the browser tab and the share card of a site
* that has no other page. Applied here rather than on one of the two paths in, which
* is the mistake the first version of this made: the API stopped saying Home and the
* editor, which is how everybody actually exports, carried on.
*/
if (sitePages.length === 1 && siteName) {
sitePages = [{ ...sitePages[0], title: siteName }];
}

const emptyPage = sitePages.find((page) => onlyVisible(page.sections as Section[]).length === 0);
if (emptyPage) {
return NextResponse.json(
Expand Down
Loading