Skip to content

Commit 4cd94e3

Browse files
authored
gitea png to logo (#13974)
* gitea png to logo.svg * gitea safari svg to logo * minify svgs * Update english docs * Update missing section on customizing logo
1 parent e25e7b9 commit 4cd94e3

File tree

20 files changed

+52
-25
lines changed

20 files changed

+52
-25
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ generate-gitignore:
699699
.PHONY: generate-images
700700
generate-images:
701701
npm install --no-save --no-package-lock fabric imagemin-zopfli
702-
node build/generate-images.js
702+
node build/generate-images.js $(TAGS)
703703

704704
.PHONY: pr\#%
705705
pr\#%: clean-all

build/generate-images.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const {readFile, writeFile} = require('fs').promises;
77
const {resolve} = require('path');
88
const Svgo = require('svgo');
99

10+
const logoFile = resolve(__dirname, '../assets/logo.svg');
11+
1012
function exit(err) {
1113
if (err) console.error(err);
1214
process.exit(err ? 1 : 0);
@@ -39,6 +41,12 @@ async function generateSvgFavicon(svg, outputFile) {
3941
await writeFile(outputFile, data);
4042
}
4143

44+
async function generateSvg(svg, outputFile) {
45+
const svgo = new Svgo();
46+
const {data} = await svgo.optimize(svg);
47+
await writeFile(outputFile, data);
48+
}
49+
4250
async function generate(svg, outputFile, {size, bg}) {
4351
const {objects, options} = await loadSvg(svg);
4452
const canvas = new fabric.Canvas();
@@ -69,15 +77,26 @@ async function generate(svg, outputFile, {size, bg}) {
6977
}
7078

7179
async function main() {
72-
const svg = await readFile(resolve(__dirname, '../assets/logo.svg'), 'utf8');
73-
await generateSvgFavicon(svg, resolve(__dirname, '../public/img/favicon.svg'));
74-
await generate(svg, resolve(__dirname, '../public/img/gitea-lg.png'), {size: 880});
75-
await generate(svg, resolve(__dirname, '../public/img/gitea-512.png'), {size: 512});
76-
await generate(svg, resolve(__dirname, '../public/img/gitea-192.png'), {size: 192});
77-
await generate(svg, resolve(__dirname, '../public/img/gitea-sm.png'), {size: 120});
78-
await generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200});
79-
await generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180});
80-
await generate(svg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true});
80+
const gitea = process.argv.slice(2).includes('gitea');
81+
82+
const svg = await readFile(logoFile, 'utf8');
83+
await Promise.all([
84+
generateSvgFavicon(svg, resolve(__dirname, '../public/img/favicon.svg')),
85+
generateSvg(svg, resolve(__dirname, '../public/img/logo.svg')),
86+
generate(svg, resolve(__dirname, '../public/img/logo-lg.png'), {size: 880}),
87+
generate(svg, resolve(__dirname, '../public/img/logo-512.png'), {size: 512}),
88+
generate(svg, resolve(__dirname, '../public/img/logo-192.png'), {size: 192}),
89+
generate(svg, resolve(__dirname, '../public/img/logo-sm.png'), {size: 120}),
90+
generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}),
91+
generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180}),
92+
generate(svg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true}),
93+
]);
94+
if (gitea) {
95+
await Promise.all([
96+
generateSvg(svg, resolve(__dirname, '../public/img/gitea.svg')),
97+
generate(svg, resolve(__dirname, '../public/img/gitea-192.png'), {size: 192}),
98+
]);
99+
}
81100
}
82101

83102
main().then(exit).catch(exit);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ To make Gitea serve custom public files (like pages and images), use the folder
5757
For example, a file `image.png` stored in `custom/public/`, can be accessed with
5858
the url `http://gitea.domain.tld/image.png`.
5959

60+
## Changing the default logo
61+
62+
To automatically update custom logo png and svg files replace `assets/logo.svg` and run `make generate-images`. This will update the user-designated logo files served in `public/img`. Alternatively, you can manually update each `logo-X.png` and `logo.svg` file in `public/img`.
63+
6064
## Changing the default avatar
6165

6266
Place the png image at the following path: `custom/public/img/avatar_default.png`

docs/content/doc/developers/hacking-on-gitea.en-us.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ SVG icons are built using the `make svg` target which compiles the icon sources
185185

186186
### Building the Logo
187187

188-
The PNG versions of the logo are built from a single SVG source file `assets/logo.svg` using the `make generate-images` target. To run it, Node.js and npm must be available. The same process can also be used to generate a custom logo PNGs from a SVG source file. It's possible to remove parts of the SVG logo for the favicon build by adding a `detail-remove` class to the SVG nodes to be removed.
188+
The PNG and SVG versions of the gitea logo are built from a single SVG source file `assets/logo.svg` using the `TAGS="gitea" make generate-images` target. To run it, Node.js and npm must be available.
189+
190+
The same process can also be used to generate custom logo PNGs from a SVG source file by updating `assets/logo.svg` and running `make generate-images`. Omitting the `gitea` tag will update only the user-designated logo files.
189191

190192
### Updating the API
191193

public/img/gitea.svg

Lines changed: 1 addition & 0 deletions
Loading

public/img/logo-192.png

4.64 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)