Skip to content

Add configurable custom header/footer code#498

Merged
compscidr merged 2 commits intomainfrom
feature/custom-header-footer-code
Mar 16, 2026
Merged

Add configurable custom header/footer code#498
compscidr merged 2 commits intomainfrom
feature/custom-header-footer-code

Conversation

@compscidr
Copy link
Collaborator

Summary

  • Add custom_header_code and custom_footer_code settings (textarea type) that render raw HTML into <head> and before </body>
  • Register a safeHTML template function so injected code isn't HTML-escaped
  • Add textarea support in the admin settings form template and JS form collection
  • Remove the hardcoded Google Analytics snippet from header.html — it can now be added via the custom_header_code setting instead

Closes #485

Test plan

  • All existing tests pass
  • Add analytics script via custom_header_code in admin settings, verify it appears in page source <head>
  • Add custom HTML via custom_footer_code, verify it appears before </body>
  • Verify empty values don't render anything
  • Verify existing settings still save/load correctly

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 16, 2026 17:46
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.73%. Comparing base (ef0a4cd) to head (d2d314e).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_code settings (textarea) and renders them in header.html / footer.html.
  • Registers a safeHTML template 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.

Comment on lines +76 to +77
{{ if .settings.custom_header_code.Value }}
{{ .settings.custom_header_code.Value | safeHTML }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@compscidr compscidr merged commit 3f1e4ba into main Mar 16, 2026
2 checks passed
@compscidr compscidr deleted the feature/custom-header-footer-code branch March 16, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add configurable header / footer code

2 participants