Add configurable custom header/footer code#498
Conversation
Add custom_header_code and custom_footer_code textarea settings that allow injecting arbitrary HTML/scripts (analytics, meta tags, etc.) into the <head> and before </body> via the admin settings page. - Add safeHTML template function to render raw HTML from settings - Add textarea type support in admin settings form and JS - Seed empty defaults for the two new settings - Remove hardcoded Google Analytics from header template Closes #485 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #498 +/- ##
==========================================
+ Coverage 45.68% 45.73% +0.05%
==========================================
Files 8 8
Lines 2038 2040 +2
==========================================
+ Hits 931 933 +2
Misses 990 990
Partials 117 117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds admin-configurable raw HTML injection points for site-wide <head> and end-of-<body> content, replacing the previously hardcoded analytics snippet and enabling flexible customization via settings.
Changes:
- Introduces
custom_header_code/custom_footer_codesettings (textarea) and renders them inheader.html/footer.html. - Registers a
safeHTMLtemplate function to render the injected code without escaping. - Updates the admin settings UI + JS settings collection to support textarea settings.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| www/js/admin-script.js | Includes textarea settings in the settings PATCH payload. |
| tools/migrate.go | Seeds two new default settings for header/footer injection. |
| templates/header.html | Renders custom_header_code into the <head>. |
| templates/footer.html | Renders custom_footer_code before </body>. |
| templates/admin_settings.html | Adds textarea rendering support for settings in the admin form. |
| goblog.go | Registers safeHTML template function in Gin’s FuncMap. |
| blog/blog_test.go | Registers safeHTML FuncMap for template-loading tests. |
| admin/admin_test.go | Registers safeHTML FuncMap for template-loading tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
templates/header.html
Outdated
| {{ if .settings.custom_header_code.Value }} | ||
| {{ .settings.custom_header_code.Value | safeHTML }} |
There was a problem hiding this comment.
Fixed in 8e30c22 — now using {{ with index .settings "custom_header_code" }} to guard against missing keys.
- Use FirstOrCreate in seedDefaultSettings so new settings are added on upgrade without skipping existing installs - Guard template lookups with index/with to handle missing keys - Rename safeHTML to rawHTML to clarify it bypasses escaping - Remove redundant textarea selector in JS (jQuery :input already matches textareas) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
custom_header_codeandcustom_footer_codesettings (textarea type) that render raw HTML into<head>and before</body>safeHTMLtemplate function so injected code isn't HTML-escapedheader.html— it can now be added via thecustom_header_codesetting insteadCloses #485
Test plan
custom_header_codein admin settings, verify it appears in page source<head>custom_footer_code, verify it appears before</body>🤖 Generated with Claude Code