Skip to content

web: keep content injection working under the React shell - #8392

Open
unknwon wants to merge 6 commits into
mainfrom
jc/docs-deprecate-custom-templates
Open

web: keep content injection working under the React shell#8392
unknwon wants to merge 6 commits into
mainfrom
jc/docs-deprecate-custom-templates

Conversation

@unknwon

@unknwon unknwon commented Jul 16, 2026

Copy link
Copy Markdown
Member

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

  • renderIndex now splices custom/templates/inject/head.tmpl into <head> and custom/templates/inject/footer.tmpl before </body> of the React index.html shell, so analytics snippets, meta tags, and footer scripts keep working after the web interface stops using the server-side template engine. A new templates.ReadInjectFile helper reads the custom file from disk when present and falls back to the empty embedded default.
  • Injected content is inserted verbatim (plain HTML). Go template directives are no longer evaluated in these files.
  • Static file overrides under 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)

  • Top-of-page <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.
  • Added a note that injected content is inserted verbatim.

Docs (docs/asking/release-strategy.mdx)

  • Source builds are no longer recommended; point readers to the per-commit latest-commit-build binary release.

Changelog

  • Refined the existing +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:lint clean; default and prod build tags compile.

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.
@mintlify

mintlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Gogs 🟢 Ready View Preview Jul 16, 2026, 3:13 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@mintlify

mintlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Gogs 🟡 Building Jul 16, 2026, 3:12 AM

💡 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.
unknwon added 2 commits July 16, 2026 10:23
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.
@unknwon unknwon changed the title docs: deprecate custom templates and source builds web: keep content injection working under the React shell Jul 16, 2026
@unknwon
unknwon requested a review from Copilot July 16, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.ReadInjectFile to load inject/*.tmpl from custom/ with an embedded empty default fallback.
  • Updated renderIndex to splice head.tmpl into the React shell <head> and footer.tmpl before </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 thread templates/embed.go
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>
@gogs gogs deleted a comment from goransh-walia Aug 22, 2026
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.

2 participants