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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. ---
  2. date: "2017-04-15T14:56:00+02:00"
  3. title: "Customizing Gitea"
  4. slug: "customizing-gitea"
  5. weight: 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. weight: 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 running directory, 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](https://docs.gitea.io/en-us/config-cheat-sheet/)
  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](https://docs.gitea.io/en-us/environment-variables/)
  41. **Note:** Gitea must perform a full restart to see configuration changes.
  42. **Table of Contents**
  43. {{< toc >}}
  44. ## Serving custom public files
  45. To make Gitea serve custom public files (like pages and images), use the folder
  46. `$GITEA_CUSTOM/public/` as the webroot. Symbolic links will be followed.
  47. At the moment, only files in the `public/assets/` folder are served.
  48. For example, a file `image.png` stored in `$GITEA_CUSTOM/public/assets/`, can be accessed with
  49. the url `http://gitea.domain.tld/assets/image.png`.
  50. ## Changing the logo
  51. To build a custom logo and/or favicon clone the Gitea source repository, replace `assets/logo.svg` and/or `assets/favicon.svg` and run
  52. `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:
  53. - `public/assets/img/logo.svg` - Used for site icon, app icon
  54. - `public/assets/img/logo.png` - Used for Open Graph
  55. - `public/assets/img/avatar_default.png` - Used as the default avatar image
  56. - `public/assets/img/apple-touch-icon.png` - Used on iOS devices for bookmarks
  57. - `public/assets/img/favicon.svg` - Used for favicon
  58. - `public/assets/img/favicon.png` - Used as fallback for browsers that don't support SVG favicons
  59. 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/).
  60. ## Customizing Gitea pages and resources
  61. Gitea's executable contains all the resources required to run: templates, images, style-sheets
  62. and translations. Any of them can be overridden by placing a replacement in a matching path
  63. inside the `custom` directory. For example, to replace the default `.gitignore` provided
  64. for C++ repositories, we want to replace `options/gitignore/C++`. To do this, a replacement
  65. must be placed in `$GITEA_CUSTOM/options/gitignore/C++` (see about the location of the `CustomPath`
  66. directory at the top of this document).
  67. Every single page of Gitea can be changed. Dynamic content is generated using [go templates](https://golang.org/pkg/html/template/),
  68. which can be modified by placing replacements below the `$GITEA_CUSTOM/templates` directory.
  69. To obtain any embedded file (including templates), the [`gitea embedded` tool]({{< relref "doc/administration/cmd-embedded.en-us.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).
  70. Be aware that any statement contained inside `{{` and `}}` are Gitea's template syntax and
  71. shouldn't be touched without fully understanding these components.
  72. ### Customizing startpage / homepage
  73. 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`.
  74. Edit as you wish.
  75. Dont forget to restart your Gitea to apply the changes.
  76. ### Adding links and tabs
  77. 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.
  78. 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:
  79. 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`.
  80. To match the current style, the link should have the class name "item", and you can use `{{AppSubUrl}}` to get the base URL:
  81. `<a class="item" href="{{AppSubUrl}}/assets/impressum.html">Impressum</a>`
  82. For more information, see [Adding Legal Pages](https://docs.gitea.io/en-us/adding-legal-pages).
  83. You can add new tabs in the same way, putting them in `extra_tabs.tmpl`.
  84. The exact HTML needed to match the style of other tabs is in the file
  85. `templates/repo/header.tmpl`
  86. ([source in GitHub](https://github.com/go-gitea/gitea/blob/main/templates/repo/header.tmpl))
  87. ### Other additions to the page
  88. Apart from `extra_links.tmpl` and `extra_tabs.tmpl`, there are other useful templates you can put in your `$GITEA_CUSTOM/templates/custom/` directory:
  89. - `header.tmpl`, just before the end of the `<head>` tag where you can add custom CSS files for instance.
  90. - `body_outer_pre.tmpl`, right after the start of `<body>`.
  91. - `body_inner_pre.tmpl`, before the top navigation bar, but already inside the main container `<div class="full height">`.
  92. - `body_inner_post.tmpl`, before the end of the main container.
  93. - `body_outer_post.tmpl`, before the bottom `<footer>` element.
  94. - `footer.tmpl`, right before the end of the `<body>` tag, a good place for additional JavaScript.
  95. #### Example: PlantUML
  96. You can add [PlantUML](https://plantuml.com/) support to Gitea's markdown by using a PlantUML server.
  97. The data is encoded and sent to the PlantUML server which generates the picture. There is an online
  98. demo server at http://www.plantuml.com/plantuml, but if you (or your users) have sensitive data you
  99. can set up your own [PlantUML server](https://plantuml.com/server) instead. To set up PlantUML rendering,
  100. copy JavaScript files from https://gitea.com/davidsvantesson/plantuml-code-highlight and put them in your
  101. `$GITEA_CUSTOM/public/assets/` folder. Then add the following to `custom/footer.tmpl`:
  102. ```html
  103. <script>
  104. $(async () => {
  105. if (!$('.language-plantuml').length) return;
  106. await Promise.all([
  107. $.getScript('https://your-gitea-server.com/assets/deflate.js'),
  108. $.getScript('https://your-gitea-server.com/assets/encode.js'),
  109. $.getScript('https://your-gitea-server.com/assets/plantuml_codeblock_parse.js'),
  110. ]);
  111. // Replace call with address to your plantuml server
  112. parsePlantumlCodeBlocks("https://www.plantuml.com/plantuml");
  113. });
  114. </script>
  115. ```
  116. You can then add blocks like the following to your markdown:
  117. ```plantuml
  118. Alice -> Bob: Authentication Request
  119. Bob --> Alice: Authentication Response
  120. Alice -> Bob: Another authentication Request
  121. Alice <-- Bob: Another authentication Response
  122. ```
  123. The script will detect tags with `class="language-plantuml"`, but you can change this by providing a second argument to `parsePlantumlCodeBlocks`.
  124. #### Example: STL Preview
  125. You can display STL file directly in Gitea by adding:
  126. ```html
  127. <script>
  128. function lS(src) {
  129. return new Promise(function (resolve, reject) {
  130. let s = document.createElement("script");
  131. s.src = src;
  132. s.addEventListener("load", () => {
  133. resolve();
  134. });
  135. document.body.appendChild(s);
  136. });
  137. }
  138. if ($('.view-raw>a[href$=".stl" i]').length) {
  139. $("body").append(
  140. '<link href="/assets/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
  141. );
  142. Promise.all([
  143. lS("/assets/Madeleine.js/src/lib/stats.js"),
  144. lS("/assets/Madeleine.js/src/lib/detector.js"),
  145. lS("/assets/Madeleine.js/src/lib/three.min.js"),
  146. lS("/assets/Madeleine.js/src/Madeleine.js"),
  147. ]).then(function () {
  148. $(".view-raw")
  149. .attr("id", "view-raw")
  150. .attr("style", "padding: 0;margin-bottom: -10px;");
  151. new Madeleine({
  152. target: "view-raw",
  153. data: $('.view-raw>a[href$=".stl" i]').attr("href"),
  154. path: "/assets/Madeleine.js/src",
  155. });
  156. $('.view-raw>a[href$=".stl"]').remove();
  157. });
  158. }
  159. </script>
  160. ```
  161. to the file `templates/custom/footer.tmpl`
  162. 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.
  163. You should end-up with a folder structure similar to:
  164. ```
  165. $GITEA_CUSTOM/templates
  166. -- custom
  167. `-- footer.tmpl
  168. $GITEA_CUSTOM/public/assets/
  169. -- Madeleine.js
  170. |-- LICENSE
  171. |-- README.md
  172. |-- css
  173. | |-- pygment_trac.css
  174. | `-- stylesheet.css
  175. |-- examples
  176. | |-- ajax.html
  177. | |-- index.html
  178. | `-- upload.html
  179. |-- images
  180. | |-- bg_hr.png
  181. | |-- blacktocat.png
  182. | |-- icon_download.png
  183. | `-- sprite_download.png
  184. |-- models
  185. | |-- dino2.stl
  186. | |-- ducati.stl
  187. | |-- gallardo.stl
  188. | |-- lamp.stl
  189. | |-- octocat.stl
  190. | |-- skull.stl
  191. | `-- treefrog.stl
  192. `-- src
  193. |-- Madeleine.js
  194. |-- css
  195. | `-- Madeleine.css
  196. |-- icons
  197. | |-- logo.png
  198. | |-- madeleine.eot
  199. | |-- madeleine.svg
  200. | |-- madeleine.ttf
  201. | `-- madeleine.woff
  202. `-- lib
  203. |-- MadeleineConverter.js
  204. |-- MadeleineLoader.js
  205. |-- detector.js
  206. |-- stats.js
  207. `-- three.min.js
  208. ```
  209. Then restart Gitea and open a STL file on your Gitea instance.
  210. ## Customizing Gitea mails
  211. The `$GITEA_CUSTOM/templates/mail` folder allows changing the body of every mail of Gitea.
  212. Templates to override can be found in the
  213. [`templates/mail`](https://github.com/go-gitea/gitea/tree/main/templates/mail)
  214. directory of Gitea source.
  215. Override by making a copy of the file under `$GITEA_CUSTOM/templates/mail` using a
  216. full path structure matching source.
  217. Any statement contained inside `{{` and `}}` are Gitea's template
  218. syntax and shouldn't be touched without fully understanding these components.
  219. ## Adding Analytics to Gitea
  220. 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.
  221. ## Customizing gitignores, labels, licenses, locales, and readmes.
  222. Place custom files in corresponding sub-folder under `custom/options`.
  223. **NOTE:** The files should not have a file extension, e.g. `Labels` rather than `Labels.txt`
  224. ### gitignores
  225. To add custom .gitignore, add a file with existing [.gitignore rules](https://git-scm.com/docs/gitignore) in it to `$GITEA_CUSTOM/options/gitignore`
  226. ## Customizing the git configuration
  227. Starting with Gitea 1.20, you can customize the git configuration via the `git.config` section.
  228. ### Enabling signed git pushes
  229. To enable signed git pushes, set these two options:
  230. ```ini
  231. [git.config]
  232. receive.advertisePushOptions = true
  233. receive.certNonceSeed = <randomstring>
  234. ```
  235. `certNonceSeed` should be set to a random string and be kept secret.
  236. ### Labels
  237. 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`:
  238. ```yaml
  239. labels:
  240. - name: "foo/bar" # name of the label that will appear in the dropdown
  241. exclusive: true # whether to use the exclusive namespace for scoped labels. scoped delimiter is /
  242. color: aabbcc # hex colour coding
  243. description: Some label # long description of label intent
  244. ```
  245. 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.
  246. `#hex-color label name ; label description`
  247. For more information, see the [labels documentation]({{< relref "doc/usage/labels.en-us.md" >}}).
  248. ### Licenses
  249. To add a custom license, add a file with the license text to `$GITEA_CUSTOM/options/license`
  250. ### Locales
  251. Locales are managed via our [Crowdin](https://crowdin.com/project/gitea).
  252. You can override a locale by placing an altered locale file in `$GITEA_CUSTOM/options/locale`.
  253. 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.
  254. 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.
  255. ```
  256. [i18n]
  257. LANGS = en-US,foo-BAR
  258. NAMES = English,FooBar
  259. ```
  260. The first locale will be used as the default if user browser's language doesn't match any locale in the list.
  261. Locales may change between versions, so keeping track of your customized locales is highly encouraged.
  262. ### Readmes
  263. To add a custom Readme, add a markdown formatted file (without an `.md` extension) to `$GITEA_CUSTOM/options/readme`
  264. **NOTE:** readme templates support **variable expansion**.
  265. currently there are `{Name}` (name of repository), `{Description}`, `{CloneURL.SSH}`, `{CloneURL.HTTPS}` and `{OwnerName}`
  266. ### Reactions
  267. To change reaction emoji's you can set allowed reactions at app.ini
  268. ```
  269. [ui]
  270. REACTIONS = +1, -1, laugh, confused, heart, hooray, eyes
  271. ```
  272. A full list of supported emoji's is at [emoji list](https://gitea.com/gitea/gitea.com/issues/8)
  273. ## Customizing the look of Gitea
  274. The default built-in themes are `gitea` (light), `arc-green` (dark), and `auto` (chooses light or dark depending on operating system settings).
  275. 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`.
  276. Gitea also has support for user themes, which means every user can select which theme should be used.
  277. 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`.
  278. To make a custom theme available to all users:
  279. 1. Add a CSS file to `$GITEA_CUSTOM/public/assets/css/theme-<theme-name>.css`.
  280. The value of `$GITEA_CUSTOM` of your instance can be queried by calling `gitea help` and looking up the value of "CustomPath".
  281. 2. Add `<theme-name>` to the comma-separated list of setting `THEMES` in `app.ini`
  282. Community themes are listed in [gitea/awesome-gitea#themes](https://gitea.com/gitea/awesome-gitea#themes).
  283. 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).
  284. If your custom theme is considered a dark theme, set the global css variable `--is-dark-theme` to `true`.
  285. This allows Gitea to adjust the Monaco code editor's theme accordingly.
  286. ## Customizing fonts
  287. Fonts can be customized using CSS variables:
  288. ```css
  289. :root {
  290. --fonts-proportional: /* custom proportional fonts */ !important;
  291. --fonts-monospace: /* custom monospace fonts */ !important;
  292. --fonts-emoji: /* custom emoji fonts */ !important;
  293. }
  294. ```