2017-11-27 05:44:32 +08:00
---
date: "2017-04-15T14:56:00+02:00"
title: "Customizing Gitea"
slug: "customizing-gitea"
2023-07-26 10:00:14 +08:00
sidebar_position: 100
2017-11-27 05:44:32 +08:00
toc: false
draft: false
Refactor docs (#23752)
This was intended to be a small followup for
https://github.com/go-gitea/gitea/pull/23712, but...here we are.
1. Our docs currently use `slug` as the entire URL, which makes
refactoring tricky (see https://github.com/go-gitea/gitea/pull/23712).
Instead, this PR attempts to make future refactoring easier by using
slugs as an extension of the section. (Hugo terminology)
- What the above boils down to is this PR attempts to use directory
organization as URL management. e.g. `usage/comparison.en-us.md` ->
`en-us/usage/comparison/`, `usage/packages/overview.en-us.md` ->
`en-us/usage/packages/overview/`
- Technically we could even remove `slug`, as Hugo defaults to using
filename, however at least with this PR it means `slug` only needs to be
the name for the **current file** rather than an entire URL
2. This PR adds appropriate aliases (redirects) for pages, so anything
on the internet that links to our docs should hopefully not break.
3. A minor nit I've had for a while, renaming `seek-help` to `support`.
It's a minor thing, but `seek-help` has a strange connotation to it.
4. The commits are split such that you can review the first which is the
"actual" change, and the second is added redirects so that the first
doesn't break links elsewhere.
---------
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-04-28 11:33:41 +08:00
aliases:
- /en-us/customizing-gitea
2017-11-27 05:44:32 +08:00
menu:
sidebar:
2023-03-23 23:18:24 +08:00
parent: "administration"
2017-11-27 05:44:32 +08:00
name: "Customizing Gitea"
identifier: "customizing-gitea"
2023-07-26 10:00:14 +08:00
sidebar_position: 100
2017-11-27 05:44:32 +08:00
---
# Customizing Gitea
2019-04-30 02:08:21 +08:00
Customizing Gitea is typically done using the `CustomPath` folder - by default this is
2023-07-19 17:48:54 +08:00
the `custom` folder from the working directory (WorkPath), but may be different if your build has
2019-04-30 02:08:21 +08:00
set this differently. This is the central place to override configuration settings,
2020-01-21 07:34:23 +08:00
templates, etc. You can check the `CustomPath` using `gitea help` . You can also find
the path on the _Configuration_ tab in the _Site Administration_ page. You can override
2019-04-30 02:08:21 +08:00
the `CustomPath` by setting either the `GITEA_CUSTOM` environment variable or by
using the `--custom-path` option on the `gitea` binary. (The option will override the
environment variable.)
2017-11-27 05:44:32 +08:00
2019-03-10 05:15:45 +08:00
If Gitea is deployed from binary, all default paths will be relative to the Gitea
2018-01-09 06:48:42 +08:00
binary. If installed from a distribution, these paths will likely be modified to
2019-04-30 02:08:21 +08:00
the Linux Filesystem Standard. Gitea will attempt to create required folders, including
`custom/` . Distributions may provide a symlink for `custom` using `/etc/gitea/` .
Application settings can be found in file `CustomConf` which is by default,
2021-01-19 23:50:55 +08:00
`$GITEA_CUSTOM/conf/app.ini` but may be different if your build has set this differently.
2019-04-30 02:08:21 +08:00
Again `gitea help` will allow you review this variable and you can override it using the
`--config` option on the `gitea` binary.
2017-11-27 05:44:32 +08:00
2018-01-09 06:48:42 +08:00
- [Quick Cheat Sheet ](https://docs.gitea.io/en-us/config-cheat-sheet/ )
2021-05-05 00:16:23 +08:00
- [Complete List ](https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini )
2017-11-27 05:44:32 +08:00
2019-04-30 02:08:21 +08:00
If the `CustomPath` folder can't be found despite checking `gitea help` , check the `GITEA_CUSTOM`
2018-01-09 06:48:42 +08:00
environment variable; this can be used to override the default path to something else.
2021-01-19 23:50:55 +08:00
`GITEA_CUSTOM` might, for example, be set by an init script. You can check whether the value
is set under the "Configuration" tab on the site administration page.
2018-01-09 06:48:42 +08:00
2021-04-19 23:47:49 +08:00
- [List of Environment Variables ](https://docs.gitea.io/en-us/environment-variables/ )
2018-01-09 06:48:42 +08:00
**Note:** Gitea must perform a full restart to see configuration changes.
2017-11-27 05:44:32 +08:00
## Serving custom public files
2018-01-09 06:48:42 +08:00
To make Gitea serve custom public files (like pages and images), use the folder
2021-01-19 23:50:55 +08:00
`$GITEA_CUSTOM/public/` as the webroot. Symbolic links will be followed.
2017-11-27 05:44:32 +08:00
2021-01-19 23:50:55 +08:00
For example, a file `image.png` stored in `$GITEA_CUSTOM/public/` , can be accessed with
2021-07-04 21:56:40 +08:00
the url `http://gitea.domain.tld/assets/image.png` .
2017-11-27 05:44:32 +08:00
2021-05-07 14:32:29 +08:00
## Changing the logo
2020-12-19 09:17:27 +08:00
2022-05-23 23:54:48 +08:00
To build a custom logo and/or favicon clone the Gitea source repository, replace `assets/logo.svg` and/or `assets/favicon.svg` and run
`make generate-images` . `assets/favicon.svg` is used for the favicon only. This will update below output files which you can then place in `$GITEA_CUSTOM/public/img` on your server:
2021-01-02 03:04:35 +08:00
2022-05-23 23:54:48 +08:00
- `public/img/logo.svg` - Used for site icon, app icon
2021-05-07 14:32:29 +08:00
- `public/img/logo.png` - Used for Open Graph
- `public/img/avatar_default.png` - Used as the default avatar image
- `public/img/apple-touch-icon.png` - Used on iOS devices for bookmarks
2022-05-23 23:54:48 +08:00
- `public/img/favicon.svg` - Used for favicon
- `public/img/favicon.png` - Used as fallback for browsers that don't support SVG favicons
2020-12-19 09:17:27 +08:00
2021-05-07 14:32:29 +08:00
In case the source image is not in vector format, you can attempt to convert a raster image using tools like [this ](https://www.aconvert.com/image/png-to-svg/ ).
2017-11-27 05:44:32 +08:00
2020-02-02 10:17:44 +08:00
## Customizing Gitea pages and resources
2017-11-27 05:44:32 +08:00
2020-02-02 10:17:44 +08:00
Gitea's executable contains all the resources required to run: templates, images, style-sheets
and translations. Any of them can be overridden by placing a replacement in a matching path
inside the `custom` directory. For example, to replace the default `.gitignore` provided
for C++ repositories, we want to replace `options/gitignore/C++` . To do this, a replacement
2021-01-19 23:50:55 +08:00
must be placed in `$GITEA_CUSTOM/options/gitignore/C++` (see about the location of the `CustomPath`
2020-02-02 10:17:44 +08:00
directory at the top of this document).
2017-11-27 05:44:32 +08:00
2020-02-02 10:17:44 +08:00
Every single page of Gitea can be changed. Dynamic content is generated using [go templates ](https://golang.org/pkg/html/template/ ),
2021-01-19 23:50:55 +08:00
which can be modified by placing replacements below the `$GITEA_CUSTOM/templates` directory.
2020-02-02 10:17:44 +08:00
2023-07-26 10:00:14 +08:00
To obtain any embedded file (including templates), the [`gitea embedded` tool ](administration/cmd-embedded.md ) can be used. Alternatively, they can be found in the [`templates` ](https://github.com/go-gitea/gitea/tree/main/templates ) directory of Gitea source (Note: the example link is from the `main` branch. Make sure to use templates compatible with the release you are using).
2020-02-02 10:17:44 +08:00
Be aware that any statement contained inside `{{` and `}}` are Gitea's template syntax and
2018-01-09 06:48:42 +08:00
shouldn't be touched without fully understanding these components.
2017-11-27 05:44:32 +08:00
2019-10-29 03:11:02 +08:00
### Customizing startpage / homepage
2021-05-05 00:16:23 +08:00
Copy [`home.tmpl` ](https://github.com/go-gitea/gitea/blob/main/templates/home.tmpl ) for your version of Gitea from `templates` to `$GITEA_CUSTOM/templates` .
2019-10-29 03:11:02 +08:00
Edit as you wish.
2021-11-28 21:28:30 +08:00
Dont forget to restart your Gitea to apply the changes.
2019-10-29 03:11:02 +08:00
2018-01-12 03:56:40 +08:00
### Adding links and tabs
2017-12-03 08:26:06 +08:00
2021-01-19 23:50:55 +08:00
If all you want is to add extra links to the top navigation bar or footer, or extra tabs to the repository view, you can put them in `extra_links.tmpl` (links added to the navbar), `extra_links_footer.tmpl` (links added to the left side of footer), and `extra_tabs.tmpl` inside your `$GITEA_CUSTOM/templates/custom/` directory.
2018-01-10 14:19:50 +08:00
2018-01-12 03:56:40 +08:00
For instance, let's say you are in Germany and must add the famously legally-required "Impressum"/about page, listing who is responsible for the site's content:
2021-01-19 23:50:55 +08:00
just place it under your "$GITEA_CUSTOM/public/" directory (for instance `$GITEA_CUSTOM/public/impressum.html` ) and put a link to it in either `$GITEA_CUSTOM/templates/custom/extra_links.tmpl` or `$GITEA_CUSTOM/templates/custom/extra_links_footer.tmpl` .
2018-01-12 03:56:40 +08:00
To match the current style, the link should have the class name "item", and you can use `{{AppSubUrl}}` to get the base URL:
2021-07-16 03:49:12 +08:00
`<a class="item" href="{{AppSubUrl}}/assets/impressum.html">Impressum</a>`
2018-01-12 03:56:40 +08:00
2020-01-14 21:34:40 +08:00
For more information, see [Adding Legal Pages ](https://docs.gitea.io/en-us/adding-legal-pages ).
2018-01-12 03:56:40 +08:00
You can add new tabs in the same way, putting them in `extra_tabs.tmpl` .
The exact HTML needed to match the style of other tabs is in the file
`templates/repo/header.tmpl`
2021-05-05 00:16:23 +08:00
([source in GitHub](https://github.com/go-gitea/gitea/blob/main/templates/repo/header.tmpl))
2018-01-12 03:56:40 +08:00
### Other additions to the page
2021-01-19 23:50:55 +08:00
Apart from `extra_links.tmpl` and `extra_tabs.tmpl` , there are other useful templates you can put in your `$GITEA_CUSTOM/templates/custom/` directory:
2018-01-12 03:56:40 +08:00
- `header.tmpl` , just before the end of the `<head>` tag where you can add custom CSS files for instance.
- `body_outer_pre.tmpl` , right after the start of `<body>` .
- `body_inner_pre.tmpl` , before the top navigation bar, but already inside the main container `<div class="full height">` .
- `body_inner_post.tmpl` , before the end of the main container.
- `body_outer_post.tmpl` , before the bottom `<footer>` element.
2022-09-11 22:14:46 +08:00
- `footer.tmpl` , right before the end of the `<body>` tag, a good place for additional JavaScript.
2018-01-12 03:56:40 +08:00
2020-01-21 07:34:23 +08:00
#### Example: PlantUML
You can add [PlantUML ](https://plantuml.com/ ) support to Gitea's markdown by using a PlantUML server.
2020-04-07 07:43:17 +08:00
The data is encoded and sent to the PlantUML server which generates the picture. There is an online
demo server at http://www.plantuml.com/plantuml, but if you (or your users) have sensitive data you
2020-01-21 07:34:23 +08:00
can set up your own [PlantUML server ](https://plantuml.com/server ) instead. To set up PlantUML rendering,
2022-09-11 22:14:46 +08:00
copy JavaScript files from https://gitea.com/davidsvantesson/plantuml-code-highlight and put them in your
2021-01-19 23:50:55 +08:00
`$GITEA_CUSTOM/public` folder. Then add the following to `custom/footer.tmpl` :
2020-01-21 07:34:23 +08:00
```html
< script >
2022-05-05 15:53:38 +08:00
$(async () => {
if (!$('.language-plantuml').length) return;
await Promise.all([
2022-09-11 22:14:46 +08:00
$.getScript('https://your-gitea-server.com/assets/deflate.js'),
$.getScript('https://your-gitea-server.com/assets/encode.js'),
$.getScript('https://your-gitea-server.com/assets/plantuml_codeblock_parse.js'),
2022-05-05 15:53:38 +08:00
]);
// Replace call with address to your plantuml server
parsePlantumlCodeBlocks("https://www.plantuml.com/plantuml");
});
2020-01-21 07:34:23 +08:00
< / script >
```
You can then add blocks like the following to your markdown:
2022-07-28 09:22:47 +08:00
```plantuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
2020-04-07 07:43:17 +08:00
2022-07-28 09:22:47 +08:00
Alice -> Bob: Another authentication Request
Alice < -- Bob: Another authentication Response
```
2020-01-21 07:34:23 +08:00
The script will detect tags with `class="language-plantuml"` , but you can change this by providing a second argument to `parsePlantumlCodeBlocks` .
2020-04-23 01:02:54 +08:00
#### Example: STL Preview
You can display STL file directly in Gitea by adding:
2020-12-09 14:47:06 +08:00
2020-04-23 01:02:54 +08:00
```html
< script >
2020-12-09 14:47:06 +08:00
function lS(src) {
return new Promise(function (resolve, reject) {
let s = document.createElement("script");
s.src = src;
s.addEventListener("load", () => {
resolve();
});
document.body.appendChild(s);
});
}
if ($('.view-raw>a[href$=".stl" i]').length) {
$("body").append(
2021-07-16 03:49:12 +08:00
'< link href = "/assets/Madeleine.js/src/css/Madeleine.css" rel = "stylesheet" > '
2020-12-09 14:47:06 +08:00
);
Promise.all([
2021-07-16 03:49:12 +08:00
lS("/assets/Madeleine.js/src/lib/stats.js"),
lS("/assets/Madeleine.js/src/lib/detector.js"),
lS("/assets/Madeleine.js/src/lib/three.min.js"),
lS("/assets/Madeleine.js/src/Madeleine.js"),
2020-12-09 14:47:06 +08:00
]).then(function () {
$(".view-raw")
.attr("id", "view-raw")
.attr("style", "padding: 0;margin-bottom: -10px;");
new Madeleine({
target: "view-raw",
data: $('.view-raw>a[href$=".stl" i]').attr("href"),
2021-07-16 03:49:12 +08:00
path: "/assets/Madeleine.js/src",
2020-12-09 14:47:06 +08:00
});
$('.view-raw>a[href$=".stl"]').remove();
2020-04-23 01:02:54 +08:00
});
2020-12-09 14:47:06 +08:00
}
2020-04-23 01:02:54 +08:00
< / script >
```
2020-12-09 14:47:06 +08:00
2020-04-23 01:02:54 +08:00
to the file `templates/custom/footer.tmpl`
2022-07-12 11:51:14 +08:00
You also need to download the content of the library [Madeleine.js ](https://github.com/beige90/Madeleine.js ) and place it under `$GITEA_CUSTOM/public/` folder.
2020-04-23 01:02:54 +08:00
2021-07-19 00:21:32 +08:00
You should end-up with a folder structure similar to:
2020-12-09 14:47:06 +08:00
2020-04-23 01:02:54 +08:00
```
2021-01-19 23:50:55 +08:00
$GITEA_CUSTOM/templates
2020-04-23 01:02:54 +08:00
-- custom
`-- footer.tmpl
2021-01-19 23:50:55 +08:00
$GITEA_CUSTOM/public
2020-04-23 01:02:54 +08:00
-- Madeleine.js
|-- LICENSE
|-- README.md
|-- css
| |-- pygment_trac.css
| `-- stylesheet.css
|-- examples
| |-- ajax.html
| |-- index.html
| `-- upload.html
|-- images
| |-- bg_hr.png
| |-- blacktocat.png
| |-- icon_download.png
| `-- sprite_download.png
|-- models
| |-- dino2.stl
| |-- ducati.stl
| |-- gallardo.stl
| |-- lamp.stl
| |-- octocat.stl
| |-- skull.stl
| `-- treefrog.stl
`-- src
|-- Madeleine.js
|-- css
| `-- Madeleine.css
|-- icons
| |-- logo.png
| |-- madeleine.eot
| |-- madeleine.svg
| |-- madeleine.ttf
| `-- madeleine.woff
`-- lib
|-- MadeleineConverter.js
|-- MadeleineLoader.js
|-- detector.js
|-- stats.js
`-- three.min.js
```
2021-11-28 21:28:30 +08:00
Then restart Gitea and open a STL file on your Gitea instance.
2020-04-23 01:02:54 +08:00
2019-07-11 13:27:57 +08:00
## Customizing Gitea mails
2021-01-19 23:50:55 +08:00
The `$GITEA_CUSTOM/templates/mail` folder allows changing the body of every mail of Gitea.
2019-07-11 13:27:57 +08:00
Templates to override can be found in the
2021-05-05 00:16:23 +08:00
[`templates/mail` ](https://github.com/go-gitea/gitea/tree/main/templates/mail )
2019-07-11 13:27:57 +08:00
directory of Gitea source.
2021-01-19 23:50:55 +08:00
Override by making a copy of the file under `$GITEA_CUSTOM/templates/mail` using a
2019-07-11 13:27:57 +08:00
full path structure matching source.
Any statement contained inside `{{` and `}}` are Gitea's template
syntax and shouldn't be touched without fully understanding these components.
2018-11-05 10:21:56 +08:00
## Adding Analytics to Gitea
2021-01-19 23:50:55 +08:00
Google Analytics, Matomo (previously Piwik), and other analytics services can be added to Gitea. To add the tracking code, refer to the `Other additions to the page` section of this document, and add the JavaScript to the `$GITEA_CUSTOM/templates/custom/header.tmpl` file.
2018-11-05 10:21:56 +08:00
2017-11-27 05:44:32 +08:00
## Customizing gitignores, labels, licenses, locales, and readmes.
2018-01-09 06:48:42 +08:00
Place custom files in corresponding sub-folder under `custom/options` .
2018-07-06 05:25:04 +08:00
2019-02-28 20:09:47 +08:00
**NOTE:** The files should not have a file extension, e.g. `Labels` rather than `Labels.txt`
### gitignores
2021-01-19 23:50:55 +08:00
To add custom .gitignore, add a file with existing [.gitignore rules ](https://git-scm.com/docs/gitignore ) in it to `$GITEA_CUSTOM/options/gitignore`
2019-02-28 20:09:47 +08:00
2023-05-24 00:30:19 +08:00
## Customizing the git configuration
Starting with Gitea 1.20, you can customize the git configuration via the `git.config` section.
### Enabling signed git pushes
To enable signed git pushes, set these two options:
```ini
[git.config]
receive.advertisePushOptions = true
receive.certNonceSeed = < randomstring >
```
`certNonceSeed` should be set to a random string and be kept secret.
2019-02-28 20:09:47 +08:00
### Labels
2023-03-07 07:39:07 +08:00
Starting with Gitea 1.19, you can add a file that follows the [YAML label format ](https://github.com/go-gitea/gitea/blob/main/options/label/Advanced.yaml ) to `$GITEA_CUSTOM/options/label` :
```yaml
labels:
- name: "foo/bar" # name of the label that will appear in the dropdown
exclusive: true # whether to use the exclusive namespace for scoped labels. scoped delimiter is /
color: aabbcc # hex colour coding
description: Some label # long description of label intent
```
The [legacy file format ](https://github.com/go-gitea/gitea/blob/main/options/label/Default ) can still be used following the format below, however we strongly recommend using the newer YAML format instead.
2019-02-28 20:09:47 +08:00
`#hex-color label name ; label description`
2023-07-26 10:00:14 +08:00
For more information, see the [labels documentation ](usage/labels.md ).
2023-03-07 07:39:07 +08:00
2019-02-28 20:09:47 +08:00
### Licenses
2021-01-19 23:50:55 +08:00
To add a custom license, add a file with the license text to `$GITEA_CUSTOM/options/license`
2019-02-28 20:09:47 +08:00
### Locales
2021-12-24 11:56:57 +08:00
Locales are managed via our [Crowdin ](https://crowdin.com/project/gitea ).
2021-01-19 23:50:55 +08:00
You can override a locale by placing an altered locale file in `$GITEA_CUSTOM/options/locale` .
2021-05-05 00:16:23 +08:00
Gitea's default locale files can be found in the [`options/locale` ](https://github.com/go-gitea/gitea/tree/main/options/locale ) source folder and these should be used as examples for your changes.
2019-10-29 03:11:02 +08:00
2019-02-28 20:09:47 +08:00
To add a completely new locale, as well as placing the file in the above location, you will need to add the new lang and name to the `[i18n]` section in your `app.ini` . Keep in mind that Gitea will use those settings as **overrides** , so if you want to keep the other languages as well you will need to copy/paste the default values and add your own to them.
```
[i18n]
LANGS = en-US,foo-BAR
NAMES = English,FooBar
```
2022-04-03 17:46:48 +08:00
The first locale will be used as the default if user browser's language doesn't match any locale in the list.
2019-02-28 20:09:47 +08:00
Locales may change between versions, so keeping track of your customized locales is highly encouraged.
### Readmes
2021-01-19 23:50:55 +08:00
To add a custom Readme, add a markdown formatted file (without an `.md` extension) to `$GITEA_CUSTOM/options/readme`
2019-02-28 20:09:47 +08:00
2021-01-19 23:50:55 +08:00
**NOTE:** readme templates support **variable expansion** .
2020-04-07 09:40:38 +08:00
currently there are `{Name}` (name of repository), `{Description}` , `{CloneURL.SSH}` , `{CloneURL.HTTPS}` and `{OwnerName}`
2020-04-07 07:43:17 +08:00
2019-12-02 06:57:24 +08:00
### Reactions
To change reaction emoji's you can set allowed reactions at app.ini
2020-12-09 14:47:06 +08:00
2019-12-02 06:57:24 +08:00
```
[ui]
REACTIONS = +1, -1, laugh, confused, heart, hooray, eyes
```
2020-12-09 14:47:06 +08:00
2019-12-02 06:57:24 +08:00
A full list of supported emoji's is at [emoji list ](https://gitea.com/gitea/gitea.com/issues/8 )
2018-07-06 05:25:04 +08:00
## Customizing the look of Gitea
2021-09-27 22:47:44 +08:00
The default built-in themes are `gitea` (light), `arc-green` (dark), and `auto` (chooses light or dark depending on operating system settings).
2021-08-30 02:26:43 +08:00
The default theme can be changed via `DEFAULT_THEME` in the [ui ](https://docs.gitea.io/en-us/config-cheat-sheet/#ui-ui ) section of `app.ini` .
Gitea also has support for user themes, which means every user can select which theme should be used.
The list of themes a user can choose from can be configured with the `THEMES` value in the [ui ](https://docs.gitea.io/en-us/config-cheat-sheet/#ui-ui ) section of `app.ini` .
To make a custom theme available to all users:
2022-06-28 00:16:51 +08:00
1. Add a CSS file to `$GITEA_CUSTOM/public/css/theme-<theme-name>.css` .
The value of `$GITEA_CUSTOM` of your instance can be queried by calling `gitea help` and looking up the value of "CustomPath".
2021-08-30 02:26:43 +08:00
2. Add `<theme-name>` to the comma-separated list of setting `THEMES` in `app.ini`
Community themes are listed in [gitea/awesome-gitea#themes ](https://gitea.com/gitea/awesome-gitea#themes ).
2023-03-15 10:20:19 +08:00
The `arc-green` theme source can be found [here ](https://github.com/go-gitea/gitea/blob/main/web_src/css/themes/theme-arc-green.css ).
2020-10-20 04:01:06 +08:00
2021-11-25 15:14:48 +08:00
If your custom theme is considered a dark theme, set the global css variable `--is-dark-theme` to `true` .
2021-11-28 21:28:30 +08:00
This allows Gitea to adjust the Monaco code editor's theme accordingly.
2021-11-25 15:14:48 +08:00
2020-10-20 04:01:06 +08:00
## Customizing fonts
Fonts can be customized using CSS variables:
```css
:root {
--fonts-proportional: /* custom proportional fonts */ !important;
--fonts-monospace: /* custom monospace fonts */ !important;
--fonts-emoji: /* custom emoji fonts */ !important;
}
```