You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

customizing-gitea.en-us.md 17KB

Add Privacy Policy and Terms of Service Page (#9513) * Add privacy policy page and link * Add TOS page and link * Add update date * [Docs] Add customizing PP and TOS * Separate h2 user-generated content with its paragraph * Reimplement Privacy Policy The document is inspired from GitHub. * Refactor to contrib * [Docs] Mention how to add legal pages * Reimplement Terms of Service Adapted from GitHub * Update revision date * Rename to mark as sample file * Apply suggestion from @sapk Co-Authored-By: Antoine GIRARD <sapk@users.noreply.github.com> * Apply suggestion from @sapk Use absolute link instead Co-Authored-By: Antoine GIRARD <sapk@users.noreply.github.com> * Apply suggestion from @zeripath Change `Last Updated` element to `<h4>` Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Close this `<li>` element instance Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Intentionally grammar fix Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Information grammar Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Cannot guarantee absolute security... Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Use `<h4>` element for last updated date Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Remove trailing `</p>` at the end of API clause Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Migrate privacy email domain to Your Gitea Instance Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestions from @zeripath Remove `<p>` container for `<ol>` definitions Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestions from @zeripath Remove `<p>` container that contain `<ol>` user-generated content Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestions from @zeripath Remove `<p>` container for private repositories `<ol>` listing Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestions from @zeripath Migrate remaining email domains to Your Gitea Instance Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Offer support Co-Authored-By: zeripath <art27@cantab.net> * Apply suggestion from @zeripath Change "Your Gitea Instance" references to match your situation and Gitea project disclaimer Co-Authored-By: zeripath <art27@cantab.net> * Reword transmission data to reflect hosting on third-party provider * Reword Analytics clause to reflects that not all Gitea instances deploy analytics OOTB * Remove `<p>` container from account terms * Migrate support email on tos to your-gitea-instance * Reword Tracking and Analytics clause for OOTB case * [Docs] Append privacy.html to cp destination * Apply suggestion from @6543 Create or append to footer template Co-Authored-By: 6543 <6543@obermui.de> * Apply suggestion from myself @6543 suggest replacing this `cp` line (which assumed that Gitea sources are available) with `wget` to GitHub raw link. At the time of writing this, this returned 404, but when this PR has been merged, this should get the actual page. * Apply suggestions from @6543 1. Add gpg key to profile information 2. Add Git repos to list of User Personal Information 3. Comment out responsibility for sensitive information Co-Authored-By: 6543 <6543@obermui.de> Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. ---
  2. date: "2017-04-15T14:56:00+02:00"
  3. title: "Customizing Gitea"
  4. slug: "customizing-gitea"
  5. sidebar_position: 100
  6. toc: false
  7. draft: false
  8. aliases:
  9. - /en-us/customizing-gitea
  10. menu:
  11. sidebar:
  12. parent: "administration"
  13. name: "Customizing Gitea"
  14. identifier: "customizing-gitea"
  15. sidebar_position: 100
  16. ---
  17. # Customizing Gitea
  18. Customizing Gitea is typically done using the `CustomPath` folder - by default this is
  19. the `custom` folder from the working directory (WorkPath), but may be different if your build has
  20. set this differently. This is the central place to override configuration settings,
  21. templates, etc. You can check the `CustomPath` using `gitea help`. You can also find
  22. the path on the _Configuration_ tab in the _Site Administration_ page. You can override
  23. the `CustomPath` by setting either the `GITEA_CUSTOM` environment variable or by
  24. using the `--custom-path` option on the `gitea` binary. (The option will override the
  25. environment variable.)
  26. If Gitea is deployed from binary, all default paths will be relative to the Gitea
  27. binary. If installed from a distribution, these paths will likely be modified to
  28. the Linux Filesystem Standard. Gitea will attempt to create required folders, including
  29. `custom/`. Distributions may provide a symlink for `custom` using `/etc/gitea/`.
  30. Application settings can be found in file `CustomConf` which is by default,
  31. `$GITEA_CUSTOM/conf/app.ini` but may be different if your build has set this differently.
  32. Again `gitea help` will allow you review this variable and you can override it using the
  33. `--config` option on the `gitea` binary.
  34. - [Quick Cheat Sheet](administration/config-cheat-sheet.md)
  35. - [Complete List](https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini)
  36. If the `CustomPath` folder can't be found despite checking `gitea help`, check the `GITEA_CUSTOM`
  37. environment variable; this can be used to override the default path to something else.
  38. `GITEA_CUSTOM` might, for example, be set by an init script. You can check whether the value
  39. is set under the "Configuration" tab on the site administration page.
  40. - [List of Environment Variables](administration/environment-variables.md)
  41. **Note:** Gitea must perform a full restart to see configuration changes.
  42. ## Serving custom public files
  43. To make Gitea serve custom public files (like pages and images), use the folder
  44. `$GITEA_CUSTOM/public/` as the webroot. Symbolic links will be followed.
  45. At the moment, only the following files are served:
  46. - `public/robots.txt`
  47. - files in the `public/.well-known/` folder
  48. - files in the `public/assets/` folder
  49. For example, a file `image.png` stored in `$GITEA_CUSTOM/public/assets/`, can be accessed with
  50. the url `http://gitea.domain.tld/assets/image.png`.
  51. ## Changing the logo
  52. To build a custom logo and/or favicon clone the Gitea source repository, replace `assets/logo.svg` and/or `assets/favicon.svg` and run
  53. `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/assets/img` on your server:
  54. - `public/assets/img/logo.svg` - Used for site icon, app icon
  55. - `public/assets/img/logo.png` - Used for Open Graph
  56. - `public/assets/img/avatar_default.png` - Used as the default avatar image
  57. - `public/assets/img/apple-touch-icon.png` - Used on iOS devices for bookmarks
  58. - `public/assets/img/favicon.svg` - Used for favicon
  59. - `public/assets/img/favicon.png` - Used as fallback for browsers that don't support SVG favicons
  60. 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/).
  61. ## Customizing Gitea pages and resources
  62. Gitea's executable contains all the resources required to run: templates, images, style-sheets
  63. and translations. Any of them can be overridden by placing a replacement in a matching path
  64. inside the `custom` directory. For example, to replace the default `.gitignore` provided
  65. for C++ repositories, we want to replace `options/gitignore/C++`. To do this, a replacement
  66. must be placed in `$GITEA_CUSTOM/options/gitignore/C++` (see about the location of the `CustomPath`
  67. directory at the top of this document).
  68. Every single page of Gitea can be changed. Dynamic content is generated using [go templates](https://pkg.go.dev/html/template),
  69. which can be modified by placing replacements below the `$GITEA_CUSTOM/templates` directory.
  70. 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).
  71. Be aware that any statement contained inside `{{` and `}}` are Gitea's template syntax and
  72. shouldn't be touched without fully understanding these components.
  73. ### Customizing startpage / homepage
  74. 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`.
  75. Edit as you wish.
  76. Dont forget to restart your Gitea to apply the changes.
  77. ### Adding links and tabs
  78. 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.
  79. 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:
  80. just place it under your "$GITEA_CUSTOM/public/assets/" directory (for instance `$GITEA_CUSTOM/public/assets/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`.
  81. To match the current style, the link should have the class name "item", and you can use `{{AppSubUrl}}` to get the base URL:
  82. `<a class="item" href="{{AppSubUrl}}/assets/impressum.html">Impressum</a>`
  83. For more information, see [Adding Legal Pages](administration/adding-legal-pages.md).
  84. You can add new tabs in the same way, putting them in `extra_tabs.tmpl`.
  85. The exact HTML needed to match the style of other tabs is in the file
  86. `templates/repo/header.tmpl`
  87. ([source in GitHub](https://github.com/go-gitea/gitea/blob/main/templates/repo/header.tmpl))
  88. ### Other additions to the page
  89. Apart from `extra_links.tmpl` and `extra_tabs.tmpl`, there are other useful templates you can put in your `$GITEA_CUSTOM/templates/custom/` directory:
  90. - `header.tmpl`, just before the end of the `<head>` tag where you can add custom CSS files for instance.
  91. - `body_outer_pre.tmpl`, right after the start of `<body>`.
  92. - `body_inner_pre.tmpl`, before the top navigation bar, but already inside the main container `<div class="full height">`.
  93. - `body_inner_post.tmpl`, before the end of the main container.
  94. - `body_outer_post.tmpl`, before the bottom `<footer>` element.
  95. - `footer.tmpl`, right before the end of the `<body>` tag, a good place for additional JavaScript.
  96. ### Using Gitea variables
  97. It's possible to use various Gitea variables in your custom templates.
  98. First, _temporarily_ enable development mode: in your `app.ini` change from `RUN_MODE = prod` to `RUN_MODE = dev`. Then add `{{ $ | DumpVar }}` to any of your templates, restart Gitea and refresh that page; that will dump all available variables.
  99. Find the data that you need, and use the corresponding variable; for example, if you need the name of the repository then you'd use `{{.Repository.Name}}`.
  100. If you need to transform that data somehow, and aren't familiar with Go, an easy workaround is to add the data to the DOM and add a small JavaScript script block to manipulate the data.
  101. ### Example: PlantUML
  102. You can add [PlantUML](https://plantuml.com/) support to Gitea's markdown by using a PlantUML server.
  103. The data is encoded and sent to the PlantUML server which generates the picture. There is an online
  104. demo server at http://www.plantuml.com/plantuml, but if you (or your users) have sensitive data you
  105. can set up your own [PlantUML server](https://plantuml.com/server) instead. To set up PlantUML rendering,
  106. copy JavaScript files from https://gitea.com/davidsvantesson/plantuml-code-highlight and put them in your
  107. `$GITEA_CUSTOM/public/assets/` folder. Then add the following to `custom/footer.tmpl`:
  108. ```html
  109. <script>
  110. $(async () => {
  111. if (!$('.language-plantuml').length) return;
  112. await Promise.all([
  113. $.getScript('https://your-gitea-server.com/assets/deflate.js'),
  114. $.getScript('https://your-gitea-server.com/assets/encode.js'),
  115. $.getScript('https://your-gitea-server.com/assets/plantuml_codeblock_parse.js'),
  116. ]);
  117. // Replace call with address to your plantuml server
  118. parsePlantumlCodeBlocks("https://www.plantuml.com/plantuml");
  119. });
  120. </script>
  121. ```
  122. You can then add blocks like the following to your markdown:
  123. ```plantuml
  124. Alice -> Bob: Authentication Request
  125. Bob --> Alice: Authentication Response
  126. Alice -> Bob: Another authentication Request
  127. Alice <-- Bob: Another authentication Response
  128. ```
  129. The script will detect tags with `class="language-plantuml"`, but you can change this by providing a second argument to `parsePlantumlCodeBlocks`.
  130. ### Example: STL Preview
  131. You can display STL file directly in Gitea by adding:
  132. ```html
  133. <script>
  134. function lS(src) {
  135. return new Promise(function (resolve, reject) {
  136. let s = document.createElement("script");
  137. s.src = src;
  138. s.addEventListener("load", () => {
  139. resolve();
  140. });
  141. document.body.appendChild(s);
  142. });
  143. }
  144. if ($('.view-raw>a[href$=".stl" i]').length) {
  145. $("body").append(
  146. '<link href="/assets/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
  147. );
  148. Promise.all([
  149. lS("/assets/Madeleine.js/src/lib/stats.js"),
  150. lS("/assets/Madeleine.js/src/lib/detector.js"),
  151. lS("/assets/Madeleine.js/src/lib/three.min.js"),
  152. lS("/assets/Madeleine.js/src/Madeleine.js"),
  153. ]).then(function () {
  154. $(".view-raw")
  155. .attr("id", "view-raw")
  156. .attr("style", "padding: 0;margin-bottom: -10px;");
  157. new Madeleine({
  158. target: "view-raw",
  159. data: $('.view-raw>a[href$=".stl" i]').attr("href"),
  160. path: "/assets/Madeleine.js/src",
  161. });
  162. $('.view-raw>a[href$=".stl"]').remove();
  163. });
  164. }
  165. </script>
  166. ```
  167. to the file `templates/custom/footer.tmpl`
  168. 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/assets/` folder.
  169. You should end-up with a folder structure similar to:
  170. ```
  171. $GITEA_CUSTOM/templates
  172. -- custom
  173. `-- footer.tmpl
  174. $GITEA_CUSTOM/public/assets/
  175. -- Madeleine.js
  176. |-- LICENSE
  177. |-- README.md
  178. |-- css
  179. | |-- pygment_trac.css
  180. | `-- stylesheet.css
  181. |-- examples
  182. | |-- ajax.html
  183. | |-- index.html
  184. | `-- upload.html
  185. |-- images
  186. | |-- bg_hr.png
  187. | |-- blacktocat.png
  188. | |-- icon_download.png
  189. | `-- sprite_download.png
  190. |-- models
  191. | |-- dino2.stl
  192. | |-- ducati.stl
  193. | |-- gallardo.stl
  194. | |-- lamp.stl
  195. | |-- octocat.stl
  196. | |-- skull.stl
  197. | `-- treefrog.stl
  198. `-- src
  199. |-- Madeleine.js
  200. |-- css
  201. | `-- Madeleine.css
  202. |-- icons
  203. | |-- logo.png
  204. | |-- madeleine.eot
  205. | |-- madeleine.svg
  206. | |-- madeleine.ttf
  207. | `-- madeleine.woff
  208. `-- lib
  209. |-- MadeleineConverter.js
  210. |-- MadeleineLoader.js
  211. |-- detector.js
  212. |-- stats.js
  213. `-- three.min.js
  214. ```
  215. Then restart Gitea and open a STL file on your Gitea instance.
  216. ## Customizing Gitea mails
  217. The `$GITEA_CUSTOM/templates/mail` folder allows changing the body of every mail of Gitea.
  218. Templates to override can be found in the
  219. [`templates/mail`](https://github.com/go-gitea/gitea/tree/main/templates/mail)
  220. directory of Gitea source.
  221. Override by making a copy of the file under `$GITEA_CUSTOM/templates/mail` using a
  222. full path structure matching source.
  223. Any statement contained inside `{{` and `}}` are Gitea's template
  224. syntax and shouldn't be touched without fully understanding these components.
  225. ## Adding Analytics to Gitea
  226. 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.
  227. ## Customizing gitignores, labels, licenses, locales, and readmes
  228. Place custom files in corresponding sub-folder under `custom/options`.
  229. **NOTE:** The files should not have a file extension, e.g. `Labels` rather than `Labels.txt`
  230. ### gitignores
  231. To add custom .gitignore, add a file with existing [.gitignore rules](https://git-scm.com/docs/gitignore) in it to `$GITEA_CUSTOM/options/gitignore`
  232. ## Customizing the git configuration
  233. Starting with Gitea 1.20, you can customize the git configuration via the `git.config` section.
  234. ### Enabling signed git pushes
  235. To enable signed git pushes, set these two options:
  236. ```ini
  237. [git.config]
  238. receive.advertisePushOptions = true
  239. receive.certNonceSeed = <randomstring>
  240. ```
  241. `certNonceSeed` should be set to a random string and be kept secret.
  242. ### Labels
  243. 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`:
  244. ```yaml
  245. labels:
  246. - name: "foo/bar" # name of the label that will appear in the dropdown
  247. exclusive: true # whether to use the exclusive namespace for scoped labels. scoped delimiter is /
  248. color: aabbcc # hex colour coding
  249. description: Some label # long description of label intent
  250. ```
  251. 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.
  252. `#hex-color label name ; label description`
  253. For more information, see the [labels documentation](usage/labels.md).
  254. ### Licenses
  255. To add a custom license, add a file with the license text to `$GITEA_CUSTOM/options/license`
  256. ### Locales
  257. Locales are managed via our [Crowdin](https://crowdin.com/project/gitea).
  258. You can override a locale by placing an altered locale file in `$GITEA_CUSTOM/options/locale`.
  259. 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.
  260. 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.
  261. ```
  262. [i18n]
  263. LANGS = en-US,foo-BAR
  264. NAMES = English,FooBar
  265. ```
  266. The first locale will be used as the default if user browser's language doesn't match any locale in the list.
  267. Locales may change between versions, so keeping track of your customized locales is highly encouraged.
  268. ### Readmes
  269. To add a custom Readme, add a markdown formatted file (without an `.md` extension) to `$GITEA_CUSTOM/options/readme`
  270. **NOTE:** readme templates support **variable expansion**.
  271. currently there are `{Name}` (name of repository), `{Description}`, `{CloneURL.SSH}`, `{CloneURL.HTTPS}` and `{OwnerName}`
  272. ### Reactions
  273. To change reaction emoji's you can set allowed reactions at app.ini
  274. ```
  275. [ui]
  276. REACTIONS = +1, -1, laugh, confused, heart, hooray, eyes
  277. ```
  278. A full list of supported emoji's is at [emoji list](https://gitea.com/gitea/gitea.com/issues/8)
  279. ## Customizing the look of Gitea
  280. The built-in themes are `gitea-light`, `gitea-dark`, and `gitea-auto` (which automatically adapts to OS settings).
  281. The default theme can be changed via `DEFAULT_THEME` in the [ui](administration/config-cheat-sheet.md#ui-ui) section of `app.ini`.
  282. Gitea also has support for user themes, which means every user can select which theme should be used.
  283. The list of themes a user can choose from can be configured with the `THEMES` value in the [ui](administration/config-cheat-sheet.md#ui-ui) section of `app.ini`.
  284. To make a custom theme available to all users:
  285. 1. Add a CSS file to `$GITEA_CUSTOM/public/assets/css/theme-<theme-name>.css`.
  286. The value of `$GITEA_CUSTOM` of your instance can be queried by calling `gitea help` and looking up the value of "CustomPath".
  287. 2. Add `<theme-name>` to the comma-separated list of setting `THEMES` in `app.ini`
  288. Community themes are listed in [gitea/awesome-gitea#themes](https://gitea.com/gitea/awesome-gitea#themes).
  289. The default theme sources can be found [here](https://github.com/go-gitea/gitea/blob/main/web_src/css/themes).
  290. If your custom theme is considered a dark theme, set the global css variable `--is-dark-theme` to `true`.
  291. This allows Gitea to adjust the Monaco code editor's theme accordingly.
  292. ## Customizing fonts
  293. Fonts can be customized using CSS variables:
  294. ```css
  295. :root {
  296. --fonts-proportional: /* custom proportional fonts */ !important;
  297. --fonts-monospace: /* custom monospace fonts */ !important;
  298. --fonts-emoji: /* custom emoji fonts */ !important;
  299. }
  300. ```