# 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.html` as `/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.html` stays `/`.
- **Only pages are built.** The template's `css/`, `js/` and `assets/` aren't copied unless the config says so.
- **The first build tells you.** With no config file, `ssqch build` checks 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:

```js
// 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](https://sitesquatch.dev/docs/plugins/index.md)).

## 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`](https://sitesquatch.dev/docs/deploying/index.md#serving-a-site-under-a-path) 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:

```jinja
<!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:

```html
---
layout: base.jinja
title: About us
---
<h1>About us</h1>
```

Pages can be Markdown now too (`about.md`), with the same front matter. [Templates](https://sitesquatch.dev/docs/templates/index.md) has layouts, includes and the data each page gets, and [Starting a new page](https://sitesquatch.dev/docs/new-pages/index.md) 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 with `passthrough: [{ "node_modules/@fontsource/lora/files": "fonts/lora" }]`, and write the `@font-face` rules in your stylesheet, pointing at `/fonts/lora/...`.
- **Names by contents:** `assetsPlugin({ files: ["/css/styles.css"] })` from `ssqch/assets` names 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 in `url()` get fingerprinted copies too, so a `Cache-Control: immutable` header is safe for all of them ([`assetsPlugin`](https://sitesquatch.dev/docs/plugins/index.md)).
- **Pictures in the pages:** `imagePlugin()` from `ssqch/image` makes each `<img>` responsive, in AVIF and WebP at the widths you choose ([Images](https://sitesquatch.dev/docs/plugins/index.md)).
- **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, so `![Today's pie](pie.jpg)` just works ([Configuring a site](https://sitesquatch.dev/docs/configuring/index.md)).

## 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](https://sitesquatch.dev/docs/themes/index.md)). 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](https://sitesquatch.dev/docs/comparing-builds/index.md)).

## What to check

- `ssqch build` with no warnings: every link resolves.
- `ssqch patrol` for what agents and search engines read (the sitemap, `robots.txt`, a 404 page) ([Patrol](https://sitesquatch.dev/docs/patrol/index.md)).
- 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](https://sitesquatch.dev/docs/field-guide/index.md)).
- A Content-Security-Policy without `'unsafe-inline'` blocks `style` attributes, which Markdown tables use for column alignment: `markdown: { tableAlign: { left: "text-start", center: "text-center", right: "text-end" } }` writes classes instead ([Markdown](https://sitesquatch.dev/docs/markdown/index.md)).
