diff --git a/src/__tests__/exportPages.test.ts b/src/__tests__/exportPages.test.ts
index 2068867..538ff68 100644
--- a/src/__tests__/exportPages.test.ts
+++ b/src/__tests__/exportPages.test.ts
@@ -197,6 +197,16 @@ describe("the browser tab says what the site is called", () => {
expect(body.html).toContain('');
});
+ 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("
Riverbank Books");
+ });
+
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("Home");
diff --git a/src/app/api/export-site/route.ts b/src/app/api/export-site/route.ts
index fa94f5d..c3d7fa5 100644
--- a/src/app/api/export-site/route.ts
+++ b/src/app/api/export-site/route.ts
@@ -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) {
@@ -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(