# Trailhead: moving from Hugo

Hugo and SiteSquatch both build pages from Markdown with front matter, a data folder, layouts and static files. Hugo's content usually moves as it is: a real-world docs site with 1,007 content files moved with none of them changed, and 764 of 787 pages came out byte for byte the same. The templates are the work: Hugo's are Go templates, which ssqch doesn't run, and Jinja (ssqch's default) is the closest, since Go's `define` and `block` map onto Jinja's `extends` and `block`, and both trim whitespace with `{{- -}}`.

## Scouting

`ssqch scout` (see [Scouting a site](https://sitesquatch.dev/docs/trailheads/index.md#scouting-a-site)) lists what your site uses, each with its file and line: every shortcode with how many pages call it, the sections (`_index.md`) and `cascade`, the render hooks and ssqch's hook for each, the Go templates, and the Hugo Pipes and functions they call (`js.Build`, `css.TailwindCSS`, `.GetPage`, `.Related`). Its draft (`--write-draft`) is an `ssqch.config.js` that reads the content as Hugo does, and a container template to port for each of the site's own shortcodes:

A whole move with the loop, scout's report before, halfway and at the end, with `baseline` and `diff` between: [A move, step by step](https://sitesquatch.dev/docs/agents/index.md#a-move-step-by-step).

```js
export default defineConfig({
  dirs: { input: "content", output: "public", includes: "../_includes", data: "../data" },
  // Hugo doesn't run template code in content, and its shortcodes on a line of their own are containers.
  markdownEngine: false,
  markdown: { highlight: { classes: "pygments" } },
  passthrough: [{ static: "." }],
  data: { site: { title: "Trail Notes", url: "https://example.com", params: {} } },
  plugins: [fromHugo(), sitemapPlugin({ url: "https://example.com" }), linksPlugin({ fail: false })],
});
```

`fromHugo()` from `ssqch/from-hugo` reads Hugo's shortcodes as containers, below: a default (`shortcodes: "hugo"`) your own `markdown` can change.

## The config

| Hugo (`hugo.toml`) | SiteSquatch (`ssqch.config.js`) |
| --- | --- |
| `contentDir` (`content/`) | `dirs.input` |
| `layouts/` | `dirs.includes` (and `dirs.layouts`): templates you write in Jinja |
| `data/` | `dirs.data` |
| `static/` | `passthrough: [{ static: "." }]` |
| `publishDir` | `dirs.output` (`publishDir` works, and says ssqch's name) |
| `timeZone = "America/New_York"` | `timeZone: "America/New_York"`, the same name. A date written without a time (`date: 2026-11-02`) is that day, midnight in this zone, as Hugo reads it; without `timeZone`, ssqch uses UTC |
| A page with no date of its own | Its file's time in ssqch, which a checkout or a save moves: dates and the order of lists change from one build to the next, and on each save `ssqch serve` renders the pages that show it (every page that reads collections, when the site's code sorts by dates). `dateFallback: "git"` gives it its last commit's date (`ssqch scout` counts the pages that have none) |
| `baseURL` | the site's address goes in data and in `sitemapPlugin({ url })`; `base` is the path only, for a site served under one (`/repo/`) |
| `title`, `params` | global data: `data: { site: { title, params } }`, read as `site.title` |
| `menus` | global data (`_data/nav.yml`), and `navTree` |
| `taxonomies` | tags are collections; a page per tag is a page paginated over `collections` |
| `outputs` (RSS, `_redirects`) | a page per output file, with its `permalink` (`/index.xml`) and `layout: false`; `feedPlugin({ url, format: "rss", output: "/index.xml" })` for the RSS feed ([A feed for a blog](https://sitesquatch.dev/docs/plugins/index.md#a-feed-for-a-blog)) |
| `markup.goldmark.parser.autoHeadingIDType` | `markdown.headingIds`: `"github"` (Hugo's default) or `"blackfriday"` |
| `markup.goldmark.extensions.typographer` | `markdown.smartPunctuation` (it writes characters, where Goldmark writes entities) |
| `markup.highlight` | `markdown.highlight`, with `classes: "pygments"` for Chroma's class names; inline styles (`noClasses`, Hugo's default) aren't in ssqch, so make a stylesheet (`hugo gen chromastyles`) |
| `minify` / `--minify` | `minifyPlugin()` from `ssqch/minify` (its own bytes, not Hugo's) |
| `cascade` | directory data (`posts/posts.json`), which every page below it gets |
| `aliases` | `redirectsPlugin()`: front matter `aliases` works as it is |

## Content

- **Template code in your Markdown:** Hugo's docs and many tutorials have `{{ .Title }}` in code samples. ssqch runs Markdown through a template engine first unless `markdownEngine: false`, so set that before the first build.
- **Shortcodes:** with `fromHugo()`, a shortcode on a line of its own is a container ([Markdown](https://sitesquatch.dev/docs/markdown/index.md), "Containers"): `{{< note type="tip" >}}` to `{{< /note >}}` (or `{{% %}}`) renders `_includes/containers/note.*`, with `container.args` (what the call wrote), `container.props` (its `key="value"` parameters) `container.content` (the inside, rendered as Markdown) and `container.source` (the inside as written, for a `{{< >}}` shortcode, whose inside Hugo doesn't read as Markdown). One without a closing tag (`{{< youtube abc >}}`) has no content. Port each shortcode's Go template into its container template. A shortcode inside a line of text (`{{< new-in 0.148 />}}`, `[About]({{< ref "about" >}})`) renders through the same container template in its place, with `container.inline` true, so a template that's called both ways can check it: `{% if container.inline %}<span>...</span>{% else %}<div>...</div>{% endif %}`.
- **URLs:** Hugo lowercases paths and reads `slug` and `url`. In ssqch, `permalink` in front matter or directory data sets a page's URL; `computed` can make one from the path for every page.
- **Sections:** an `_index.md` is a section's list page. In ssqch it's a page like any other: give it a layout in its folder's directory data, and list its folder's pages with a collection: a tag, or one in the config (`collections: { functions: (api) => api.byGlob("content/functions/**") }`).
- **Page bundles:** a folder with `index.md` and its images is a bundle in both; set `pageBundles: true` (`bundles: true` before 0.17).
- **Headless pages** (`build.render: never`, snippets included elsewhere): `permalink: false`, or `ignore` them.
- **Math:** Hugo's `markup.goldmark.extensions.passthrough` (with `params.math` and a partial that loads KaTeX or MathJax) is `markdown: { math: true }`, and the same script in the layout ([Math with KaTeX or MathJax](https://sitesquatch.dev/docs/markdown/index.md#math-with-katex-or-mathjax)). ssqch reads math between dollar signs. A page that writes `\(...\)` and `\[...\]`, as Hugo's docs suggest, loses their backslashes before math is read, with no warning, so turn them into dollar signs first:

  ```js
  // \(...\) and \[...\] as dollar signs, outside code, so `math: true` reads them.
  const dollars = (source) => source.split(/(^```[\s\S]*?^```|`[^`\n]*`)/m).map((part, i) => i % 2 ? part : part
    .replace(/\\\[([\s\S]+?)\\\]/g, (_, tex) => `$$${tex}$$`)
    .replace(/\\\((.+?)\\\)/g, (_, tex) => `$${tex.trim()}$`)).join("");

  export default defineConfig({ markdown: { math: true, preprocess: dollars } });
  ```

  `$5 and $10` stay prices either way. To render while the site builds, with no script in the page, use `math: { render: "katex" }` with the site's own `katex`.
- **Summaries:** Hugo's `.Summary` is about the first 70 words, in whole paragraphs; ssqch's `page.excerpt` is what's before `<!-- more -->`, or else the first paragraph.

## Templates: Go templates in Jinja

| Go template | Jinja |
| --- | --- |
| `{{ .Title }}`, `{{ .Params.x }}` | `{{ title }}`, `{{ params.x }}` (the page's data is the context) |
| `{{ site.Title }}`, `{{ .Site.Params.x }}` | `{{ site.title }}`, `{{ site.params.x }}` (global data) |
| `{{ with .Description }}{{ . }}{{ end }}` | `{% if description %}{{ description }}{% endif %}` |
| `{{ range .Pages }}...{{ end }}` | `{% for p in collections.x %}...{% endfor %}` |
| `{{ range $i, $p := ... }}` | `loop.index0` |
| `{{ partial "x.html" . }}` | `{% include "partials/x.jinja" %}` (it shares the context) |
| `{{ partial "x.html" (dict "a" 1) }}` | a macro: `{% from "partials/x.jinja" import x %}{{ x(a=1) }}` |
| a partial that `return`s a value | a filter in `ssqch.config.js` |
| `{{ define "main" }}` in `baseof.html` | `{% extends "baseof.jinja" %}{% block main %}...{% endblock %}` |
| `{{ block "x" . }}default{{ end }}` | `{% block x %}default{% endblock %}` |
| `{{- ... -}}` | `{%- ... -%}` and `{{- ... -}}` (the same trimming) |
| `{{/* comment */}}` | `{# comment #}` |
| `{{ .Content }}` | `{{ content }}` in a layout |
| `{{ .TableOfContents }}` | `{{ toc(page.headings) \| safe }}` |
| `{{ .Date.Format "January 2, 2006" }}` | `{{ page.date \| dateformat("%B %-d, %Y") }}` |
| `{{ "css/app.css" \| relURL }}` | `/css/app.css`, written from the site's root: ssqch puts `base` in front of it in HTML. For a URL relative to the page, [a filter](#a-filter-that-needs-the-page) |
| `.Page` in a partial that's a function | `this.page` and `this.data` in a filter ([below](#a-filter-that-needs-the-page)) |
| `{{ .Permalink }}`, `{{ "x/" \| absURL }}` | `{{ absoluteUrl(page.url, site.url) }}`, `{{ absoluteUrl("/x/", site.url) }}`, with `site.url` from a data file; `base` goes in front |
| `markdownify`, `.RenderString` | `markdown(text)`, `markdown(text, "inline")` |
| `urlize`, `anchorize` | `slugify` |
| `site.GetPage "/x"` | a filter over `collections.all` |

### A filter that needs the page

A filter gets only the arguments the template passes, so a partial that read `.Page` or `.Params` of the page it was in becomes a filter written as a `function` (an arrow function has no `this`): `this.page` is the page being rendered (`this.page.url`, `inputPath`, `date`) and `this.data` is everything its templates see, front matter included. So `.Page.Title` is `this.data.title`, not `this.page.title`. This one writes URLs relative to the page, for a site that has to work from any folder (Hugo's `relativeURLs`):

```js
import path from "node:path/posix";
import { defineConfig } from "ssqch";

export default defineConfig({
  filters: {
    // {{ "css/app.css" | pageRelative }} on /docs/cedar/ is ../../css/app.css
    pageRelative: function (to) {
      const from = this.page.url.endsWith("/") ? this.page.url : path.dirname(this.page.url);
      const target = path.join("/", to);
      const relative = path.relative(from, target) || ".";
      return target.endsWith("/") ? `${relative}/` : relative;
    },
  },
});
```

It works in a layout and in an include, where `this.page` is still the page being built. Outside a render (a collection, a data file) `this` is `undefined` ([What a filter sees](https://sitesquatch.dev/docs/configuring/index.md#what-a-filter-sees)).

## Render hooks

| Hugo `layouts/_markup/` | ssqch `_includes/hooks/` |
| --- | --- |
| `render-link.html` (`.Destination`, `.Text`, `.Title`) | `link.*` (`link.href`, `link.content`, `link.title`) |
| `render-image.html` | `image.*` (`image.src`, `alt`, `title`) |
| `render-heading.html` | `heading.*` |
| `render-codeblock.html` (`.Type`, `.Inner`, `.Attributes`) | `fence.*` (`fence.lang`, `fence.code`, `fence.info`), or `fence-<lang>.*` for one language |
| `render-blockquote.html` for alerts | GitHub's `> [!NOTE]` alerts are built in (`alerts`), styled by `containers/note.*` |
| `render-table.html` (`.THead`, `.TBody`, `.Attributes`) | `table.*` (`table.content`, the rows as ssqch writes them, and `table.columns`); the template writes the `<table>` |
| `render-passthrough.html` | not in ssqch yet; for math, `markdown: { math: true }` keeps `$...$` and `$$...$$` as written ([Markdown](https://sitesquatch.dev/docs/markdown/index.md)) |

## Hugo Pipes

| Hugo | SiteSquatch |
| --- | --- |
| `css.TailwindCSS` | Tailwind's CLI as a `beforeBuild` step |
| `js.Build` | esbuild as a `beforeBuild` step, or `ssqch/assets` |
| `css.Sass`, `toCSS` | `sassPlugin()` from `ssqch/sass` |
| `fingerprint` | `assetsPlugin()` from `ssqch/assets` |
| `minify` | `minifyPlugin()` |
| `resources.Get` | `passthrough` |
| `.Resize`, `.Fill` | `imagePlugin()` from `ssqch/image` makes responsive `<picture>`s; `image()` for one file. Both resize to widths and don't crop, so crop what `.Fill` or `.Crop` cropped first |
| `quality`, in `[imaging]` or a `q60` in a processing spec (`"resize 600x q60"`) | `imagePlugin({ webpQuality, jpegQuality, avifQuality })` ([below](#image-quality)) |

### Image quality

Hugo's `[imaging]` had one `quality` for its lossy formats, which Hugo 0.163 deprecated for one per format (`[imaging.jpeg]`, `[imaging.webp]`, `[imaging.avif]`; Hugo's defaults are 75, 75 and 60). ssqch has one for each format too, on [sharp](https://sharp.pixelplumbing.com)'s scale, a whole number from 1 to 100: `webpQuality` (75 unless you set it), `jpegQuality` (89, mozjpeg) and `avifQuality` (41). They're set once on the plugin, for every image it makes, `image()`'s too:

```js
import { imagePlugin } from "ssqch/image";

export default {
  plugins: [imagePlugin({ widths: [600, 1200], webpQuality: 75, jpegQuality: 75 })],
};
```

Hugo's encoders aren't sharp's, so the same number doesn't promise the same file or the same look: build, then compare the sizes and look at a few pictures. `quality` itself is refused, with the list of options (`unknown option "quality"`), and so is a number out of range. `[imaging]`'s `resampleFilter`, `anchor`, `bgColor` and `hint` have no option in ssqch ([Images](https://sitesquatch.dev/docs/plugins/index.md#images)).

## Build it both ways

`ssqch baseline "hugo --gc --minify" --from public` builds the site with Hugo, in fresh copies with the clock pinned; it copies `node_modules` into each copy, since Hugo's `js.Build` refuses one linked from outside. Then `TZ=UTC ssqch build`, and `ssqch scout --compare` (or `ssqch diff .cache/ssqch/baseline/ref-common public`) lists the biggest groups of differences first. `ssqch docs "moving a site with an agent"` has the whole loop.

**Only dates changed:** a file whose changes are all dates or years says `only dates changed (2025 -> 2026)`, and when every changed file is like that the summary says `All N changed files differ only in dates or years`. Look at where the date comes from: a page with no `date` takes its file's time in ssqch, which a checkout sets (`dateFallback: "git"` gives it its last commit's date), and a footer's year can be the build's time, `{{ now() | dateformat("%Y") }}` ([Comparing builds](https://sitesquatch.dev/docs/comparing-builds/index.md)).
