Skip to content

Commit

Permalink
Make the 500 page load themes (#24953)
Browse files Browse the repository at this point in the history
The 500 page was not loading theme CSS, so always appeared in light
theme. This extracts the stylesheets into a shared template used by all
pages.

<img width="1262" alt="image"
src="https://github.com/go-gitea/gitea/assets/115237/72222b8d-a523-40d0-aa91-b9db32e5625d">

Small related rant: I think there should only be one `<head>` in all of
the templates, but I see it was deliberatly done that the 500 page has
its own `<head>` because "it should only depend the minimal template
functions", but I disagree because we are missing a lot of things that
are in the regular `<head>`.
  • Loading branch information
silverwind authored May 27, 2023
1 parent 7de46b0 commit 4a58a8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
13 changes: 3 additions & 10 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
{{end}}
<link rel="icon" href="{{AssetUrlPrefix}}/img/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}">
{{template "base/head_script" .}}
<noscript>
<style>
Expand Down Expand Up @@ -63,15 +62,9 @@
<meta property="og:url" content="{{AppUrl}}">
<meta property="og:description" content="{{MetaDescription}}">
{{end}}
<meta property="og:site_name" content="{{AppName}}">
{{if .IsSigned}}
{{if ne .SignedUser.Theme "gitea"}}
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{.SignedUser.Theme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
{{else if ne DefaultTheme "gitea"}}
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{DefaultTheme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
{{template "custom/header" .}}
<meta property="og:site_name" content="{{AppName}}">
{{template "base/stylesheets" .}}
{{template "custom/header" .}}
</head>
<body>
{{template "custom/body_outer_pre" .}}
Expand Down
8 changes: 8 additions & 0 deletions templates/base/stylesheets.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}">
{{if .IsSigned}}
{{if ne .SignedUser.Theme "gitea"}}
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{.SignedUser.Theme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
{{else if ne DefaultTheme "gitea"}}
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{DefaultTheme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
2 changes: 1 addition & 1 deletion templates/status/500.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<title>Internal Server Error - {{AppName}}</title>
<link rel="icon" href="{{AssetUrlPrefix}}/img/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}">
{{template "base/stylesheets" .}}
</head>
<body>
<div class="full height">
Expand Down

0 comments on commit 4a58a8c

Please sign in to comment.