EPUB and PDF
Export your docs as EPUB or PDF.
@vuesho/epub packages your pages into an EPUB book, which the site serves as a file for e-readers and offline reading. These docs are also a book. To print some pages to PDF, use the Puppeteer script instead.
Setup
Install the Package
npm i @vuesho/epubAdd the Plugin
import { epubPlugin } from "@vuesho/epub";
import { createSite, recommendedPreset } from "vuesho/config";
export default createSite(docs.toSource())
.plugins(
recommendedPreset(),
// `/cover.png` is a file in `public/`.
epubPlugin({ author: "Acme", cover: "/cover.png" }),
)
.config({ site: { name: "Acme Docs" } });The build writes the book to /docs.epub, so it's there once deployed and in vuesho preview, not in vuesho dev. Its title comes from site.name, and its language from site.lang. On a site without a name, set title.
Chapters
Each page is a chapter, in sidebar order, and pages the sidebar doesn't list come last. Pages with noindex are left out. With Internationalization, the book has the default language's pages. To leave more pages out, set filter:
epubPlugin({ filter: ({ page }) => !page.path.startsWith("changelog/") });A chapter holds a page's title and its Markdown version, and a link to a page of the book leads to its chapter. An e-reader shows a component's content without its props, so an empty component shows nothing:
<Card title="Deploying" href="/deploying">
Put your site online.
</Card>To keep a component's props, give it a Markdown version, as in AI and LLMs.
The book holds the pages' images, and the build downloads remote ones into it. An image that can't be read is left out with a warning.
Pages Rendered on Request
The book is a snapshot of the docs from the build. A page from a dynamic source has its content from the build, and a page that differs per reader has its public version, as for an audience. Rebuild the site to update the book.
Configuring the Book
path changes the book's URL, and its last segment is the downloaded file's name. To make two books, add epubPlugin() twice, with different paths and filters:
epubPlugin({ path: "/downloads/acme-guide.epub" });css replaces the book's stylesheet. To extend the default one, start from defaultEpubStyles:
import { defaultEpubStyles, epubPlugin } from "@vuesho/epub";
epubPlugin({ css: `${defaultEpubStyles}\nbody { font-size: 1.1em; }` });Writing the Book to a File
outputPath also writes the book to a file during the build. The path is relative to the project root:
epubPlugin({ outputPath: "dist/docs.epub" });With path: false, the book is only written to outputPath, which keeps it out of the deployed site:
epubPlugin({ path: false, outputPath: "dist/docs.epub" });Reproducible Builds
The book's date is the last change of its pages, from the collection's lastModified, or else the time of the build. For a reproducible build, set SOURCE_DATE_EPOCH in seconds, like the time of the last commit:
SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) npx vuesho buildPuppeteer can print a few pages of your built site to PDF.
Install Puppeteer
npm i -D puppeteerWrite the Script
The script opens each page on the vuesho preview server and saves it as a PDF in pdfs/:
import { mkdir } from "node:fs/promises";
import puppeteer from "puppeteer";
const origin = "http://localhost:3000";
const paths = ["/", "/guide/install"];
const browser = await puppeteer.launch();
await mkdir("pdfs", { recursive: true });
for (const path of paths) {
const page = await browser.newPage();
await page.goto(origin + path, { waitUntil: "networkidle2" });
const name = path === "/" ? "index" : path.slice(1).replaceAll("/", "-");
await page.pdf({ path: `pdfs/${name}.pdf`, width: 950, printBackground: true });
await page.close();
}
await browser.close();Hide the Navigation
Hide the sidebar and the table of contents in print, in your stylesheet. For the notebook layout, use #nd-notebook-layout instead of #nd-docs-layout:
@import "vuesho/style/neutral.css";
@media print {
#nd-docs-layout {
--fd-sidebar-width: 0px !important;
}
#nd-sidebar,
[data-toc-popover] {
display: none;
}
}Run the Script
Build the site and preview it, then run the script in a second terminal:
npx vuesho build
npx vuesho previewnode scripts/export-pdf.tsBuilding for Print
A collapsed accordion or an unselected tab doesn't print, and forms like feedback are no use in a PDF. Build the site for print with a VITE_PRINT flag that swaps these components for flat versions:
<template>
<div><slot /></div>
</template><script setup lang="ts">
defineProps<{ title?: string; value?: string }>();
</script>
<template>
<section>
<p>
<strong>{{ title ?? value }}</strong>
</p>
<slot />
</section>
</template>import * as ui from "vuesho/components";
import Group from "./components/print/Group.vue";
import Section from "./components/print/Section.vue";
const print = import.meta.env.VITE_PRINT === "1";
export const Accordions = print ? Group : ui.Accordions;
export const Accordion = print ? Section : ui.Accordion;
export const Tabs = print ? Group : ui.Tabs;
export const Tab = print ? Section : ui.Tab;Register the components in the config. Code tabs still print their selected tab. Leave out the plugins that add forms, like AI chat and feedback:
const print = process.env.VITE_PRINT === "1";
const p = "/src/print-components.ts";
createSite(docs.toSource()).plugins(
recommendedPreset(),
{ name: "site:print", components: { Accordions: p, Accordion: p, Tabs: p, Tab: p } },
!print && chatPlugin({ model: "openai/gpt-5" }),
!print && feedbackPlugin({ onPageFeedbackAction }),
);VITE_PRINT=1 npx vuesho build
VITE_PRINT=1 npx vuesho previewOptions
Prop
Type