A cabin from a kit: starting from an HTML template
In your terminal ssqch docs "A cabin from a kit: starting from an HTML template"
A template you downloaded (a theme from a template gallery, a designer's handoff, last year's site) is a folder of .html pages, a css/ folder, some JavaScript and pictures. ssqch builds it nearly as it is: an .html file is a page, and the work is in four places, which this page takes in order. It takes about ten minutes.
What changes when ssqch builds it
- Each page moves into a folder of its own. ssqch writes
about.htmlas/about/index.html, served at/about/, so a link written relative to the page (css/styles.css,about.html) now points one folder too deep.index.htmlstays/. - Only pages are built. The template's
css/,js/andassets/aren't copied unless the config says so. - The first build tells you. With no config file,
ssqch buildchecks every link and lists the broken ones, with the pages they're on (/, /about/ -> css/styles.css (not found)). It's a warning, and the build still finishes. Once the site has a config,linksPlugin()keeps that check (below).
Step 1: keep the download, and copy it in
Keep the template as it came in a folder whose name starts with . (.template/): ssqch skips those, and you can compare with it later. Copy its pages and files into the input folder (src/), and start a config:
// ssqch.config.js
import { linksPlugin } from "ssqch/links";
export default {
dirs: { input: "src", output: "dist" },
// The template's own files, copied as they are.
passthrough: ["src/css", "src/js", "src/assets"],
plugins: [linksPlugin()],
};
linksPlugin() checks every internal link after each build: broken links fail a production build and are warnings in ssqch serve (The gear shed).
Step 2: links from the root
Change the template's relative links to links from the site's root: css/styles.css becomes /css/styles.css, about.html becomes /about/, index.html becomes /. Do it in the pages and in the template's JavaScript; the stylesheet's own url()s can stay relative, since the stylesheet doesn't move. Build, and linksPlugin() lists what's left, with a "did you mean" for one that's nearly right. A site served under a path (GitHub Pages' /repo/) keeps root links: base adds the path to every one.
Step 3: the markup every page shares, once
A template repeats its <head>, navigation and footer in every page. Move them into a layout, src/_includes/base.jinja, with the page's own part where content goes:
<!doctype html>
<html lang="en">
<head>
<title>{{ title }} | The Stump Café</title>
<link href="/css/styles.css" rel="stylesheet">
</head>
<body>
<nav><a href="/">Home</a> <a href="/about/">About</a></nav>
{{ content | safe }}
</body>
</html>
Then each page keeps only what's its own, under front matter that names the layout:
---
layout: base.jinja
title: About us
---
<h1>About us</h1>
Pages can be Markdown now too (about.md), with the same front matter. Templates has layouts, includes and the data each page gets, and Starting a new page has ssqch new for the next one.
Step 4: the fonts, and what the stylesheet loads
- Fonts from Google: many templates load them from
fonts.googleapis.com. To serve them yourself, install them from npm (npm install @fontsource/lora), copy the files withpassthrough: [{ "node_modules/@fontsource/lora/files": "fonts/lora" }], and write the@font-facerules in your stylesheet, pointing at/fonts/lora/.... - Names by contents:
assetsPlugin({ files: ["/css/styles.css"] })fromssqch/assetsnames the stylesheet by its contents in a production build (styles.7a024223.css) and rewrites the pages that link it. The fonts and background pictures the stylesheet names inurl()get fingerprinted copies too, so aCache-Control: immutableheader is safe for all of them (assetsPlugin). - Pictures in the pages:
imagePlugin()fromssqch/imagemakes each<img>responsive, in AVIF and WebP at the widths you choose (Images). - A picture beside a page: with
pageBundles: true, a page written as a folder (src/specials/pie/index.md) gets the other files in its folder copied next to it, sojust works (Configuring a site).
When the template has a new version
Keep the download's folder, and put the new version beside it. A theme folder can hold what the template gives (its layouts, its CSS) under the site's own: theme: "themes/stump" layers the site over it, and the site's own files win, one by one (Themes). To see what a new version changed on every page, build before and after and compare: ssqch build --output dist-before, update, ssqch build, ssqch diff dist-before dist (Comparing two builds).
What to check
ssqch buildwith no warnings: every link resolves.ssqch patrolfor what agents and search engines read (the sitemap,robots.txt, a 404 page) (Patrol).- An HTML validator on every page: run the Nu Html Checker locally (
npm install -D vnu-jar, which needs Java), since validator.w3.org turns a site away after about 60 pages (The field guide). - A Content-Security-Policy without
'unsafe-inline'blocksstyleattributes, which Markdown tables use for column alignment:markdown: { tableAlign: { left: "text-start", center: "text-center", right: "text-end" } }writes classes instead (Markdown).