2017-11-27 05:44:32 +08:00
---
date: "2017-04-15T14:56:00+02:00"
title: "Customizing Gitea"
slug: "customizing-gitea"
weight: 9
toc: false
draft: false
menu:
sidebar:
parent: "advanced"
name: "Customizing Gitea"
identifier: "customizing-gitea"
2020-01-14 21:34:40 +08:00
weight: 9
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
the `custom` folder from the running directory, but may be different if your build has
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/ )
2020-06-18 11:16:59 +08:00
- [Complete List ](https://github.com/go-gitea/gitea/blob/master/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
- [List of Environment Variables ](https://docs.gitea.io/en-us/specific-variables/ )
**Note:** Gitea must perform a full restart to see configuration changes.
2017-11-27 05:44:32 +08:00
2020-12-09 14:47:06 +08:00
**Table of Contents**
2020-12-08 12:52:26 +08:00
{{< toc > }}
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
2018-01-09 06:48:42 +08:00
the url `http://gitea.domain.tld/image.png` .
2017-11-27 05:44:32 +08:00
2020-12-19 09:17:27 +08:00
## Changing the default logo
2021-01-02 03:04:35 +08:00
To build a custom logo replace `assets/logo.svg` and run `make generate-images` . This will update
2021-01-19 23:50:55 +08:00
these customizable logo files which you can then place in `$GITEA_CUSTOM/public/img` on your server:
2021-01-02 03:04:35 +08:00
- `public/img/logo.svg`
- `public/img/logo.png`
- `public/img/favicon.png`
- `public/img/avatar_default.png`
- `public/img/apple-touch-icon.png`
2020-12-19 09:17:27 +08:00
2017-11-27 05:44:32 +08:00
## Changing the default avatar
2021-01-02 03:04:35 +08:00
Either generate it via above method or place the png image at the following path:
2021-01-19 23:50:55 +08:00
- `$GITEA_CUSTOM/public/img/avatar_default.png`
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
To obtain any embedded file (including templates), the [`gitea embedded` tool ]({{< relref "doc/advanced/cmd-embedded.en-us.md" >}} ) can be used. Alternatively, they can be found in the [`templates` ](https://github.com/go-gitea/gitea/tree/master/templates ) directory of Gitea source (Note: the example link is from the `master` branch. Make sure to use templates compatible with the release you are using).
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-01-19 23:50:55 +08:00
Copy [`home.tmpl` ](https://github.com/go-gitea/gitea/blob/master/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.
Dont forget to restart your gitea to apply the changes.
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:
`<a class="item" href="{{AppSubUrl}}/impressum.html">Impressum</a>`
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`
([source in GitHub](https://github.com/go-gitea/gitea/blob/master/templates/repo/header.tmpl))
### 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.
- `footer.tmpl` , right before the end of the `<body>` tag, a good place for additional Javascript.
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,
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
{{if .RequireHighlightJS}}
< script src = "https://your-server.com/deflate.js" > < / script >
< script src = "https://your-server.com/encode.js" > < / script >
< script src = "https://your-server.com/plantuml_codeblock_parse.js" > < / script >
< script >
2020-12-09 14:47:06 +08:00
<!-- Replace call with address to your plantuml server -->
parsePlantumlCodeBlocks("http://www.plantuml..com/plantuml");
2020-01-21 07:34:23 +08:00
< / script >
{{end}}
```
You can then add blocks like the following to your markdown:
```plantuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
2020-04-07 07:43:17 +08:00
2020-01-21 07:34:23 +08:00
Alice -> Bob: Another authentication Request
Alice < -- Bob: Another authentication Response
```
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(
'< link href = "/Madeleine.js/src/css/Madeleine.css" rel = "stylesheet" > '
);
Promise.all([
lS("/Madeleine.js/src/lib/stats.js"),
lS("/Madeleine.js/src/lib/detector.js"),
lS("/Madeleine.js/src/lib/three.min.js"),
lS("/Madeleine.js/src/Madeleine.js"),
]).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"),
path: "/Madeleine.js/src",
});
$('.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`
2021-01-19 23:50:55 +08:00
You also need to download the content of the library [Madeleine.js ](https://jinjunho.github.io/Madeleine.js/ ) and place it under `$GITEA_CUSTOM/public/` folder.
2020-04-23 01:02:54 +08:00
You should end-up with a folder structucture 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
```
Then restart gitea and open a STL file on your gitea instance.
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
[`templates/mail` ](https://github.com/go-gitea/gitea/tree/master/templates/mail )
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
### Labels
2021-01-19 23:50:55 +08:00
To add a custom label set, add a file that follows the [label format ](https://github.com/go-gitea/gitea/blob/master/options/label/Default ) to `$GITEA_CUSTOM/options/label`
2019-02-28 20:09:47 +08:00
`#hex-color label name ; label description`
### 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-01-19 23:50:55 +08:00
Locales are managed via our [crowdin ](https://crowdin.com/project/gitea ).
You can override a locale by placing an altered locale file in `$GITEA_CUSTOM/options/locale` .
2020-12-09 14:47:06 +08:00
Gitea's default locale files can be found in the [`options/locale` ](https://github.com/go-gitea/gitea/tree/master/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
```
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-01-19 23:50:55 +08:00
As of version 1.6.0 Gitea has built-in themes. The two built-in themes are, 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.
2019-02-28 20:09:47 +08:00
As of version 1.8.0 Gitea also has per-user themes. 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` (defaults to `gitea` and `arc-green` , light and dark respectively)
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;
}
```