web: keep content injection working under the React shell - #8392
Open
unknwon wants to merge 6 commits into
Open
Conversation
Custom HTML templates stop taking effect as the web interface moves to a React application that no longer renders from the templates directory. Source builds are no longer recommended in favor of the per-commit latest-commit-build binary release.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Content injection via inject/head.tmpl and inject/footer.tmpl also stops working once the React migration completes, since the new shell does not render those templates.
Content injection, static file overrides, and email template overrides all continue to work; only full page template overrides go away with the React web interface.
Read custom/templates/inject/head.tmpl and inject/footer.tmpl and splice their contents into the React index.html shell during renderIndex, so analytics snippets, meta tags, and footer scripts keep working after the web interface migrates off the server-side template engine. Static file overrides under custom/public/ and email template overrides already work unchanged. Update the custom templates docs to deprecate only full page template overrides while documenting injection, static overrides, and email overrides as fully supported.
Contributor
There was a problem hiding this comment.
Pull request overview
Preserves the existing customization injection points while the web UI moves to a React index.html shell, and updates docs and changelog to clarify what template customization remains supported.
Changes:
- Added
templates.ReadInjectFileto loadinject/*.tmplfromcustom/with an embedded empty default fallback. - Updated
renderIndexto splicehead.tmplinto the React shell<head>andfooter.tmplbefore</body>. - Added unit tests for inject file resolution and for verifying correct injection placement, and updated related documentation and changelog wording.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
templates/embed.go |
Adds ReadInjectFile helper for injection templates. |
templates/embed_test.go |
Adds unit tests for ReadInjectFile. |
cmd/gogs/internal/web/web.go |
Updates renderIndex to inject head and footer content into the React shell output. |
cmd/gogs/internal/web/webapp_render_test.go |
Adds a test asserting injection placement in the rendered shell. |
docs/advancing/custom-templates.mdx |
Clarifies deprecation scope and documents verbatim injection behavior. |
docs/asking/release-strategy.mdx |
Updates guidance away from source builds toward per-commit binaries. |
CHANGELOG.md |
Refines the “Removed” entry to scope template removal and list remaining supported overrides. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+74
to
+78
| // ReadInjectFile returns the content of an injection template (e.g., | ||
| // "head.tmpl" or "footer.tmpl") from the "inject" directory. A file placed | ||
| // under customDir on disk takes precedence over the embedded default, which is | ||
| // empty. Both the embedded default and a missing custom file yield empty | ||
| // content with no error, so an instance that injects nothing renders normally. |
Comment on lines
+862
to
+866
| customDir := filepath.Join(conf.CustomDir(), "templates") | ||
| head, err := templates.ReadInjectFile(customDir, "head.tmpl") | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "read head injection") | ||
| } |
Comment on lines
+74
to
+76
| <Note> | ||
| The contents of these files are inserted into every page verbatim, so use plain HTML. Go template directives such as `{{.User}}` are not evaluated. | ||
| </Note> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Preserve the customization mechanisms that survive the move to the React web interface, and correct the docs and changelog to describe exactly what stays and what goes.
Code
renderIndexnow splicescustom/templates/inject/head.tmplinto<head>andcustom/templates/inject/footer.tmplbefore</body>of the Reactindex.htmlshell, so analytics snippets, meta tags, and footer scripts keep working after the web interface stops using the server-side template engine. A newtemplates.ReadInjectFilehelper reads the custom file from disk when present and falls back to the empty embedded default.custom/public/and email template overrides already work unchanged, verified by reading the static middleware and mail renderer wiring.Docs (
docs/advancing/custom-templates.mdx)<Danger>deprecates only full page template overrides (e.g.,home.tmpl), and states that injection,custom/public/static overrides, and email overrides remain fully supported.Docs (
docs/asking/release-strategy.mdx)latest-commit-buildbinary release.Changelog
+dev"Removed" entry so it scopes the removal to full page templates and lists what remains supported.Testing
templates.ReadInjectFile: unit test for embedded-empty default, custom-file precedence, and missing-file error.renderIndex: unit test confirming head content lands inside<head>and footer content lands before</body>from custom files.moon run gogs:lintclean; default andprodbuild tags compile.