Custom Injection
Freestruct supports custom injection hooks - template files in docs/_freestruct/ are auto-loaded if they exist (they win over the packaged engine/_freestruct/ templates; see the init kit to stage them).
Note: Location is
_freestruct/(not_includes/) to avoid collisions with Jekyll and other SSGs.
Hooks
| File | Injected |
|---|---|
inject-header.html |
Before </head> |
inject-body-start.html |
After <body> |
inject-footer.html |
Before </body> |
inject-brand.html is the head template itself, not a slot hook: a staged docs/_freestruct/inject-brand.html REPLACES the packaged default outright rather than merging with it, so a file that carries only the tags your layout lacks silently drops every slot it does not list (canonical, the og/twitter set, identity JSON-LD). Carry the full default set, or delete the file to fall back to the packaged template; the run warns and names the omitted core slots when a staged template is partial.
Placeholders
All hooks substitute the same placeholder set the head template uses - the full list is in the Freestruct.config Reference under Template Placeholders. The three you reach for most:
- `` - Site name from config
- `` - Site URL from config
- `` - Current build hash
`` is safe in head snippets (the injector strips the generated head region before deriving the next hash), but do not embed it in a body or footer snippet: the hash is derived from page content, so an embedded hash would make every following build depend on its own previous value.
Examples
Add custom fonts (inject-header.html)
<link rel="stylesheet" href="/fonts/inter.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
Add skip link (inject-body-start.html)
<a href="#main" class="skip-link">Skip to content</a>
Add analytics (inject-footer.html)
<script defer src="/js/analytics.js"></script>
How it works
- Create or edit the template file in
docs/_freestruct/ - Run your SSG build
- Run
npx freestruct [output] - Check the output HTML
The files are loaded only if they exist - no config needed.
Related
- Template - Frontmatter and page conventions
- Cache Busting - Understanding the hash
- Post-Render Hooks - Beyond SEO
- Freestruct.config Reference - Configuration reference