Skip to content

Conversation

@philip-peterson
Copy link
Contributor

@philip-peterson philip-peterson commented May 28, 2025

This PR introduces a proof of concept for rendering the Explore Users page using Gomponents instead of text/template. The goal is to evaluate Gomponents as a mechanism for backend HTML generation in Gitea.

Benefits demonstrated in this POC:

  • Typed props structures for better safety and clarity
  • Preserves server-side HTML rendering, maintaining SEO and accessibility
  • Full Go syntax highlighting in editors
  • Easier decomposition of large templates into smaller, reusable components
  • Colocated rendering logic without needing global template.FuncMap helpers
  • Includes a backwards-compatible path to reuse existing templates (e.g., headers, footers) for gradual migration

To test: visit http://localhost:3000/explore/users and verify it looks the same way it normally would.

Example:

<input
	type="search"
	name="q"
	{{with .Value}} value="{{.}}"{{end}}
	maxlength="255"
	spellcheck="false"
	placeholder="{{with .Placeholder}}{{.}}{{else}}{{ctx.Locale.Tr "search.search"}}{{end}}"
	{{if .Disabled}} disabled{{end}}
>

becomes:

func SearchInput(locale translation.Locale, value, placeholder string, disabled bool) g.Node {
	if placeholder == "" {
		placeholder = string(locale.Tr("search.search"))
	}

	return gh.Input(
		gh.Type("search"),
		gh.Name("q"),
		gh.MaxLength("255"),
		g.Attr("spellcheck", "false"),
		gh.Value(value),
		gh.Placeholder(placeholder),
		If(disabled, gh.Disabled()),
	)
}

Issue targeted: None

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 28, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/dependencies labels May 28, 2025
@wxiaoguang
Copy link
Contributor

Sorry but I do not think we should introduce a new template system at the moment.

Although tmpl is not that good, it does have many good sides:

  1. Make site admin can customize the Gitea pages
  2. Dynamically reload the changes when in dev mode, then no need to waste time on building and restarting
  3. Decouple package import dependencies
  4. Easier to read and write, more like HTML, and is supported by many IDEs
  5. The HTML part of tmpl files can be maintained by some text tools like grep (search&replace)

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/dependencies modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants