Skip to content

Commit f1d6a1f

Browse files
Add the ability to have built in themes in Gitea (#4198)
This makes it easier for user who want to theme but don't have the ability to know how to customize templates all that is required is a change in a config option The reason why I chose the DEFAULT_THEME as variable, as perhaps in the future we will allow users to chose their theme whon logged in just like we do with languages
1 parent 28c1c90 commit f1d6a1f

File tree

11 files changed

+849
-75
lines changed

11 files changed

+849
-75
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ else
5555
endif
5656
endif
5757

58+
# $(call strip-suffix,filename)
59+
strip-suffix = $(firstword $(subst ., ,$(1)))
60+
5861
.PHONY: all
5962
all: build
6063

@@ -301,7 +304,7 @@ public/js/index.js: $(JAVASCRIPTS)
301304

302305
.PHONY: stylesheets-check
303306
stylesheets-check: generate-stylesheets
304-
@diff=$$(git diff public/css/index.css); \
307+
@diff=$$(git diff public/css/*); \
305308
if [ -n "$$diff" ]; then \
306309
echo "Please run 'make generate-stylesheets' and commit the result:"; \
307310
echo "$${diff}"; \
@@ -311,6 +314,7 @@ stylesheets-check: generate-stylesheets
311314
.PHONY: generate-stylesheets
312315
generate-stylesheets:
313316
node_modules/.bin/lessc --clean-css public/less/index.less public/css/index.css
317+
$(foreach file, $(filter-out public/less/themes/_base.less, $(wildcard public/less/themes/*)),node_modules/.bin/lessc --clean-css public/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
314318

315319
.PHONY: swagger-ui
316320
swagger-ui:

custom/conf/app.ini.sample

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ THEME_COLOR_META_TAG = `#6cc644`
7575
MAX_DISPLAY_FILE_SIZE = 8388608
7676
; Whether the email of the user should be shown in the Explore Users page
7777
SHOW_USER_EMAIL = true
78+
; Set the default theme for the Gitea install
79+
DEFAULT_THEME = gitea
7880

7981
[ui.admin]
8082
; Number of users that are displayed on one page

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
6868
- `EXPLORE_PAGING_NUM`: **20**: Number of repositories that are shown in one explore page.
6969
- `ISSUE_PAGING_NUM`: **10**: Number of issues that are shown in one page (for all pages that list issues).
7070
- `FEED_MAX_COMMIT_NUM`: **5**: Number of maximum commits shown in one activity feed.
71+
- `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install.
7172

7273
### UI - Admin (`ui.admin`)
7374

docs/content/doc/advanced/customizing-gitea.en-us.md

+4
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ Apart from `extra_links.tmpl` and `extra_tabs.tmpl`, there are other useful temp
9191
## Customizing gitignores, labels, licenses, locales, and readmes.
9292

9393
Place custom files in corresponding sub-folder under `custom/options`.
94+
95+
## Customizing the look of Gitea
96+
97+
Gitea has two built-in themes, the default theme `gitea`, and a dark theme `arc-green`. To change the look of your Gitea install change the value of `DEFAULT_THEME` in the [ui](https://docs.gitea.io/en-us/config-cheat-sheet/#ui-ui) section of `app.ini` to another one of the available options.

modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ var (
280280
ThemeColorMetaTag string
281281
MaxDisplayFileSize int64
282282
ShowUserEmail bool
283+
DefaultTheme string
283284

284285
Admin struct {
285286
UserPagingNum int
@@ -303,6 +304,7 @@ var (
303304
ReactionMaxUserNum: 10,
304305
ThemeColorMetaTag: `#6cc644`,
305306
MaxDisplayFileSize: 8388608,
307+
DefaultTheme: `gitea`,
306308
Admin: struct {
307309
UserPagingNum int
308310
RepoPagingNum int

modules/templates/helper.go

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func NewFuncMap() []template.FuncMap {
186186
"ParseDeadline": func(deadline string) []string {
187187
return strings.Split(deadline, "|")
188188
},
189+
"DefaultTheme": func() string {
190+
return setting.UI.DefaultTheme
191+
},
189192
}}
190193
}
191194

0 commit comments

Comments
 (0)