The gear shed: built-in plugins
In your terminal ssqch docs "The gear shed: built-in plugins"
ssqch/image: responsive images, each local<img>a<picture>in modern formats and several widths, and copies for templates and data files: Images, below.ssqch/minify:minifyPlugin(options)minifies HTML output, after the image transform.minify(html, options)does the same for a string. Options:collapseWhitespace,removeComments,shortDoctype(any doctype becomes<!doctype html>, lowercase, which is valid HTML; a linter'sdoctype-stylerule may want it uppercase:shortDoctype: falsekeeps it as written) andshortenAttributes(alltrueby default), and, off by default as html-minifier's are,css(each page's<style>elements compressed, asminifyCssdoes),xml(the whitespace between tags out of.xml,.rssand.atomfiles, such as feeds and sitemaps, but not inside text, CDATA or comments) andjson(.jsonand.webmanifestfiles without spaces).minifyCss(css)compresses CSS text with ssqch's Sass, as a compressed stylesheet is written (.a { color: #ffffff; }becomes.a{color:#fff}), for CSS a template inlines:filters: { minifyCss }. It reads the text as plain CSS, so Sass's own syntax, and CSS it can't read (native CSS nesting among it), is an error naming the line; withcss: true, such a<style>stays as it is and the build warns once for the page. Each text is compressed once and kept, so a stylesheet inlined in every page costs one compression.shortenAttributesdrops the values of boolean attributes (defer="defer"becomesdefer) and whitespace that doesn't matter inclass,srcset,sizes, URL attributes and the viewport<meta>, whose numbers it writes as html-minifier-terser does (initial-scale=1.0becomesinitial-scale=1). The minifier is ssqch's own, built into the package as WebAssembly, and it minifies the ReverentGeek blog's 169 pages in about 0.1 s. Its output isn't byte for byte html-minifier-terser's withcollapseWhitespace,removeComments,useShortDoctypeandcollapseBooleanAttributes, in two ways: it keeps each attribute's quotes as written (class='a',href=x), where html-minifier-terser writes every value in double quotes, and it leaves an unclosed element as it is (<p>one<p>two), where html-minifier-terser closes it. It has none of html-minifier-terser's other options (removeOptionalTags,removeAttributeQuotes,sortAttributes,decodeEntities,minifyCSS,minifyJS): a site that needs those bytes runs that package as a transform instead, andssqch diff(not--exact) reads the two minifiers' output as the same where only quotes differ.ssqch/rss:rssPlugin()adds the filtersgetNewestCollectionItemDate,dateToRfc3339,dateToRfc822,rssDateandrssLastUpdatedDate(the Eleventy RSS plugin's first names, as aliases: they work, and say once that they'redateToRfc3339andgetNewestCollectionItemDate | dateToRfc3339),htmlToAbsoluteUrlsandfeedHtml, and its feeds useabsoluteUrl, which every site has (a template function, and an export ofssqchand ofssqch/rss). They're also named exports, for your own code. Under abase, they put it in front of a URL from the site's root that doesn't have it yet (absoluteUrl(post.url, site.url)ishttps://example.com/repo/posts/pine/), and so dohtmlToAbsoluteUrlsandfeedHtmlfor every URL in the HTML, called as a template function or from code, with the build's base.feedHtml(post.templateContent, absolutePostUrl)is a post's HTML ready for a feed: a feed's HTML never goes through the image plugin, so each local<img src>is pointed at one generated copy (a single URL, not a<picture>orsrcset, which many readers drop), a<picture>'s<source srcset>goes (the<img>is the copy every reader shows; addssqch:ignoreto keep one as written), a link to a local image at the copy a page's link gets,loading,decoding,sizes,srcset,fetchpriorityandssqch:*attributes go, and every URL is made absolute. Options, as a third argument:width(default 1200, never wider than the original; an<img width>that's smaller wins) andformat(default"auto", the source's).feedHtmlmakes the copies with the image plugin, so the config needsimagePlugin()as well; without it the build fails withthe image processor isn't set up. A feed of your own in a template uses them: apermalink: /feed.xmltemplate that loops over the newest posts, withabsoluteUrl(post.url, site.url)for each entry's link and id,post.date | dateToRfc3339for<updated>, andfeedHtml(post.templateContent, url)for<content type="html">, which Jinja escapes as the XML needs (in Liquid, add| escape). OrfeedPlugin()writes it for you:feedPlugin:feedPlugin({ url: "https://example.com" }), fromssqch/rss, writes/feed.xml: an Atom feed of thepostscollection's newest 20 entries, newest first, each with itstitle, its whole address as its link and id (orfeedIdfrom its front matter as the id, below), itsdate, itsdescriptionas the summary, and its content asfeedHtml()makes it (a picture as one generated copy, every URL whole, underbasetoo). The feed's title and subtitle aretitleanddescriptionin the site's data (src/_data/site.json). Options:url(required: the site's address),collection(a tag or a collection of the config's; default"posts"),limit(default 20; 0 for all),format("atom", the default, or"rss"),output(default"/feed.xml"),title,description, andauthor(a name, or{ name, email, url }, whereurlis the author's page, Atom's<uri>, which an RSS feed has no place for; default the title). Your layout links it:<link rel="alternate" type="application/atom+xml" href="/feed.xml">. A collection that isn't there is an error that lists the ones that are; so is a missingurl, aformatit doesn't write, and a page of your own at the same address. The blog starter (ssqch init) uses it, and A feed for a blog, below, builds one from the start, with the feed it writes. Eleventy's RSS plugin calls its ownfeedPlugintoo; ssqch's options are these.ssqch/assets:assetsPlugin({ files })fingerprints CSS and JS for long-lived caching. Templates link the plain paths (<link rel="stylesheet" href="/assets/index.css">). In a production build, each listed file in the output folder (written there by your CSS or JS tool beforessqch build) is renamed toindex.<hash>.css, older fingerprinted copies are deleted, and everyhrefandsrcin the HTML that points at it is rewritten, keeping any query string.ssqch serveleaves the plain paths alone, unless the plain file isn't there but the last production build left a fingerprinted copy: then pages link to that copy (with a warning), so serving after a build without running your CSS and JS watchers still has styles. A listed file that's missing fails a production build.assetUrl("/assets/index.css")returns the URL to use, for places outside anhreforsrc. Imports in inline module scripts are rewritten too (<script type="module">import { setup } from "/assets/pco.js"</script>, andimport("/assets/pco.js")with a plain string), and a listed file can be a passthrough copy: it's copied into the output before it's fingerprinted. A listed stylesheet'surl()s, its fonts and background pictures, point at fingerprinted copies of those files, made beside them (url(fonts/lora.woff2)becomesurl(fonts/lora.1a2b3c4d.woff2), relative as it was, with its query and fragment, and a URL with the site'sbaseworks too): the stylesheet is rewritten before its own hash is taken, so a new font gives it a new name as well. The files themselves stay where they were, for anything else that names them, and a page's<link rel="preload">of a font goes to the copy. A file that isn't in the output or a passthrough copy, adata:URL and another site's are left as they are. Imports inside JavaScript files aren't rewritten. Options:files(URL paths, required),fingerprint(trueorfalse; on for production builds by default) andintegrity(addintegrity="sha384-..."to the<link>and<script>elements that load a fingerprinted file; defaultfalse). WithelementsPlugin(), listelementsPlugin()first: listed afterassetsPlugin(), it writes the tag's<script>with the old name after the file was renamed, and the link checker fails the build.ssqch/links:linksPlugin(options)checks the built site's internal links after each build. Everyhref(ona,linkandarea),src(images, scripts, iframes, media),srcsetandimagesrcsetURL has to point at something in the output, and a#fragmenthas to match anidon the page it points to. URLs outside attributes are checked too, when they're on the site (from its root, or absolute on its address):<meta>values that are URLs (og:image,og:url,twitter:image), strings inapplication/ld+jsonblocks (without their#fragment, which names a thing there), and in.xmloutput (feeds, the sitemap), URLs in attributes and in elements like<loc>and<id>, including the escaped HTML of a feed entry's content. That's where an image URL the image plugin never saw shows up: a feed's<img>pointing at a source file that isn't published. The site's address is theurloption, or the onesitemap.xmluses; links to it (https://example.com/about/,httporhttps) are checked like links from the root. Other external links aren't checked, and neither are paths a_redirectsfile in the output covers, read as Netlify reads it: the first line that matches, a line that isn't forced (301, not301!) only for an address with no file, and a4xxline (a catch-all/* /404.html 404, a410for a page that's gone) not a redirect, so a link it answers is still broken. A link that works through a redirect (a_redirectsline, or a redirect pageredirectsPlugin()wrote) is a note after the build, not a warning:note: 1 link goes through a redirectand each link, where it ends up, and the pages it's on, so you can point it at the page after a move (-qleaves it out; a page's link to its own old address, showing off the move, isn't one). Broken links fail production builds, listing each link and the pages it's on (/about/ -> /team/ (not found), or/a/, /b/, /c/ and 5 more -> /team/ (not found)for a link broken on many pages; the first 20 links, then... and N more (--verbose lists them all);--verboselists every one and every page), and are warnings inssqch serve.--format jsonhas one entry for each page and link. One that's nearly right says what it probably meant:/about/ -> /contactt/ (not found; did you mean /contact/?), and the same for anid. Options:anchors(check#fragments; defaulttrue),ignore(URL path prefixes to skip, like["/downloads/"]),fail(trueorfalse; production builds only by default) andurl(the site's address, like"https://example.com"; default: the address insitemap.xml). A build with no config file (nossqch.config.jsand nositesquatch.toml) checks its links without being asked, since a folder of HTML or a downloaded template is where they're likeliest broken (eachabout.htmlis built as/about/, so its relative links move one folder down), Starting from an HTML template: broken links are warnings there, never a failed build, with a line saying why it checked, and a build whose links all work says nothing about them. Once the site has a config, addlinksPlugin()to its plugins to keep checking. A folder with another generator's config isn't checked: its message comes first.ssqch/sass:sassPlugin({ files: { "src/scss": "/css" } })compiles Sass with grass, built into the package as WebAssembly, so there's no Dart Sass to install. grass writes a few things differently from Dart Sass; a site that needs Dart Sass's exact output can run thesasspackage frombeforeBuildinstead ({ run: "sass src/scss:dist/css" }). A folder compiles every.scssand.sassfile in it that doesn't start with_, keeping their paths; a file ({ "src/app.scss": "/app.css" }) compiles to the path given. The CSS is written at the start of each build, sossqch/assetscan fingerprint it and the link checker sees it, andssqch serverebuilds when a source changes. Options:files(required),style("compressed"for production builds and"expanded"otherwise, by default),loadPaths, andcharset:falseleaves out what grass (as Dart Sass) starts CSS with when it has a character outside ASCII, a byte order mark when compressed and@charset "UTF-8";when expanded, so the file starts as a Jekyll site's did (jekyll-sass-converter takes the mark out). An import that names its extension (@import "primer-core/index.scss") is found in the load paths too, as Dart Sass finds it, and a stylesheet that starts with Jekyll's front matter (---lines) compiles, the lines left blank. (Yes, that makes it Sassquatch.)ssqch/sitemap:sitemapPlugin({ url: "https://example.com" })writessitemap.xmllisting every HTML page with its absolute URL and its date as<lastmod>. Left out: pages withsitemap: falsein their data, 404 pages, pages 2 and on of a list split into pages (pagination with asizeover 1; a page per tag is still listed), and URLs matchingexcludeglobs (["/tags/**"]). Options:url(the site's address, required: a sitemap lists whole addresses, and search engines read only those, so a build without one stops and asks for it; jekyll-sitemap wrote paths from the root instead),exclude,lastmod(defaulttrue),output(default"/sitemap.xml"),paginated(list every page of a split list) andalternates, a page's translations as hreflang links: a function that gets each page (url,inputPath,outputPath,date,data) and returns[{ hreflang: "fr", href: "/fr/guide/" }], the page itself included (x-defaulttoo, if you have one), or nothing. Anhreffrom the site's root gets the address andbasein front, after its<lastmod>(the order the sitemap schema checks), and the sitemap gets thexhtmlnamespace only when a page has some:alternates: (page) => page.data.translations?.map((t) => ({ hreflang: t.lang, href: t.url })). It's called at once, so work the translations out in data or a collection first. To check a sitemap with alternates against sitemaps.org'ssitemap.xsd(xmllint --schema), import W3C's XHTML schema beside it: the sitemap schema takes another namespace's elements only when their schema is known (No matching global element declaration available, but demanded by the strict wildcard, otherwise).ssqch/elements:elementsPlugin()is interactivity without a framework. A custom element is a tag with a hyphen (<like-button>) and a script that defines it. Putlike-button.jsinsrc/elements/(andlike-button.cssnext to it, if it has styles), write the tag in any page or layout, and that page gets the script and the stylesheet; pages without the tag get neither, so a page with no elements loads no JavaScript. What's inside the tag is the fallback a visitor sees before the script runs, or without JavaScript:<like-button><a href="/likes/">3 likes</a></like-button>.ssqch:loadon a tag says when its script loads:eager(with the page, the default),idle(when the browser has a quiet moment) orvisible(when the element scrolls into view), which is the "islands" idea without a framework to run it. The whole folder is copied to/elements/, so elements can import shared modules (a file without a hyphen in its name isn't an element). To fingerprint an element's script withassetsPlugin({ files: ["/elements/like-button.js"] }), listelementsPlugin()before it, so the page's<script>is written before the file is renamed. Options:dir(default:elementsin the input folder, which has to exist),url(default/elements/) andload(eager,idleorvisible: the default for tags withoutssqch:load; any other value is an error that says so). Theislandsexample has three small elements.ssqch/llms:llmsPlugin({ url: "https://example.com", description: "Hikes and the gear for them." })writes the site for language models, as llmstxt.org describes it:/llms.txtlists the site's pages (each one's title, a link to its Markdown and itsdescription), under a##heading for each of the site's top folders (/guide/...is "Guide"; the top's pages are "Pages"), and each of those pages gets a Markdown copy beside its URL as llms.txt's v2 proposal has it (/guide/intro.htmlis/guide/intro.md; a URL without a file name getsindex.md, so/guide/intro/is/guide/intro/index.mdand/is/index.md). A copy is what the page says: a Markdown page's copy is its Markdown after its template engine ran ({{ site.title }}is the title, a{% for %}is the list it wrote), without its front matter, its<script>and<style>blocks, or pictures withalt=""(decoration), and with its title on top when only the front matter had it, and its pictures (and links to them) at the addresses the page shows, so a pictureimagePlugin()published under another name links the published file; any other page's copy (a home page in Jinja) is its<article>(or its<main>when it has several, a list of cards), or else its<main>or<body>, as Markdown (headings, paragraphs, lists, links, code, quotes, tables and described pictures; navigation, forms, scripts and anythinghiddenare left out, and any element around headings, lists or paragraphs, such as one ofelementsPlugin()'s, a<search>or a<span>, is read as a<div>is; a link around them, a card, makes its first heading or paragraph the link). Links in a copy are whole addresses (withurl), and a link to a page that has a copy goes to the copy (one with a query,/contact/?plan=day-hike, goes to the page, which reads it), a relative.mdlink to another page's file included ([Install](install.md))./llms-full.txthas the heading, then every copy in one file, each after aurl:line. A page whose front matter saysllms: falseis left out. The plugin adds one template function,markdownCopy(page.url): the URL of the page's copy, or""when it has none, for the layout to link it (a build adds no markup of its own):{% if markdownCopy(page.url) %}<link rel="alternate" type="text/markdown" href="{{ markdownCopy(page.url) }}">{% endif %}. Options:title(the#heading; defaultsite.titlein the site's data, or the home page's title),description(a>line under it),details(Markdown after that, in both files: what a model should know first),url(the site's address, for whole links; without it, links are from the site's root),exclude(URL globs, like["/drafts/**"]; 404 pages are always left out),copies(defaulttrue;falselinksllms.txtto the pages instead),full(defaulttrue),section(a function that gets each listed page and returns its section's name, or nothing for the default; sections come in the order of their first page, with "Optional" last) andsort(a function that compares two pages, asArray.prototype.sorttakes it; default by URL). Each page they get is{ url, inputPath, outputPath, date, data }:datais the page's data after the cascade, its front matter included (section: (page) => page.data.category,sort: (a, b) => (a.data.order ?? 99) - (b.data.order ?? 99)),inputPathandoutputPathare absolute paths (/home/ranger/site/src/guide/intro.md), anddateis aDate. One that throws stops the build, naming the page (section(), for /guide/intro/: ...).paths(parts of the site with anllms.txtof their own, like["/docs/"]),budget(the most characters anllms.txthas before pages move into "Optional"; default 50,000) and the template functionllmsTxt(page.url), in A big site's llms.txt. vitepress-plugin-llms does this for VitePress sites.ssqch/robots:robotsPlugin({ ai: { training: false } })writes/robots.txt: everyone's group (disallow, URL paths no crawler should read), a group withDisallow: /for each kind of AI crawler that's turned off (ai:training,searchandfetch, eachtrueby default), and theSitemap:line withsitemapPlugin()'s address (sitemap: falseleaves it out, a string is another address). Posted signs lists the crawlers of each kind and the links a layout writes for agents.ssqch/vue:vuePlugin(options)renders the Vue components a site's pages use, at build time, with the site's own Vite,@vitejs/plugin-vueand Vue (npm install -D vite @vitejs/plugin-vue vue; ssqch doesn't bundle them, and says so if they're missing). With pnpm, which keeps a VitePress site's vite and @vitejs/plugin-vue besidevitepressrather than in the site'snode_modules, they're found there. Vue renders with its production build in a production build and its development build while serving (NODE_ENVfollows ssqch's env unless you set it). A page's<script setup>imports name them, as VitePress's pages do (import ApiIndex from './ApiIndex.vue', then<ApiIndex />in the page), andcomponentsnames the ones every page can use ({ TrailSchoolLink: ".vitepress/theme/components/TrailSchoolLink.vue" }, VitePress'sapp.component()). Each tag a page has (and no template in_includes/components/, which comes first) becomes the HTML Vue's server renderer writes for it: its attributes are its props, and a binding is read as Vue reads it in the page, with the page's front matter (frontmatter,$frontmatter),params(a dynamic route's, from its URL:[partnerId].mdwritten as/partners/vehikl.html),page(VitePress'suseData().page) and thedataof each VitePress loader its<script setup>imports (import { data } from './errors.data'; the loader'sload()runs once a build, through Vite, with__dirname), and what's between its tags is its default slot, with the components inside it rendered first (a layout component that holds the page works). WithfromVitepress()fromssqch/from-vitepress(a site moving from VitePress), components that import from"vitepress"get a stand-in (withcurrent, its page's state, for a wrapper that renders the site's theme: the VitePress trailhead's "Keeping your VitePress theme") foruseData()(the page's front matter, title and route, and the config'sthemeConfig),useRoute(),withBase()andinBrowser, and@theme/is the theme's folder.hydrateruns each component in the browser too, as an island:"load","idle"or"visible"(when it scrolls into view) wraps its HTML in<ssqch-vue>and adds one script to the pages that have one,/assets/vue/islands.js, which loads only the components on the page; defaultfalse, HTML only.cssis where the components' styles go (default"/assets/vue.css", for your layout to link;falsefor none), and the fonts and images they point at go where Vite put them (/assets/inter-x.woff2, afterbase); the site'spublic/isn't copied (that'spassthrough's),rootis Vite's root (default the input folder, so scope ids are VitePress's), andviteadds Vite options (resolve.alias,plugins). The components build in.cache/ssqch/vue/before each build; while serving, an edit that's only to pages keeps the last one. A VitePress loader named like ssqch's data (api/api.data.ts) goes inignore, whichssqch scoutdrafts.ssqch/react: React components in a site's pages and layouts, rendered at build time with the site's own React, react-dom and esbuild, and withhydraterun in the browser as islands: React components, below.ssqch/redirects:redirectsPlugin(options)keeps old URLs working. A page lists its old URLs in front matter (aliases: [/2019/pine-cones/, /pine.html]), and theredirectsoption adds others ({ "/feed/": "/feed.xml" }, where the new URL can be on another site). Each old URL gets a small page that sends visitors on (a meta refresh, a canonical link andnoindex), and withhostFile: true, a/old /new 301line is appended to_redirectsinstead, after any lines your own_redirectstemplate writes, andlinksPlugin()honors those lines._redirectsis the file Netlify and Cloudflare read. WithhostFileon,pagesdefaults tofalse: a host serves a file that exists before it reads_redirects, so with both, an old address would answer 200 with the redirect page and never the 301 (setpages: trueto write both anyway). An old URL with a*or a:namesegment is a pattern, as a host's_redirectsfile reads one (redirects: { "/news/*": "/blog/:splat", "/:year/:slug/": "/posts/:slug/" }): only a host can match it, so it's a line and never a page, it needshostFile: true(without it the build stops and says so), and its line comes after the exact addresses, the pattern with the most fixed in front first (/news/2019/*before/news/*), because a host takes the first line that matches.linksPlugin()follows both kinds of line: a link that a pattern covers isn't reported. A colon inside a name (/wiki/Help:Contents) is part of the name. An old URL that's another page's URL is an error. For redirect pages in your own markup, add_includes/hooks/redirect.*(any engine): it getsredirect.fromandredirect.towith the site's global data. A redirect page sends visitors on with a meta refresh and an inlinelocation.replace(which keeps the#part); a strict Content-Security-Policy, one without'unsafe-inline'for scripts, blocks the script, and the meta refresh still works without the#. To keep both, write the page with a hook whose script is a file the policy allows (<script src="/redirect.js"></script>, withlocation.replace(document.querySelector("link[rel=canonical]").href + location.hash)in it), or usehostFile: true, where a host answers with the redirect and no page is needed. On Netlify, a site served under a path needs a catch-all line to its 404 page, since Netlify answers a miss with it by itself only at the domain's root, and the line has to come after every other (Cloudflare'snot_found_handling: "404-page"finds the nearest404.htmlby itself):notFound: "/404.html"(withhostFile: true) writes/* /404.html 404, with the base in front of both, as the file's last line. Options:pages(defaulttrue, andfalsewithhostFile),hostFile(defaultfalse; callednetlifybefore 0.14, which now stops the build and nameshostFile),redirectsandnotFound.
Images
imagePlugin(options), from ssqch/image, turns every local <img> in HTML output into a <picture>: a <source> for each format, each at several widths, with the <img> as the fallback. Images are encoded with sharp and kept in a cache, so a later build encodes only what's new. [ssqch] Encoded ... lines come as each image's files are done, while pages go on rendering; the build waits for every file before the link checker, the other plugins' files, afterBuild hooks and the summary.
// ssqch.config.js
import { imagePlugin } from "ssqch/image";
export default {
plugins: [imagePlugin({ formats: ["avif", "webp", "auto"], widths: [400, 800, 1600] })],
};
A page then writes a plain <img src="/img/ridge.jpg" alt="The ridge">, and gets AVIF and WebP copies at 400, 800 and 1600 pixels wide (never wider than the original), with a JPEG <img> for the browsers that take neither.
| Option | Default | What it does |
|---|---|---|
formats | ["webp", "auto"] | The formats to write, as <source>s in this order; the last is the <img>'s. avif, webp, jpeg, png, and auto, the source's own format (a GIF keeps its animation, and an SVG is copied as it is). |
widths | [300, 600, 900, 1200, 1500] | The widths to make, never wider than the original; "auto" is the original's own width. |
defaultAttributes | { loading: "lazy", decoding: "async", sizes: "auto" } | The attributes every <img> gets unless it has its own. An image above the fold (a banner, the first row of a grid) needs loading="eager" written on it, or ssqch:preload on the largest one (below). |
outputDir | "img" | The folder in the output for the copies. |
urlPath | "/img/" | The URL path they're served from. |
webpQuality | 75 | sharp's WebP quality, a whole number from 1 to 100. |
avifQuality | 41 | sharp's AVIF quality, from 1 to 100. |
avifEffort | 2 | sharp's AVIF effort, from 0 (fastest) to 9 (slowest, with the smallest files). |
jpegQuality | 89 | sharp's JPEG quality (mozjpeg), from 1 to 100. |
minimumThreshold | 1.25 | A width larger than the original is clamped to it only when the width before it is this many times smaller. |
prune | false | After a full build, delete every file in the image folder the build didn't use (below). |
hashCache | true | Remember image ids between builds, in .cache/ssqch. |
linkedImages | true | Point a link to a local image at a generated copy (below). |
cacheDir | ".cache/ssqch/img" | Where images are encoded and kept between builds, from the project root, with links to them in the output; false encodes straight into the output. See Keep the image cache between builds. |
Quality: the quality options are sharp's own numbers, so webpQuality 75, avifQuality 41 and jpegQuality 89 are what sharp means by them, and avifEffort 2 trades a little size for speed (what it costs; a site from 0.7 converts its numbers). A number out of range fails the build and says what to use. PNGs are written at zlib's level 6. A copy's name is a hash of its source and its format's own settings, so changing jpegQuality renames the JPEG copies (browsers download them again once) and leaves the AVIF and WebP ones as they were. Whatever renames a copy (a changed setting, or a release that changes how copies are named, as 0.15.0 did for every one) encodes it again on the next build, so that build takes as long as a build with no cache: the blog's first build on 0.15.0 took 5 minutes on Netlify, where it usually takes 37 seconds, and the builds after it were fast again.
Old copies: the config's leaveNoTrace removes the copies an earlier build used and this one didn't (a picture taken off its page, a width you dropped), as it does a deleted page: they're on its list. prune: true goes further, after a full build: it deletes every file in the image folder the build didn't use, copies from before an ssqch that listed them and files no build of ssqch wrote included, so don't keep files of your own there.
One image's own settings: on an <img>, ssqch:widths="300,600" picks that image's widths, a plain width attribute pins it to one width, and ssqch:ignore leaves it alone. Watch for that width: written to reserve the picture's space (<img width="800" height="600">, as speed guides advise), it gets one 800-pixel copy and the config's widths aren't used for it, so a phone fetches the big one; add ssqch:widths to keep width and height as the space it takes and still get the copies. With ssqch:widths, the <img>'s own width and height stay as written, as the size it's shown at (<img src="/img/logo.png" width="36" height="36" ssqch:widths="36,72" sizes="36px">, a logo with a copy for sharp screens, stays 36 by 36); with only one of them, the other follows the picture's shape, and with neither, they're the largest copy's.
The largest paint: ssqch:preload is for the image that's the page's largest paint (a banner): a <link rel="preload" as="image"> with its imagesrcset and imagesizes goes in <head> before the first stylesheet, for the first of formats, and the image loads eagerly with fetchpriority="high" (sizes="auto" only works for lazy images, so auto is left out of its sizes). The preload is for the <img>'s picture on every screen, so leave it off an <img> whose <picture> has a <source media>.
A <picture> of your own: one the page wrote itself, for another crop on a phone (art direction: <picture><source media="(max-width: 40rem)" srcset="/img/tall.jpg"><img src="/img/wide.jpg" alt="The ridge"></picture>), stays the page's: its <img> gets its formats as <source>s after the page's own, with no second <picture> around them, and each local picture a <source srcset> names is published as one copy in its own format and at its own size, with its descriptor (2x, 800w) as written. A candidate that isn't a picture in the input folder stays as it is. For the phone's crop in modern formats and several widths too, write its <source>s with image(): Another crop on a phone, below, has the filter. ssqch:ignore is for the tag it's on, so to leave a whole <picture> alone, put it on each <source> and on the <img>.
Colors: images with a color profile other than sRGB (Display P3, Adobe RGB) are converted to sRGB first, so their colors stay true. HDR photos can't be yet (known gaps).
Linked images: a link to a local image (<a href="/photos/big.jpg">, the click-to-enlarge pattern) is pointed at a generated copy in the image's own format, at its own width capped at the largest of widths, so the link works without publishing the source file; ssqch:ignore on the <a>, or linkedImages: false, leaves links alone.
In templates and data files: image() and imageUrl() make copies with the same settings and cache, for what isn't an <img>. They take different paths: image() a file from the project (image("src/img/hero.jpg"), as code reads files), and imageUrl() the image's address on the site (imageUrl("/img/hero.jpg"), as a page links it). Given the other kind, each says so and names the path it meant (image(): file not found: /img/hero.jpg (looked for /img/hero.jpg; that's a path from the site's root, which imageUrl() takes: image() takes one from the project, "src/img/hero.jpg")).
image(src, { widths, formats })makes one image's files, returning{ webp: [{ url, width, height, srcset, sourceType, ... }] }; with"auto"informats, the files are underautotoo, next to the format it became (png). Its files are named after a hash of the source;namegives them a name and folder of your own, for URLs other things link to (image("logos/acme.png", { widths: [200], name: "/assets/sponsors/acme" })writes/assets/sponsors/acme-200.webp, and a name without a leading/is inside the image folder). Data files can call it even without the plugin.imageUrl(src, { width, format })is one generated copy, for URLs outside an<img>(og:image, JSON-LD, a feed):{{ imageUrl(site.logo, { width: 1200 }).url }}gives{ url, width, height, type, format }, at mostwidthpixels wide ("auto", the default, is the original's) informat(default"auto", the source's own, which every reader can show).srcis a site path, from the input folder, the way an<img src>starting with/is, and a remote URL comes back as{ url }. It's a template function on every site, and a named export ofssqch/imagefor data files.
When an image fails: images are encoded as many at once as there are cores, each on one thread, so a file's bytes don't depend on the machine (set UV_THREADPOOL_SIZE to change how many threads the pool has). A file that can't be made after a page that points at it was written (sharp failing on a source that read well, a full disk) fails the build with an images error that names the source and the pages, rather than publish markup for a file that isn't there; a source ssqch can't decode is found before any page points at it, and is a warning that leaves its tag as written.
Another crop on a phone
A hand-written <picture> keeps its crop, and the image plugin publishes each picture a <source srcset> names as one copy, in its own format. For the phone's crop in modern formats and several widths too, write its <source>s with image(), in a filter of the config's (an async filter is waited for), and the plugin adds the <img>'s formats after them:
// ssqch.config.js
import { safe } from "ssqch";
import { image, imagePlugin } from "ssqch/image";
export default {
plugins: [imagePlugin({ formats: ["avif", "webp", "auto"] })],
filters: {
// The <source>s for another crop of a picture, in every format, at two widths.
crop: async (src, media, sizes) => {
const files = await image(src, { widths: [450, 900], formats: ["avif", "webp", "jpeg"] });
return safe(Object.values(files).map((copies) => `<source media="${media}" type="${copies[0].sourceType}" srcset="${copies.map((c) => c.srcset).join(", ")}" sizes="${sizes}">`).join(""));
},
},
};
<picture>{{ "src/img/ridge-tall.jpg" | crop("(max-width: 40rem)", "100vw") }}<img src="/img/ridge-wide.jpg" alt="The ridge"></picture>
The <source>s point at files image() wrote, so the plugin leaves them as they are. image() takes a path from the project (src/img/...), and the <img> a path on the site (/img/...). Call it from a filter, a data function or a hook, which run during the build: called while the config file itself loads (at its top level), the build hasn't started, and it's an error.
What AVIF effort costs
avifEffort matters on a cold build, the one that encodes everything; a later build takes the copies from the cache. Against the default of 2, 0 builds in a little over half the time and writes AVIF files 17 to 47% bigger, 3 takes 1.5 times as long to save 2 to 3%, and 4 takes 4 to 5 times as long to save 6%. Above the default, each step costs much more time than it saves bytes, and 4 is where the time jumps.
Measured on an Apple M5 Pro (15 cores) with formats: ["avif"], avifQuality left at 41 and the default widths, no output folder and no .cache, the median of three builds: 11 JPEG photos (53 AVIF files) and 25 PNG pictures (124 files).
avifEffort | JPEG: build time | JPEG: AVIF bytes | PNG: build time | PNG: AVIF bytes |
|---|---|---|---|---|
0 | 0.40 s | 1,553 KB (17% more) | 0.93 s | 3,094 KB (47% more) |
2 (the default) | 0.72 s | 1,329 KB | 1.65 s | 2,104 KB |
3 | 1.09 s | 1,287 KB (3% less) | 2.45 s | 2,072 KB (2% less) |
4 | 3.73 s | 1,246 KB (6% less) | 6.84 s | 1,978 KB (6% less) |
6 | 10.1 s | 1,219 KB (8% less) | not measured | not measured |
9 | 34.7 s | 1,210 KB (9% less) | not measured | not measured |
Your pictures and machine will give other numbers, so to choose for a site, build it cold with each value and compare the time and ssqch footprint. The sizes are compared at the same avifQuality, not at the same measured picture quality. Changing avifEffort renames the AVIF copies, so the next build encodes them again.
Quality numbers from 0.7
0.7's numbers were its own encoders', and sharp reads them differently. A site that set avifQuality, jpegQuality or avifSpeed converts them, to keep its pictures looking as they did.
The speed setting: 0.7's avifSpeed 7 or 8 (its default) becomes avifEffort: 2; 4, 5 or 6 becomes 3; 2 or 3 becomes 4; 1 becomes 5; 9 becomes 1; and 10 becomes 0. A build with avifSpeed stops and says what to use.
The quality numbers convert with this table, avifQuality and jpegQuality each by its own column, reading between rows along the line and rounding to a whole number. webpQuality stays as it is. Nothing warns about a number you leave as it was: it's in range, and now means sharp's (an AVIF quality of 60 written for 0.7 is now a higher quality than it was, and a JPEG quality of 70 a lower one).
| 0.7's number | avifQuality | jpegQuality |
|---|---|---|
| 30 | 28 | 54 |
| 40 | 34 | 60 |
| 45 | 38 | 63 |
| 50 | 41 (the default) | 66 |
| 55 | 45 | 69 |
| 60 | 48 | 72 |
| 65 | 52 | 76 |
| 70 | 55 | 80 |
| 75 | 58 | 85 |
| 80 | 61 | 89 (the default) |
| 85 | 74 | 93 |
| 90 | 86 | 97 |
| 92 | 90 | 100 |
| 95 | 96 | 100 |
| 98 and up | 100 | 100 |
So 0.7's imagePlugin({ avifQuality: 60, avifSpeed: 4, jpegQuality: 70 }) is now imagePlugin({ avifQuality: 48, avifEffort: 3, jpegQuality: 80 }). Look at a few pictures afterwards. At the top of the scale (JPEG 92 and AVIF 98 up) sharp's best is a little below what 0.7 made.
The cache: expect the first build to encode every image again, converted or not. 0.15.0 changed how every copy is named, so 0.7's cache doesn't carry over. Add prune: true for one full build afterwards to delete 0.7's copies from the cache and the output, which nothing uses now.
A feed for a blog
A feed lets readers follow a blog in a feed reader, and feedPlugin() writes one from the posts you already have, with no template. Three things make it work: the posts are in a collection, the site has a title, and the plugin knows the site's address.
The posts get the posts tag from directory data (src/posts/posts.json), and each has a title, a date, and a description if you want a summary in the feed:
{ "tags": "posts", "layout": "post.jinja" }
---
title: Fresh tracks on the Cedar Trail
date: 2026-11-02
description: Size 24, and heading for the snack shack.
---
Size 24, and heading straight for the [snack shack](/posts/pine-cone-crunch/).
The feed's title and subtitle are the site's, from src/_data/site.json:
{ "title": "Ranger Notes", "description": "Sightings from the Cedar Trail." }
Then the plugin, with the address the site is served at:
import { feedPlugin } from "ssqch/rss";
export default {
dirs: { input: "src", output: "dist" },
plugins: [feedPlugin({ url: "https://ranger.example" })],
};
ssqch build writes dist/feed.xml, an Atom feed, newest post first:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Ranger Notes</title>
<subtitle>Sightings from the Cedar Trail.</subtitle>
<link href="https://ranger.example/feed.xml" rel="self"/>
<link href="https://ranger.example/"/>
<id>https://ranger.example/</id>
<updated>2026-11-02T00:00:00Z</updated>
<author><name>Ranger Notes</name></author>
<entry>
<title>Fresh tracks on the Cedar Trail</title>
<link href="https://ranger.example/posts/fresh-tracks/"/>
<id>https://ranger.example/posts/fresh-tracks/</id>
<updated>2026-11-02T00:00:00Z</updated>
<summary>Size 24, and heading for the snack shack.</summary>
<content type="html"><p>Size 24, and heading straight for the <a href="https://ranger.example/posts/pine-cone-crunch/">snack shack</a>.</p>
</content>
</entry>
<entry>
<title>Pine Cone Crunch is back</title>
<link href="https://ranger.example/posts/pine-cone-crunch/"/>
<id>https://ranger.example/posts/pine-cone-crunch/</id>
<updated>2026-10-15T00:00:00Z</updated>
<content type="html"><p>The camp store has it again, by the bag.</p>
</content>
</entry>
</feed>
The link in the post went from /posts/pine-cone-crunch/ to a whole address: a feed reader shows the post away from the site, so a path from the root would lead nowhere. A post without a description has no <summary>, and <updated> at the top is the newest post's date, so the feed changes only when the posts do.
Last, tell browsers and feed readers where it is, in the layout's <head>:
<link rel="alternate" type="application/atom+xml" href="/feed.xml" title="Ranger Notes">
- RSS instead:
feedPlugin({ url, format: "rss" })writes RSS 2.0 (<rss version="2.0">, with each post's<guid>and the dates as RSS writes them). Every reader reads both; link it withtype="application/rss+xml". To offer both, add the plugin twice, the second withoutput: "/rss.xml". - Another collection:
collection: "notes"for a tag or a collection of the config's,limit: 0for every post rather than the newest 20, andtitle,descriptionandauthorwhen the feed's should differ from the site's. - A post that moves keeps its entry: a feed reader knows an entry by its id, the post's address, so a post at a new address shows up again as new, and
ssqch diffsays so (feed entries removed (readers see them go)). Give the post its old id in its front matter,feedId: "https://ranger.example/posts/pine-cone-crunch/", and the entry keeps it while its link is the new address (RSS's<guid>getsisPermaLink="false").feedIdis text; anything else stops the build at that page. - Images: a responsive image from the image plugin is one
<img>in the feed, of a generated copy at its whole address, as the feed's own template function makes it (see the entry above). - Wrong: a missing
urlstops the build (plugin "ssqch/feed": needs the site's address, like feedPlugin({ url: "https://example.com" })), and so does a collection that isn't there, naming the ones that are (there's no collection `post` to make the feed from (the collections are `all`, `posts`)). - Your own feed template at
/feed.xmlis an error beside the plugin, since both would write the file. To keep yours, take the plugin out and userssPlugin()'s filters in the template.
React components
reactPlugin(options) from ssqch/react renders a site's React components into its pages at build time, so a Docusaurus, Gatsby or Astro site's own components (a pricing table, a counter, a site's own <Tabs>) keep working as they are. A framework's own components (Docusaurus's @theme/Tabs, Gatsby's <Link>) are built on that framework's router and context, and don't run outside it: they become ssqch's containers and plain links, or a stand-in of a few lines through esbuild.alias (ssqch docs --from docusaurus). A Markdown page imports them as MDX does (import Counter from "./Counter.jsx", then <Counter start={3} /> in the page), and components names the ones every page and layout can use. Each tag becomes the HTML React's server renderer writes for it, with its attributes as props (JSX values like {3} and {{ color: "green" }} read as values) and what's between its tags as children. With hydrate, a component runs in the browser too, as an island: a page that has one gets one script, which loads only its components, and everything else stays plain HTML. Its options are components ({ Counter: "src/components/Counter.jsx" }), hydrate ("load", "idle" or "visible", for all or by name: { Counter: "visible" }), css (default "/assets/react.css") and esbuild (options to add, like alias). A component that throws, a misspelled tag and an import that isn't there each stop the build at the page's line, with the cause. ssqch docs "React components" has all of it: the options, props, children, islands, Markdown, the dev server and the errors.
reactPlugin() uses the site's own React, react-dom and JSX compiler, from its node_modules, so components get the same React the rest of the site uses and ssqch doesn't bundle one: npm install react react-dom and npm install -D esbuild, and a build without them says what to run, for the site's package manager. The compiler is esbuild: a site built with Vite or Astro has it already, and a Docusaurus or Gatsby site adds it with one line. With pnpm, an esbuild that's Vite's or Astro's (beside them in node_modules/.pnpm) is found there. React 18 or later (islands use react-dom/client).
npm install react react-dom
npm install -D esbuild
// ssqch.config.js
import { reactPlugin } from "ssqch/react";
export default {
dirs: { input: "src" },
markdownEngine: false,
plugins: [
reactPlugin({
components: { Counter: "src/components/Counter.jsx" },
hydrate: { Counter: "visible" },
}),
],
};
---
title: Cedar Trail
---
import { TrailCard } from "./components/TrailCard.jsx"
# Cedar Trail
<TrailCard name="Cedar" miles={4.5} open={true} style={{ color: "green" }}>
Pack **Squatch Snacks** and a map.
</TrailCard>
<Counter start={3} label="Pine cones seen" />
| Option | What it does |
|---|---|
components | Components every page and layout can use without importing them, by the tag's name: { Counter: "src/components/Counter.jsx" }. A path is from the project's root (or a package's name, "@acme/trail-ui"). The tag renders the module's default export, or else its export of the same name. Default: none, only what pages import. |
hydrate | Which components run in the browser too: "load" (at once), "idle" (when the browser has nothing else to do) or "visible" (when it scrolls into view) for all of them, or an object by name for some ({ Counter: "visible", Search: "load" }). Default false: HTML only, and no JavaScript on any page. |
css | Where the CSS the components import goes (import "./Counter.css", CSS modules too): a path like "/assets/react.css" (the default), which your layout links, or false for none. |
esbuild | esbuild's options to add, as esbuild.build() takes them: alias ({ "@site": "." } for Docusaurus's imports), define, loader, external, plugins. React and react-dom always come from the site's root, wherever the component that imports them is (a stand-in in a folder with its own node_modules), so the browser gets one copy; don't alias react itself, which gives the server's renderer a second one and "Invalid hook call" errors. |
How a tag finds its component. A PascalCase tag (<TrailCard>, <Counter />) in a Markdown page, an HTML page or a layout is a component: _includes/components/<Name>.* comes first (a template), then the components the page imports, then components. A Markdown page imports the way MDX does, at the start of a line: import Counter from "./Counter.jsx", import { Tabs, TabItem } from "./tabs.tsx" (named exports, as too), over several lines if you like. The paths are from the page, a bare name is a package, and the import lines are left out of the page. Imports in a layout or an HTML page aren't read, so a layout's components go in components. .jsx, .tsx, .ts and .js (with JSX in it, as Docusaurus and Gatsby write it) all work, and a component can import CSS, pictures, fonts, packages (CommonJS ones too) and other components.
Children. What's between a component's tags is its children. When that's only other components (and the space between them), they're React elements, as MDX gives them, so a parent that reads its children's props works: <Tabs> around <TabItem value="a">s counts and reads them with Children, and context from the parent reaches them. Anything else between the tags (Markdown, HTML, text) is children as that HTML, put where the component puts children, with the components inside it rendered first: a component can show it but not take it apart. In a Markdown page, leave blank lines around Markdown inside a tag, as MDX does, and put a tag that holds blocks on a line of its own: CommonMark reads <Tabs> at the start of a line as HTML, and inside a line of text it's part of a paragraph.
Props. Each attribute is a prop, by the name written. A JSX value is read as a value, in a Markdown page, a layout or an HTML page: miles={4.5} is the number, open={true} true, style={{ color: "green" }} an object, items={["a", "b"]} a list, and title={title} the page's title (any name in the page's data, page.url too). Anything more ({count + 1}, a function) arrives as the expression's text, since nothing runs it. A quoted value is a string, braces and all (label="{cones}"), a bare attribute is true (<Counter compact />), class is passed as React's className, and Vue's binding (:start="3") works the same as start={3}.
Astro's client:*. A client:load, client:visible or other client:* attribute left on a tag isn't a prop and doesn't hydrate anything: it's left off, and the build warns, naming what to put in hydrate.
Islands. A hydrated component's HTML is wrapped in <ssqch-react data-component="Counter-1a2b3c4d" data-hydrate="visible" data-props="...">, with its props as JSON, and the page gets <script type="module" src="/assets/react/islands.js"></script> before </body>. That script loads only the components the page has, each its own file in /assets/react/, beside the React they share, and hydrates each where it is. A page without an island has no script. A hydrated component's children are always HTML, rendered on the server, in an <ssqch-children style="display:contents"> element that React leaves as it is in the browser, so they keep their Markdown and their own islands: a hydrated <Tabs> can't read its <TabItem>s' props, so hydrate the part that changes instead. Props cross to the browser as JSON, so a component that's hydrated gets strings, numbers, true and false, lists and objects (a date as its ISO text). There's no whole-page hydration: a site's React app around every page (a theme's layout, client-side routing) becomes ssqch layouts, and only the parts that change in the browser stay React.
Markdown and template engines. A Markdown page that runs a template engine first (markdownEngine, Jinja by default) reads {{ as the start of its own tag, so style={{ color: "green" }} fails there with a syntax error. An MDX site sets markdownEngine: false (the example above), or writes the value as :style="{ color: 'green' }". Single braces (miles={4.5}) are fine either way. A tag inside a code block or inline code is text, as it is everywhere: `<Counter start={1} />` shows the tag. MDX's other syntax isn't read: {expressions} in text stay text, and export lines are shown, so a .mdx page becomes a .md page with its imports and tags.
Production and the dev server. The components build with esbuild into .cache/ssqch/react/ before each build: the server's module (React stays the site's) and, with hydrate, the browser's, minified in a production build. React's production or development build follows ssqch's env, unless NODE_ENV is set. While serving, an edit to a component (or anything it imports, outside node_modules) rebuilds them and every page; an edit only to pages keeps the last build of the components. Every page renders again on each rebuild while the plugin is on.
When it's used wrong.
- React or esbuild missing: the build stops with what to run, for the site's package manager:
reactPlugin() needs react, react-dom and esbuild in the site's packages: `npm install react react-dom` and `npm install -D esbuild`. React and react-dom render the components; esbuild compiles their JSX. - A component that throws stops the build at its tag, with the page's lines around it and the cause:
reactPlugin(): <TrailCard> (src/components/TrailCard.jsx) at src/trails/cedar.md:12 didn't render: Cannot read properties of undefined (reading 'miles'). A tag that's in a layout says the page and(or its layout). - A misspelled tag stops it too, with the name the page has:
<TrialCard> at src/trails/cedar.md:12 isn't a component this page has (did you mean <TrailCard>?). A tag that another page imports and this one doesn't says which page does. Any other PascalCase tag with no component is the usual warning, and stays as written. - An import that isn't there stops the build at the page's import line: a relative path with no file (
src/trails/cedar.md:4 imports ./TrailCard.jsx, which isn't there), or a package or alias esbuild can't find (imports @theme/Tabs, and esbuild can't find it: install it, or add analiasin theesbuildoption). - A module with nothing to render (no default export and none of the tag's name) names the file. JSX or TypeScript esbuild can't read is esbuild's message, with the component's file and line.
- An option that isn't one, or a
hydratethat isn'tfalse,"load","idle"or"visible", stops the build with the options it has. A name inhydratethat no page imports andcomponentsdoesn't name is an error with the closest name.