Custom Injection
Add custom code via injection hooks
Custom Injection
Freestruct supports custom injection hooks - create template files in docs/_freestruct/ and they’ll be auto-loaded if they exist.
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> |
Placeholders
All hooks support these placeholders:
- `` - Site name from config
- `` - Site URL from config
- `` - Current build hash
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
node docs/lib/inject.js [output] - Check the output HTML
The files are loaded only if they exist - no config needed.
See also
- Cache Busting - Understanding the hash
- Post-Render Hooks - Beyond SEO