import { readFile, mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; import type { Plugin, ResolvedConfig } from "vite"; import { blogPosts } from "../src/content/blogPosts"; import { NOTEBOOKLM_ALT_FAQ, NOTEBOOKLM_ALT_META, NOTEBOOKLM_ALT_ROWS } from "../src/content/notebooklmAlternative"; import type { BlogPost } from "../src/content/seoTypes"; import { tools, toolsHub, type ToolDef } from "../src/content/tools"; /** * Writes a static HTML file per public route after `vite build`, so crawlers that do not run JavaScript still get the * page's title, description, canonical, headings, copy and links. The React app replaces #root on load. * * Files are written as .html, not /index.html: Cloudflare Pages serves /blogs/x from blogs/x.html with no * redirect, while a folder index would 308 to /blogs/x/ and fight the canonical (which has no trailing slash). */ type Rendered = { path: string; title: string; description: string; body: string; jsonLd?: object[]; ogType?: string }; const esc = (s: string) => s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); /** Post copy supports [text](url) links and **bold**; render them as real anchors. */ const inline = (text: string) => esc(text) .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, label: string, href: string) => `${label}`) .replace(/\*\*([^*]+)\*\*/g, "$1"); const plain = (text: string) => text.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1"); const faqLd = (items: { q: string; a: string }[]) => ({ "@context": "https://schema.org", "@type": "FAQPage", mainEntity: items.map((f) => ({ "@type": "Question", name: f.q, acceptedAnswer: { "@type": "Answer", text: plain(f.a) } })), }); const faqHtml = (items: { q: string; a: string }[]) => items.length ? `

Questions

${items.map((f) => `

${esc(f.q)}

${inline(f.a)}

`).join("")}
` : ""; const nav = () => `
`; const footer = () => ``; const page = (main: string) => `${nav()}
${main}
${footer()}`; function pathTitle(p: string) { const post = blogPosts.find((b) => `/blogs/${b.slug}` === p); if (post) return post.title; const tool = tools.find((t) => `/tools/${t.slug}` === p); if (tool) return tool.heroTitle; if (p === "/notebooklm-alternative") return "Notestack vs NotebookLM"; return p; } function renderPost(post: BlogPost): Rendered { const sections = post.sections .map( (s) => `

${esc(s.heading)}

${s.paragraphs.map((p) => `

${inline(p)}

`).join("")}${ s.bullets?.length ? `
    ${s.bullets.map((b) => `
  • ${inline(b)}
  • `).join("")}
` : "" }${s.callout ? `

${inline(s.callout)}

` : ""}
`, ) .join(""); const mission = post.mission ? `

${esc(post.mission.question)} ${inline(post.mission.answer)}

` : ""; const related = post.relatedPaths.length ? `` : ""; const faq = post.faq.map((f) => ({ q: f.question, a: f.answer })); return { path: `/blogs/${post.slug}`, title: `${post.title} | Notestack`, description: post.description, ogType: "article", body: page( `

${esc(post.heroEyebrow)}

${esc(post.title)}

${esc(post.heroDescription)}

${mission}${sections}${faqHtml(faq)}
${related}`, ), jsonLd: [ { "@context": "https://schema.org", "@type": "BlogPosting", headline: post.title, description: post.description, datePublished: post.publishedAt, author: { "@type": "Organization", name: "Notestack" }, publisher: { "@type": "Organization", name: "Firebird Technologies" }, }, ...(faq.length ? [faqLd(faq)] : []), ], }; } function renderTool(tool: ToolDef): Rendered { const faq = tool.faq.map((f) => ({ q: f.question, a: f.answer })); const sections = tool.sections .map( (s) => `

${esc(s.heading)}

${s.paragraphs.map((p) => `

${inline(p)}

`).join("")}${ s.bullets?.length ? `
    ${s.bullets.map((b) => `
  • ${esc(b)}
  • `).join("")}
` : "" }
`, ) .join(""); const next = encodeURIComponent(`/tools/${tool.slug}`); return { path: `/tools/${tool.slug}`, title: tool.metaTitle, description: tool.description, body: page( ``, ), jsonLd: [ { "@context": "https://schema.org", "@type": "SoftwareApplication", name: tool.heroTitle, applicationCategory: "MultimediaApplication", operatingSystem: "Web", description: tool.description, offers: { "@type": "Offer", price: "0", priceCurrency: "USD" }, publisher: { "@type": "Organization", name: "Notestack" }, }, faqLd(faq), ], }; } function routes(): Rendered[] { const posts = [...blogPosts].sort((a, b) => b.publishedAt.localeCompare(a.publishedAt)); const altFaq = NOTEBOOKLM_ALT_FAQ.map((f) => ({ q: f.q, a: f.a })); return [ { path: "/", title: "Notestack: your knowledge, in orbit | NotebookLM alternative for writers", description: "Notestack turns any blog, newsletter, site or markdown files into a grounded research notebook, audio overviews, videos and a launch kit, all in your own voice.", body: page( `

Your knowledge, in orbit.

Notestack turns your blog, newsletter, site or markdown files into a research notebook you can question, podcasts you can publish and launch kits for every platform. Every word traced back to what you actually wrote.

Start free or see Notestack vs NotebookLM.

Free tools

Field notes

`, ), jsonLd: [ { "@context": "https://schema.org", "@type": "SoftwareApplication", name: "Notestack", applicationCategory: "BusinessApplication", operatingSystem: "Web", description: "The NotebookLM alternative for writers: a grounded research notebook built from your own archive.", offers: { "@type": "Offer", price: "0", priceCurrency: "USD" }, publisher: { "@type": "Organization", name: "Firebird Technologies" }, }, ], }, { path: "/notebooklm-alternative", title: NOTEBOOKLM_ALT_META.title, description: NOTEBOOKLM_ALT_META.description, body: page( `

NotebookLM alternative

Notestack vs NotebookLM: the NotebookLM alternative for writers

NotebookLM is great for a pile of documents. Notestack is built for a body of work: it syncs your blog, newsletter, site or markdown, answers with citations to the exact lines you wrote, and turns your knowledge into audio, video and launch posts.

Start free

Notestack vs NotebookLM

${NOTEBOOKLM_ALT_ROWS.map( (r) => ``, ).join("")}
NotestackNotebookLM
${esc(r.feature)}${esc(r.notestack)}${esc(r.notebooklm)}

When NotebookLM is still the right call

If you are studying someone else's documents for a one off project, want a free tool from Google, or live in Google Drive, NotebookLM is excellent. Notestack is the NotebookLM alternative when the sources are your own writing and the goal is to reuse and publish it.

Pair it with the right publishing tool

  • Blog2Video: turn blog posts, URLs and scripts into finished videos.
  • PDF2Video: turn any PDF, report, paper or deck into a narrated video.
  • BlogHub: list your blog or newsletter in a free directory.
${faqHtml( altFaq, )}

Comparing more tools? Read our guide to NotebookLM alternatives and NotebookLM vs ChatGPT.

`, ), jsonLd: [faqLd(altFaq)], }, { path: "/pricing", title: "Pricing | Notestack", description: "Notestack pricing: Free ($0), Writer ($24.99 a month, $18.99 billed annually) and Studio ($48.99 a month, $36.99 billed annually). Annual billing saves 24%.", body: page( `

Pick your trajectory

Start free

`, ), }, { path: "/blogs", title: "Blog | Notestack", description: "Field notes on research, deep writing and turning your archive into audio, video and launches.", body: page( `

Every post is a search for an answer

${posts .map( (p) => ``, ) .join("")}`, ), }, { path: "/tools", title: toolsHub.metaTitle, description: toolsHub.description, body: page( `

${esc(toolsHub.heroTitle)}

${esc(toolsHub.heroDescription)}

`, ), }, ...tools.map(renderTool), ...posts.filter((p) => !p.canonicalPath).map(renderPost), ]; } /** Strips the head tags this plugin owns, so every route gets exactly one of each. */ function sanitize(template: string) { return template .replace(/[\s\S]*?<\/title>\s*/gi, "") .replace(/<meta\s+name="description"[^>]*>\s*/gi, "") .replace(/<meta\s+property="og:(title|description|url|type)"[^>]*>\s*/gi, "") .replace(/<meta\s+name="twitter:(title|description)"[^>]*>\s*/gi, "") .replace(/<link\s+rel="canonical"[^>]*>\s*/gi, ""); } function head(r: Rendered, origin: string) { const url = `${origin}${r.path === "/" ? "/" : r.path}`; const tags = [ `<title>${esc(r.title)}`, ``, ``, ``, ``, ``, ``, ``, ``, ...(r.jsonLd ?? []).map((ld) => ``), ]; return tags.join("\n "); } /** * The static copy is for crawlers and screen readers, not for people: until the app's JS and CSS load it would flash * as an unstyled page of links. Keep it in the document but visually hidden (not display:none, which some crawlers * skip), and paint the app's black background from the first frame. React's createRoot replaces it on load. */ const STATIC_STYLE = ""; export function prerenderPlugin(siteUrl: string): Plugin { const origin = siteUrl.replace(/\/+$/, ""); let config: ResolvedConfig; return { name: "notestack-prerender", apply: "build", configResolved(c) { config = c; }, async closeBundle() { const outDir = path.resolve(config.root, config.build.outDir); const template = sanitize(await readFile(path.join(outDir, "index.html"), "utf8")); const all = routes(); for (const r of all) { const html = template .replace("", ` ${head(r, origin)}\n ${STATIC_STYLE}\n `) .replace('
', `
${r.body}
`); const file = r.path === "/" ? path.join(outDir, "index.html") : path.join(outDir, `${r.path.slice(1)}.html`); await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, html, "utf8"); } // Signed in and unknown routes fall back to an app shell with no page content (see public/_redirects). await writeFile(path.join(outDir, "app.html"), template.replace("", ` \n Notestack\n ${STATIC_STYLE}\n `), "utf8"); config.logger.info(`prerendered ${all.length} public routes`); }, }; }