Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Stop the SEO text flashing on SaaS page load (#8801)

Anthony Stirling9894f2e3cef3
diff --git a/frontend/.env.saas b/frontend/.env.saas
index 0314c59fa4..b3a63f3313 100644
--- a/frontend/.env.saas
+++ b/frontend/.env.saas
@@ -19,3 +19,6 @@ VITE_DEV_BYPASS_AUTH=false
# the per-user landing setting is hidden. Soft-release escape hatch.
# Set to `editor` (here or via the build env) to hold the processor back.
VITE_LOGIN_LANDING_MODE=dynamic
+
+# Public origin for canonical links, JSON-LD and sitemap; RUN_SUBPATH supplies /app.
+VITE_OG_BASE_URL=https://stirling.com
diff --git a/frontend/public/og-metadata.json b/frontend/public/og-metadata.json
index 8185278f9e..f8a65193e2 100644
--- a/frontend/public/og-metadata.json
+++ b/frontend/public/og-metadata.json
@@ -979,311 +979,5 @@
"/overlay-pdf": "/overlay-pdfs",
"/split-pdf-by-sections": "/split",
"/split-pdf-by-chapters": "/split"
- },
- "navLinks": [
- {
- "path": "/add-image",
- "label": "Add Image to PDF"
- },
- {
- "path": "/add-page-numbers",
- "label": "Add Page Numbers to PDF"
- },
- {
- "path": "/add-stamp",
- "label": "Add Stamp to PDF"
- },
- {
- "path": "/add-text",
- "label": "Add Text to PDF"
- },
- {
- "path": "/watermark",
- "label": "Add Watermark to PDF"
- },
- {
- "path": "/adjust-contrast",
- "label": "Adjust PDF Colors and Contrast"
- },
- {
- "path": "/annotations",
- "label": "Annotate PDF"
- },
- {
- "path": "/auto-form-detection",
- "label": "Auto Form Detection"
- },
- {
- "path": "/auto-rename",
- "label": "Auto Rename PDF Files"
- },
- {
- "path": "/auto-rotate",
- "label": "Auto Rotate"
- },
- {
- "path": "/cbr-to-pdf",
- "label": "CBR to PDF Converter"
- },
- {
- "path": "/cbz-to-pdf",
- "label": "CBZ to PDF Converter"
- },
- {
- "path": "/change-permissions",
- "label": "Change PDF Permissions"
- },
- {
- "path": "/classify",
- "label": "Classify"
- },
- {
- "path": "/single-large-page",
- "label": "Combine PDF into a Single Page"
- },
- {
- "path": "/compare",
- "label": "Compare PDF Files"
- },
- {
- "path": "/compress",
- "label": "Compress PDF"
- },
- {
- "path": "/booklet-imposition",
- "label": "Create a PDF Booklet"
- },
- {
- "path": "/create-portfolio",
- "label": "Create Portfolio"
- },
- {
- "path": "/crop",
- "label": "Crop PDF"
- },
- {
- "path": "/remove-pages",
- "label": "Delete Pages from PDF"
- },
- {
- "path": "/edit-table-of-contents",
- "label": "Edit PDF Bookmarks"
- },
- {
- "path": "/change-metadata",
- "label": "Edit PDF Metadata"
- },
- {
- "path": "/pdf-text-editor",
- "label": "Edit PDF Text"
- },
- {
- "path": "/eml-to-pdf",
- "label": "Email (EML) to PDF Converter"
- },
- {
- "path": "/extract-images",
- "label": "Extract Images from PDF"
- },
- {
- "path": "/extract-pages",
- "label": "Extract PDF Pages"
- },
- {
- "path": "/file-to-pdf",
- "label": "File to PDF Converter"
- },
- {
- "path": "/form-fill",
- "label": "Fill PDF Forms"
- },
- {
- "path": "/flatten",
- "label": "Flatten PDF"
- },
- {
- "path": "/html-to-pdf",
- "label": "HTML to PDF Converter"
- },
- {
- "path": "/img-to-pdf",
- "label": "Image to PDF Converter"
- },
- {
- "path": "/add-attachments",
- "label": "Manage PDF Attachments"
- },
- {
- "path": "/markdown-to-pdf",
- "label": "Markdown to PDF Converter"
- },
- {
- "path": "/merge",
- "label": "Merge PDF"
- },
- {
- "path": "/ocr",
- "label": "OCR PDF"
- },
- {
- "path": "/reorganize-pages",
- "label": "Organize PDF Pages"
- },
- {
- "path": "/overlay-pdfs",
- "label": "Overlay PDFs"
- },
- {
- "path": "/add-password",
- "label": "Password Protect PDF"
- },
- {
- "path": "/convert",
- "label": "PDF Converter"
- },
- {
- "path": "/get-pdf-info",
- "label": "PDF Info and Metadata Viewer"
- },
- {
- "path": "/page-layout",
- "label": "PDF Multi-Page Layout"
- },
- {
- "path": "/multi-tool",
- "label": "PDF Page Editor"
- },
- {
- "path": "/pdf-to-cbr",
- "label": "PDF to CBR Converter"
- },
- {
- "path": "/pdf-to-cbz",
- "label": "PDF to CBZ Converter"
- },
- {
- "path": "/pdf-to-csv",
- "label": "PDF to CSV Converter"
- },
- {
- "path": "/pdf-to-xlsx",
- "label": "PDF to Excel Converter"
- },
- {
- "path": "/pdf-to-html",
- "label": "PDF to HTML Converter"
- },
- {
- "path": "/pdf-to-img",
- "label": "PDF to Image Converter"
- },
- {
- "path": "/pdf-to-markdown",
- "label": "PDF to Markdown Converter"
- },
- {
- "path": "/pdf-to-pdfa",
- "label": "PDF to PDF/A Converter"
- },
- {
- "path": "/pdf-to-presentation",
- "label": "PDF to PowerPoint Converter"
- },
- {
- "path": "/pdf-to-text",
- "label": "PDF to Text Converter"
- },
- {
- "path": "/pdf-to-word",
- "label": "PDF to Word Converter"
- },
- {
- "path": "/pdf-to-xml",
- "label": "PDF to XML Converter"
- },
- {
- "path": "/read",
- "label": "PDF Viewer"
- },
- {
- "path": "/automate",
- "label": "PDF Workflow Automation"
- },
- {
- "path": "/redact",
- "label": "Redact PDF"
- },
- {
- "path": "/remove-annotations",
- "label": "Remove Annotations from PDF"
- },
- {
- "path": "/remove-blanks",
- "label": "Remove Blank Pages from PDF"
- },
- {
- "path": "/remove-image",
- "label": "Remove Images from PDF"
- },
- {
- "path": "/remove-certificate-sign",
- "label": "Remove PDF Certificate Signature"
- },
- {
- "path": "/remove-password",
- "label": "Remove PDF Password"
- },
- {
- "path": "/repair",
- "label": "Repair PDF"
- },
- {
- "path": "/replace-color-pdf",
- "label": "Replace and Invert PDF Colors"
- },
- {
- "path": "/scale-pages",
- "label": "Resize PDF Pages"
- },
- {
- "path": "/rotate",
- "label": "Rotate PDF"
- },
- {
- "path": "/sanitize",
- "label": "Sanitize PDF"
- },
- {
- "path": "/show-js",
- "label": "Show JavaScript in PDF"
- },
- {
- "path": "/sign",
- "label": "Sign PDF"
- },
- {
- "path": "/cert-sign",
- "label": "Sign PDF with a Certificate"
- },
- {
- "path": "/split",
- "label": "Split PDF"
- },
- {
- "path": "/scanner-image-split",
- "label": "Split Scanned Photos"
- },
- {
- "path": "/timestamp-pdf",
- "label": "Timestamp PDF"
- },
- {
- "path": "/unlock-pdf-forms",
- "label": "Unlock PDF Forms"
- },
- {
- "path": "/validate-signature",
- "label": "Validate PDF Signature"
- }
- ]
+ }
}
diff --git a/frontend/public/og-metadata.saas.json b/frontend/public/og-metadata.saas.json
index fa8ff83bd2..0962a39a45 100644
--- a/frontend/public/og-metadata.saas.json
+++ b/frontend/public/og-metadata.saas.json
@@ -988,311 +988,5 @@
"/overlay-pdf": "/overlay-pdfs",
"/split-pdf-by-sections": "/split",
"/split-pdf-by-chapters": "/split"
- },
- "navLinks": [
- {
- "path": "/add-image",
- "label": "Add Image to PDF"
- },
- {
- "path": "/add-page-numbers",
- "label": "Add Page Numbers to PDF"
- },
- {
- "path": "/add-stamp",
- "label": "Add Stamp to PDF"
- },
- {
- "path": "/add-text",
- "label": "Add Text to PDF"
- },
- {
- "path": "/watermark",
- "label": "Add Watermark to PDF"
- },
- {
- "path": "/adjust-contrast",
- "label": "Adjust PDF Colors and Contrast"
- },
- {
- "path": "/annotations",
- "label": "Annotate PDF"
- },
- {
- "path": "/auto-form-detection",
- "label": "Auto Form Detection"
- },
- {
- "path": "/auto-rename",
- "label": "Auto Rename PDF Files"
- },
- {
- "path": "/auto-rotate",
- "label": "Auto Rotate"
- },
- {
- "path": "/cbr-to-pdf",
- "label": "CBR to PDF Converter"
- },
- {
- "path": "/cbz-to-pdf",
- "label": "CBZ to PDF Converter"
- },
- {
- "path": "/change-permissions",
- "label": "Change PDF Permissions"
- },
- {
- "path": "/classify",
- "label": "Classify"
- },
- {
- "path": "/single-large-page",
- "label": "Combine PDF into a Single Page"
- },
- {
- "path": "/compare",
- "label": "Compare PDF Files"
- },
- {
- "path": "/compress",
- "label": "Compress PDF"
- },
- {
- "path": "/booklet-imposition",
- "label": "Create a PDF Booklet"
- },
- {
- "path": "/create-portfolio",
- "label": "Create Portfolio"
- },
- {
- "path": "/crop",
- "label": "Crop PDF"
- },
- {
- "path": "/remove-pages",
- "label": "Delete Pages from PDF"
- },
- {
- "path": "/edit-table-of-contents",
- "label": "Edit PDF Bookmarks"
- },
- {
- "path": "/change-metadata",
- "label": "Edit PDF Metadata"
- },
- {
- "path": "/pdf-text-editor",
- "label": "Edit PDF Text"
- },
- {
- "path": "/eml-to-pdf",
- "label": "Email (EML) to PDF Converter"
- },
- {
- "path": "/extract-images",
- "label": "Extract Images from PDF"
- },
- {
- "path": "/extract-pages",
- "label": "Extract PDF Pages"
- },
- {
- "path": "/file-to-pdf",
- "label": "File to PDF Converter"
- },
- {
- "path": "/form-fill",
- "label": "Fill PDF Forms"
- },
- {
- "path": "/flatten",
- "label": "Flatten PDF"
- },
- {
- "path": "/html-to-pdf",
- "label": "HTML to PDF Converter"
- },
- {
- "path": "/img-to-pdf",
- "label": "Image to PDF Converter"
- },
- {
- "path": "/add-attachments",
- "label": "Manage PDF Attachments"
- },
- {
- "path": "/markdown-to-pdf",
- "label": "Markdown to PDF Converter"
- },
- {
- "path": "/merge",
- "label": "Merge PDF"
- },
- {
- "path": "/ocr",
- "label": "OCR PDF"
- },
- {
- "path": "/reorganize-pages",
- "label": "Organize PDF Pages"
- },
- {
- "path": "/overlay-pdfs",
- "label": "Overlay PDFs"
- },
- {
- "path": "/add-password",
- "label": "Password Protect PDF"
- },
- {
- "path": "/convert",
- "label": "PDF Converter"
- },
- {
- "path": "/get-pdf-info",
- "label": "PDF Info and Metadata Viewer"
- },
- {
- "path": "/page-layout",
- "label": "PDF Multi-Page Layout"
- },
- {
- "path": "/multi-tool",
- "label": "PDF Page Editor"
- },
- {
- "path": "/pdf-to-cbr",
- "label": "PDF to CBR Converter"
- },
- {
- "path": "/pdf-to-cbz",
- "label": "PDF to CBZ Converter"
- },
- {
- "path": "/pdf-to-csv",
- "label": "PDF to CSV Converter"
- },
- {
- "path": "/pdf-to-xlsx",
- "label": "PDF to Excel Converter"
- },
- {
- "path": "/pdf-to-html",
- "label": "PDF to HTML Converter"
- },
- {
- "path": "/pdf-to-img",
- "label": "PDF to Image Converter"
- },
- {
- "path": "/pdf-to-markdown",
- "label": "PDF to Markdown Converter"
- },
- {
- "path": "/pdf-to-pdfa",
- "label": "PDF to PDF/A Converter"
- },
- {
- "path": "/pdf-to-presentation",
- "label": "PDF to PowerPoint Converter"
- },
- {
- "path": "/pdf-to-text",
- "label": "PDF to Text Converter"
- },
- {
- "path": "/pdf-to-word",
- "label": "PDF to Word Converter"
- },
- {
- "path": "/pdf-to-xml",
- "label": "PDF to XML Converter"
- },
- {
- "path": "/read",
- "label": "PDF Viewer"
- },
- {
- "path": "/automate",
- "label": "PDF Workflow Automation"
- },
- {
- "path": "/redact",
- "label": "Redact PDF"
- },
- {
- "path": "/remove-annotations",
- "label": "Remove Annotations from PDF"
- },
- {
- "path": "/remove-blanks",
- "label": "Remove Blank Pages from PDF"
- },
- {
- "path": "/remove-image",
- "label": "Remove Images from PDF"
- },
- {
- "path": "/remove-certificate-sign",
- "label": "Remove PDF Certificate Signature"
- },
- {
- "path": "/remove-password",
- "label": "Remove PDF Password"
- },
- {
- "path": "/repair",
- "label": "Repair PDF"
- },
- {
- "path": "/replace-color-pdf",
- "label": "Replace and Invert PDF Colors"
- },
- {
- "path": "/scale-pages",
- "label": "Resize PDF Pages"
- },
- {
- "path": "/rotate",
- "label": "Rotate PDF"
- },
- {
- "path": "/sanitize",
- "label": "Sanitize PDF"
- },
- {
- "path": "/show-js",
- "label": "Show JavaScript in PDF"
- },
- {
- "path": "/sign",
- "label": "Sign PDF"
- },
- {
- "path": "/cert-sign",
- "label": "Sign PDF with a Certificate"
- },
- {
- "path": "/split",
- "label": "Split PDF"
- },
- {
- "path": "/scanner-image-split",
- "label": "Split Scanned Photos"
- },
- {
- "path": "/timestamp-pdf",
- "label": "Timestamp PDF"
- },
- {
- "path": "/unlock-pdf-forms",
- "label": "Unlock PDF Forms"
- },
- {
- "path": "/validate-signature",
- "label": "Validate PDF Signature"
- }
- ]
+ }
}
diff --git a/frontend/scripts/generate-og-metadata.mjs b/frontend/scripts/generate-og-metadata.mjs
index 8f19d83e5d..66352b95ee 100644
--- a/frontend/scripts/generate-og-metadata.mjs
+++ b/frontend/scripts/generate-og-metadata.mjs
@@ -5,7 +5,7 @@
// Outputs:
// src/editor/core/data/ogImageMap.json - { toolId: imageBasename } (imported by the client)
// src/editor/core/data/urlSeoOverrides.json - { path: { title, description } } (client per-URL meta, English only)
-// public/og-metadata.json - { default, byTool, byPath, canonicalByPath, navLinks } (prerender input)
+// public/og-metadata.json - { default, byTool, byPath, canonicalByPath } (prerender input)
// public/og-metadata.saas.json - same shape, SaaS marketing copy/art (prerender input, --mode saas)
//
// Run: `node scripts/generate-og-metadata.mjs` (writes files)
@@ -444,41 +444,15 @@ for (const [id, name] of Object.entries(TOOL_SEO_TITLES)) {
urlSeoOverrides[p] = { title: name, description: descFor(id) };
}
-// --- crawlable internal-link hub --------------------------------------------
-// One routable link per tool + each convert SEO landing page. The in-app
-// toolbar uses onClick buttons (not <a href>), and the prerendered body is
-// otherwise empty, so these baked links are the only tool links a crawler can
-// follow - they spread link equity and help discovery. Paths are the first
-// alias for each tool (guaranteed routable by parseToolRoute). Dev/link tools
-// are external redirects, not landing pages, so they are excluded.
-const stripSuffix = (t) =>
- t.endsWith(` - ${SITE_NAME}`) ? t.slice(0, -` - ${SITE_NAME}`.length) : t;
+// First alias per tool, guaranteed routable by parseToolRoute.
const primaryPathByTool = {};
for (const [p, id] of Object.entries(urlToTool))
if (!(id in primaryPathByTool)) primaryPathByTool[id] = p;
-const navLinks = [];
-const seenNav = new Set();
-const pushNav = (p, label) => {
- if (p && !seenNav.has(p)) {
- seenNav.add(p);
- navLinks.push({ path: p, label });
- }
-};
-for (const id of allIds) {
- if (linkIds.includes(id)) continue;
- pushNav(
- primaryPathByTool[id] || canonicalPath(id),
- stripSuffix(byTool[id].title),
- );
-}
-for (const [p, seo] of Object.entries(CONVERT_SEO_PAGES)) pushNav(p, seo.name);
-navLinks.sort((a, b) => a.label.localeCompare(b.label));
-
// --- alias canonicalisation --------------------------------------------------
// Many paths route to the same tool (/compress-pdf and /compress). Indexing them
-// all is duplicate content, so every alias canonicalises to the primary path the
-// nav hub links to, and the prerender leaves aliases out of the sitemap. Paths
+// all is duplicate content, so every alias canonicalises to the tool's primary
+// path, and the prerender leaves aliases out of the sitemap. Paths
// keyed to themselves in byPath are landing pages with their own copy, so they
// stay primary.
const canonicalByPath = {};
@@ -497,18 +471,15 @@ const manifest = {
byTool,
byPath,
canonicalByPath,
- navLinks,
};
// SaaS manifest: same tool pages as above, but the home default and two extra
// marketing routes carry the stirling.com cards. Keeps all per-tool OG intact.
-// SaaS is the deploy with a canonical origin, so it needs the link hub most.
const saasManifest = {
default: SAAS_DEFAULT,
byTool: { ...byTool },
byPath: { ...byPath },
canonicalByPath: { ...canonicalByPath },
- navLinks,
};
// Same app-surface rule as the pageTitles loop above: noindex, never a landing page.
for (const [routePath, label] of Object.entries(SAAS_ONLY_PAGE_TITLES)) {
diff --git a/frontend/scripts/og-prerender.d.mts b/frontend/scripts/og-prerender.d.mts
index 53dce4bd8a..662c075871 100644
--- a/frontend/scripts/og-prerender.d.mts
+++ b/frontend/scripts/og-prerender.d.mts
@@ -22,18 +22,12 @@ export interface OgInjectOptions {
isHome?: boolean;
}
-export interface OgNavLink {
- path: string;
- label: string;
-}
-
export interface OgManifest {
default: OgEntry;
byTool: Record<string, OgEntry>;
byPath: Record<string, string>;
/** Alias path -> primary path it canonicalises to (aliases only). */
canonicalByPath?: Record<string, string>;
- navLinks?: OgNavLink[];
}
export function escapeHtml(value: string): string;
@@ -52,11 +46,6 @@ export function buildJsonLd(
entry: OgEntry,
opts: { siteRoot: string; pageUrl: string; isHome: boolean },
): string;
-export function buildBodyContent(
- entry: OgEntry,
- opts?: { navLinks?: OgNavLink[]; heading?: string | null },
-): string;
-export function injectBody(html: string, content: string): string;
export function injectOg(
html: string,
entry: OgEntry,
@@ -68,8 +57,6 @@ export function prerenderOg(args: {
ogBase?: string;
canonicalBase?: string;
baseHref?: string;
- /** Bake the crawlable landing body; only useful on public web deploys. */
- injectLanding?: boolean;
}): Promise<number>;
export function buildSitemap(
manifest: OgManifest,
diff --git a/frontend/scripts/og-prerender.mjs b/frontend/scripts/og-prerender.mjs
index 662b7f9528..06d34b4440 100644
--- a/frontend/scripts/og-prerender.mjs
+++ b/frontend/scripts/og-prerender.mjs
@@ -236,67 +236,6 @@ export function injectOg(html, entry, opts = {}) {
);
}
-// Scoped styling for the prerendered body content so the pre-hydration paint
-// (what crawlers see and the first visible paint for users) looks intentional.
-// It lives inside #root and is wiped when React mounts.
-const SEO_STYLE =
- "<style>.spdf-seo{max-width:760px;margin:0 auto;padding:56px 24px;" +
- "font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;color:#1a1a1a}" +
- ".spdf-seo h1{font-size:2rem;line-height:1.2;margin:0 0 .75rem}" +
- ".spdf-seo p{font-size:1.05rem;line-height:1.6;color:#444;margin:0 0 1rem}" +
- ".spdf-seo nav{margin-top:2.5rem}.spdf-seo nav h2{font-size:.95rem;" +
- "text-transform:uppercase;letter-spacing:.04em;color:#666;margin:0 0 .5rem}" +
- ".spdf-seo nav a{display:inline-block;margin:0 .75rem .35rem 0;" +
- "color:#0a58ca;text-decoration:none;font-size:.92rem}" +
- "@media(prefers-color-scheme:dark){.spdf-seo{color:#e8e8e8}" +
- ".spdf-seo p{color:#b8b8b8}.spdf-seo nav a{color:#6ea8fe}}</style>";
-
-/**
- * Build the crawlable body content injected into #root: an H1, the page
- * description, and a hub of real <a href> links to every tool. React (createRoot)
- * replaces it on mount, so it only ever shows on a full page load - i.e. to
- * crawlers and as the first paint (which also helps LCP). Links are relative so
- * they resolve against <base href> under any deploy (root, /app, context path).
- * @param {{title:string,description:string}} entry
- * @param {{navLinks?:{path:string,label:string}[], heading?:string|null}} opts
- */
-export function buildBodyContent(
- entry,
- { navLinks = [], heading = null } = {},
-) {
- const name =
- heading ||
- (entry.title.endsWith(APP_SUFFIX)
- ? entry.title.slice(0, -APP_SUFFIX.length)
- : entry.title);
- const links = navLinks
- .map(
- (l) =>
- `<a href="${escapeHtml(l.path.replace(/^\//, ""))}">${escapeHtml(l.label)}</a>`,
- )
- .join("\n ");
- const nav = links
- ? `\n <nav aria-label="All PDF tools">\n <h2>All PDF tools</h2>\n ${links}\n </nav>`
- : "";
- return (
- `<div class="spdf-seo">${SEO_STYLE}\n ` +
- `<h1>${escapeHtml(name)}</h1>\n ` +
- `<p>${escapeHtml(entry.description)}</p>${nav}\n </div>`
- );
-}
-
-const ROOT_RE = /<div id="root">\s*<\/div>/;
-
-/** Inject crawlable content into the (otherwise empty) React mount point. */
-export function injectBody(html, content) {
- return replaceOrThrow(
- html,
- ROOT_RE,
- () => `<div id="root">${content}</div>`,
- 'empty <div id="root">',
- );
-}
-
const BASE_HREF_RE = /<base\s+href="[^"]*"\s*\/?>/i;
// Clean single/multi-segment route (e.g. /compress, /settings/people); rejects
@@ -322,10 +261,6 @@ function cleanSegments(routePath) {
* `ogBase` and `canonicalBase` are absolute deploy roots (see injectOg) - any
* sub-path already folded in by the caller, because only the caller knows
* whether a given origin serves the app at the sub-path or at its own root.
- *
- * `injectLanding` bakes the crawlable landing body (see buildBodyContent). It is
- * only worth the pre-hydration flash on a crawlable public deploy, so callers
- * enable it only when a deploy origin is known.
* @returns {Promise<number>}
*/
export async function prerenderOg({
@@ -334,37 +269,18 @@ export async function prerenderOg({
ogBase = "",
canonicalBase = "",
baseHref = "/",
- injectLanding = false,
}) {
const template = await fs.readFile(path.join(distDir, "index.html"), "utf8");
const homePath = "/";
const canonicalByPath = manifest.canonicalByPath || {};
- const navLinks = manifest.navLinks;
- // The hub is the only crawlable path to the tools, so an empty one is a stale
- // manifest, not a valid input - fail loudly instead of shipping a bare page.
- if (injectLanding && (!Array.isArray(navLinks) || navLinks.length === 0)) {
- throw new Error(
- "prerenderOg: manifest has no navLinks - run scripts/generate-og-metadata.mjs",
- );
- }
- let home = injectOg(template, manifest.default, {
+ const home = injectOg(template, manifest.default, {
ogBase,
canonicalBase,
pageUrlPath: ogBase ? homePath : null,
canonicalPath: homePath,
isHome: true,
});
- // Home <title> stays the brand ("Stirling PDF"); the H1 targets the keyword.
- if (injectLanding) {
- home = injectBody(
- home,
- buildBodyContent(manifest.default, {
- navLinks,
- heading: "Free Online PDF Tools",
- }),
- );
- }
await fs.writeFile(path.join(distDir, "index.html"), home);
let count = 0;
@@ -382,9 +298,6 @@ export async function prerenderOg({
noindex: !!entry.noindex,
isHome: false,
});
- // App/auth pages (noindex) stay the bare shell - no crawlable landing copy.
- if (injectLanding && !entry.noindex)
- html = injectBody(html, buildBodyContent(entry, { navLinks }));
const nested = segments.length > 1;
if (nested)
html = html.replace(BASE_HREF_RE, `<base href="${baseHref}" />`);
diff --git a/frontend/src/editor/core/data/ogMetadata.test.ts b/frontend/src/editor/core/data/ogMetadata.test.ts
index 31dd6eeaa7..bc04ab0577 100644
--- a/frontend/src/editor/core/data/ogMetadata.test.ts
+++ b/frontend/src/editor/core/data/ogMetadata.test.ts
@@ -8,11 +8,9 @@ import { CORE_LINK_TOOL_IDS } from "@editor/types/toolId";
// Build tooling (plain ESM, node:fs only) - import the helpers for coverage.
// oxlint-disable-next-line no-restricted-imports -- build script lives outside the @editor alias root
import {
- buildBodyContent,
buildJsonLd,
buildOgTags,
buildSitemap,
- injectBody,
injectOg,
prerenderOg,
resolveDeployBases,
@@ -296,57 +294,9 @@ describe("buildSitemap", () => {
});
});
-describe("buildBodyContent + injectBody (crawlable landing content)", () => {
- const entry = {
- image: "/og_images/compress.png",
- title: "PDF to Word Converter - Stirling PDF",
- description: "Convert PDF files into editable Word documents.",
- };
- const navLinks = [
- { path: "/compress", label: "Compress" },
- { path: "/merge", label: "Merge" },
- ];
-
- it("emits an H1 (keyword, suffix stripped), the description, and relative tool links", () => {
- const body = buildBodyContent(entry, { navLinks });
- expect(body).toContain("<h1>PDF to Word Converter</h1>");
- expect(body).toContain(
- "<p>Convert PDF files into editable Word documents.</p>",
- );
- // links are relative (no leading slash) so they resolve against <base href>
- expect(body).toContain('<a href="compress">Compress</a>');
- expect(body).toContain('<a href="merge">Merge</a>');
- expect(body).not.toContain('href="/compress"');
- });
-
- it("uses an explicit heading override for the H1 when given", () => {
- const body = buildBodyContent(entry, {
- navLinks,
- heading: "Free Online PDF Tools",
- });
- expect(body).toContain("<h1>Free Online PDF Tools</h1>");
- expect(body).not.toContain("<h1>PDF to Word Converter</h1>");
- });
-
- it("escapes HTML in the H1/description", () => {
- const body = buildBodyContent(
- { ...entry, title: "A & <B>", description: 'x "y"' },
- { navLinks: [] },
- );
- expect(body).toContain("<h1>A &amp; &lt;B&gt;</h1>");
- expect(body).toContain("x &quot;y&quot;");
- });
-
- it("injectBody fills the empty React mount point", () => {
- const out = injectBody(
- '<body><div id="root"></div><script></script></body>',
- "<h1>hi</h1>",
- );
- expect(out).toContain('<div id="root"><h1>hi</h1></div>');
- });
-
- it("prerenderOg injects landing content on indexable pages but not noindex ones", async () => {
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), "og-body-"));
+describe("prerenderOg leaves the React mount point empty", () => {
+ it("bakes metadata into the head and adds no body content on a public deploy", async () => {
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "og-nobody-"));
await fs.writeFile(path.join(dir, "index.html"), TEMPLATE);
const manifest = {
default: {
@@ -360,100 +310,28 @@ describe("buildBodyContent + injectBody (crawlable landing content)", () => {
title: "Compress - Stirling PDF",
description: "c",
},
- "/settings/people": {
- image: "/og_images/home.png",
- title: "People Settings - Stirling PDF",
- description: "p",
- noindex: true,
- },
- },
- byPath: {
- "/compress": "compress",
- "/settings/people": "/settings/people",
},
- navLinks: [{ path: "/compress", label: "Compress" }],
+ byPath: { "/compress": "compress" },
};
await prerenderOg({
distDir: dir,
manifest,
- ogBase: "",
+ ogBase: "https://stirling.com",
+ canonicalBase: "https://stirling.com",
baseHref: "/",
- injectLanding: true,
});
+ for (const file of ["compress.html", "index.html"]) {
+ const html = await fs.readFile(path.join(dir, file), "utf8");
+ expect(html).toContain('<div id="root"></div>');
+ expect(html).not.toContain("<h1>");
+ }
const compress = await fs.readFile(path.join(dir, "compress.html"), "utf8");
- expect(compress).toContain('<div id="root"><div class="spdf-seo">');
- expect(compress).toContain("<h1>Compress</h1>");
-
- const settings = await fs.readFile(
- path.join(dir, "settings", "people.html"),
- "utf8",
- );
- expect(settings).toContain('<div id="root"></div>'); // noindex: bare shell
-
- const home = await fs.readFile(path.join(dir, "index.html"), "utf8");
- expect(home).toContain("spdf-seo");
-
- await fs.rm(dir, { recursive: true, force: true });
- });
-
- it("leaves the mount point empty when landing content is off (self-hosted)", async () => {
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), "og-nobody-"));
- await fs.writeFile(path.join(dir, "index.html"), TEMPLATE);
- const manifest = {
- default: {
- image: "/og_images/home.png",
- title: "Stirling PDF",
- description: "home",
- },
- byTool: {
- compress: {
- image: "/og_images/compress.png",
- title: "Compress - Stirling PDF",
- description: "c",
- },
- },
- byPath: { "/compress": "compress" },
- navLinks: [{ path: "/compress", label: "Compress" }],
- };
-
- await prerenderOg({ distDir: dir, manifest, ogBase: "", baseHref: "/" });
-
- const compress = await fs.readFile(path.join(dir, "compress.html"), "utf8");
- expect(compress).toContain('<div id="root"></div>');
- expect(compress).not.toContain("spdf-seo");
- // OG/title metadata is still baked in - only the visible body is skipped.
expect(compress).toContain("<title>Compress - Stirling PDF</title>");
-
- const home = await fs.readFile(path.join(dir, "index.html"), "utf8");
- expect(home).not.toContain("spdf-seo");
-
- await fs.rm(dir, { recursive: true, force: true });
- });
-
- it("refuses to bake landing content from a manifest with no navLinks", async () => {
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), "og-nonav-"));
- await fs.writeFile(path.join(dir, "index.html"), TEMPLATE);
- const manifest = {
- default: {
- image: "/og_images/home.png",
- title: "Stirling PDF",
- description: "home",
- },
- byTool: {},
- byPath: {},
- };
-
- await expect(
- prerenderOg({
- distDir: dir,
- manifest,
- ogBase: "https://stirling.com",
- baseHref: "/",
- injectLanding: true,
- }),
- ).rejects.toThrow(/navLinks/);
+ expect(compress).toContain(
+ '<link rel="canonical" href="https://stirling.com/compress" />',
+ );
await fs.rm(dir, { recursive: true, force: true });
});
@@ -649,7 +527,6 @@ describe("prerenderOg on a sub-path deploy", () => {
},
},
byPath: { "/compress": "compress" },
- navLinks: [{ path: "/compress", label: "Compress" }],
};
const run = async (
@@ -665,7 +542,6 @@ describe("prerenderOg on a sub-path deploy", () => {
ogBase: bases.ogBase,
canonicalBase: bases.canonicalBase,
baseHref: env.baseHref,
- injectLanding: true,
});
const html = await fs.readFile(path.join(dir, "compress.html"), "utf8");
await fs.rm(dir, { recursive: true, force: true });
@@ -732,12 +608,6 @@ describe("prerender refuses a drifted HTML shell", () => {
).toThrow(/title/);
});
- it("throws when the React mount point is gone", () => {
- expect(() =>
- injectBody("<body><main></main></body>", "<h1>x</h1>"),
- ).toThrow(/root/);
- });
-
it("prerenders the shipped editor/index.html, not just the test fixture", async () => {
const here = import.meta.url;
const shell = await fs.readFile(
@@ -760,7 +630,6 @@ describe("prerender refuses a drifted HTML shell", () => {
},
},
byPath: { "/compress": "compress" },
- navLinks: [{ path: "/compress", label: "Compress" }],
};
await prerenderOg({
@@ -769,7 +638,6 @@ describe("prerender refuses a drifted HTML shell", () => {
ogBase: "https://stirling.com",
canonicalBase: "https://stirling.com",
baseHref: "/",
- injectLanding: true,
});
const html = await fs.readFile(path.join(dir, "compress.html"), "utf8");
@@ -778,7 +646,7 @@ describe("prerender refuses a drifted HTML shell", () => {
expect(html).toContain(
'<link rel="canonical" href="https://stirling.com/compress" />',
);
- expect(html).toContain('<div id="root"><div class="spdf-seo">');
+ expect(html).toContain('<div id="root"></div>');
await fs.rm(dir, { recursive: true, force: true });
});
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index f63b9aaa09..e8171268b8 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -313,8 +313,9 @@ function compressStaticCopyPlugin(): PluginOption {
function prerenderOgPlugin(options: {
isSaas: boolean;
precompress: boolean;
+ canonicalOrigin: string;
}): PluginOption {
- const { isSaas, precompress } = options;
+ const { isSaas, precompress, canonicalOrigin } = options;
// SaaS (stirling.com) prerenders the marketing cards from a dedicated
// manifest; every other flavour uses the tool-registry manifest.
const manifestFile = isSaas
@@ -327,7 +328,6 @@ function prerenderOgPlugin(options: {
const { prerenderOg, buildSitemap, resolveDeployBases } =
// oxlint-disable-next-line no-restricted-imports -- vite config runs before path aliases resolve, so a relative import is required here
await import("./scripts/og-prerender.mjs");
- const canonicalOrigin = process.env.VITE_OG_BASE_URL || "";
const deployOrigin = process.env.CF_PAGES_URL || "";
// Absolute deploy base for nested routes' <base href> (matches vite `base`).
const subpath = (process.env.RUN_SUBPATH || "").replace(/^\/+|\/+$/g, "");
@@ -358,22 +358,18 @@ function prerenderOgPlugin(options: {
return;
}
const distDir = path.resolve(__dirname, "dist");
- // The crawlable landing body only pays for itself where a crawler can
- // reach the page; self-hosted and desktop builds just get the flash.
- const injectLanding = Boolean(ogBase);
const count = await prerenderOg({
distDir,
manifest,
ogBase,
canonicalBase,
baseHref,
- injectLanding,
});
console.log(
`[prerender-og] wrote ${count} prerendered route pages` +
(ogBase
- ? ` (absolute URLs, base=${ogBase}, crawlable landing body)`
- : " (root-relative URLs, no landing body)"),
+ ? ` (absolute URLs, base=${ogBase})`
+ : " (root-relative URLs)"),
);
// prerenderOg rewrote index.html, so the bundler's siblings for the
@@ -657,6 +653,7 @@ export default defineConfig(async ({ mode, command }) => {
prerenderOgPlugin({
isSaas: effectiveMode === "saas",
precompress: effectiveMode !== "desktop",
+ canonicalOrigin: env.VITE_OG_BASE_URL || "",
}),
],
// Worker bundles are a separate Rollup pass and do NOT inherit `plugins`,