The Wayback Machine - https://web.archive.org/web/20220329133622/https://github.com/go-gitea/gitea/pull/19130
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom favicon when viewing static files if it exists #19130

Merged
merged 4 commits into from Mar 19, 2022

Conversation

ADawesomeguy
Copy link
Contributor

@ADawesomeguy ADawesomeguy commented Mar 18, 2022

Redirect /favicon.ico to /assets/img/favicon.png.

Fix #19109

@6543 6543 added the kind/bug label Mar 18, 2022
@6543 6543 added this to the 1.17.0 milestone Mar 18, 2022
// the custom favicon should be seen when viewing files instead of the default one if it exists,
routes.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) {
faviconPath := ""
res, err := http.Get(path.Join(setting.StaticURLPrefix, "/assets/img/favicon.ico"))
Copy link
Member

@Gusted Gusted Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to only check this once and not make a request every time when favicon.ico is requested. We can use os.Stat to check if such file exists.

Copy link
Member

@silverwind silverwind Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of logo files that are known to exist, basically the output files here:

generate(svg, resolve(__dirname, '../public/img/logo.svg'), {size: 32}),
generate(svg, resolve(__dirname, '../public/img/logo.png'), {size: 512}),
generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180}),
generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}),
generate(svg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true}),

If browser accept redirecting ico to either svg or png, I think this is the solution we should go for as favicon.ico generally does not exist for our installations (but users could provide it for compatibilty)

Copy link
Contributor Author

@ADawesomeguy ADawesomeguy Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may work to redirect to PNG, I'll give that a shot.

Copy link
Member

@silverwind silverwind Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's likely if PNG works, it will work with SVG as well, see https://caniuse.com/link-icon-svg for browser support.

Copy link
Member

@silverwind silverwind Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to just generate a ico in above script, but that might be more complicated, and I think it should only be a last-resort option if those redirects don't work.

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

Alright, cool! I'll give it a shot.

@ADawesomeguy ADawesomeguy requested review from Gusted and silverwind Mar 19, 2022
lunny
lunny approved these changes Mar 19, 2022
Gusted
Gusted approved these changes Mar 19, 2022
@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 19, 2022

make lgtm work

@zeripath zeripath merged commit f96e8be into go-gitea:main Mar 19, 2022
2 checks passed
@ADawesomeguy ADawesomeguy deleted the custom-favicon-fix branch Mar 19, 2022
@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 20, 2022

I guess we should backport this.

@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 20, 2022

@ADawesomeguy are you able to send a backport PR?

This is my backport script: (if it helps)
#!/bin/sh
PR="$1"
SHA="$2"
VERSION="$3"

if [ -z "$SHA" ]; then
    SHA=$(gh api /repos/go-gitea/gitea/pulls/$PR -q '.merge_commit_sha')
fi

if [ -z "$VERSION" ]; then
    VERSION="v1.16"
fi

echo git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git cherry-pick $SHA && git commit --amend && git push ADawesomeguy backport-$PR-$VERSION && xdg-open https://github.com/go-gitea/gitea/compare/release/"$VERSION"...ADawesomeguy:backport-$PR-$VERSION

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 20, 2022

Do you want me to run that, because yeah sure I can do that. What exactly is a backport?

@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 20, 2022

By backport I mean cherry-pick f96e8be on to release/v1.16,

That cherrypick branch would then be used to open a PR against release/v1.16 titled: Use custom favicon when viewing static files if it exists (#19130) (← it must be this title) the PR initial comment should be:

Backport #19130

Redirect `/favicon.ico` to `/assets/img/favicon.png`.

Fix #19109 

ADawesomeguy added a commit to ADawesomeguy/gitea that referenced this issue Mar 20, 2022
@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 20, 2022

@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 20, 2022

yeah basically.

@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 20, 2022

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 20, 2022

Alright, done!

techknowlogick pushed a commit that referenced this issue Mar 21, 2022
…19152)

Redirect `/favicon.ico` to `/assets/img/favicon.png`.

Fix #19109

Co-authored-by: zeripath <[email protected]>
zjjhot added a commit to zjjhot/gitea that referenced this issue Mar 21, 2022
* giteaofficial/main:
  Add 1.18 (go-gitea#19151)
  [skip ci] Updated translations via Crowdin
  Fix NPE `/repos/issues/search` when not signed in (go-gitea#19154)
  [skip ci] Updated licenses and gitignores
  Use custom favicon when viewing static files if it exists (go-gitea#19130)
  not send notification emails to inactive users (part 2) (go-gitea#19142)
  Make migrations SKIP_TLS_VERIFY apply to git too (go-gitea#19132)
  Do not send notification emails to inactive users (go-gitea#19131)
@silverwind
Copy link
Member

@silverwind silverwind commented Mar 21, 2022

Seems to work fine in Firefox. At some point in the future, we should redirect to the SVG.

zeripath added a commit to zeripath/gitea that referenced this issue Mar 23, 2022
 ## [1.16.5](https://github.com/go-gitea/gitea/releases/tag/1.16.5) - 2022-03-23

* BREAKING
  * Bump to build with go1.18 (go-gitea#19120 et al) (go-gitea#19127)
* SECURITY
  * Prevent redirect to Host (2) (go-gitea#19175) (go-gitea#19186)
  * Try to prevent autolinking of displaynames by email readers (go-gitea#19169) (go-gitea#19183)
  * Clean paths when looking in Storage (go-gitea#19124) (go-gitea#19179)
  * Do not send notification emails to inactive users (go-gitea#19131) (go-gitea#19139)
  * Do not send activation email if manual confirm is set (go-gitea#19119) (go-gitea#19122)
* ENHANCEMENTS
  * Use the new/choose link for New Issue on project page (go-gitea#19172) (go-gitea#19176)
* BUGFIXES
  * Fix compare link in active feeds for new branch (go-gitea#19149) (go-gitea#19185)
  * Redirect .wiki/* ui link to /wiki (go-gitea#18831) (go-gitea#19184)
  * Ensure deploy keys with write access can push (go-gitea#19010) (go-gitea#19182)
  * Ensure that setting.LocalURL always has a trailing slash (go-gitea#19171) (go-gitea#19177)
  * Cleanup protected branches when deleting users & teams (go-gitea#19158) (go-gitea#19174)
  * Use IterateBufferSize whilst querying repositories during adoption check (go-gitea#19140) (go-gitea#19160)
  * Fix NPE /repos/issues/search when not signed in (go-gitea#19154) (go-gitea#19155)
  * Use custom favicon when viewing static files if it exists (go-gitea#19130) (go-gitea#19152)
  * Fix the editor height in review box (go-gitea#19003) (go-gitea#19147)
  * Ensure isSSH is set whenever DISABLE_HTTP_GIT is set (go-gitea#19028) (go-gitea#19146)
  * Fix wrong scopes caused by empty scope input (go-gitea#19029) (go-gitea#19145)
  * Make migrations SKIP_TLS_VERIFY apply to git too (go-gitea#19132) (go-gitea#19141)
  * Handle email address not exist (go-gitea#19089) (go-gitea#19121)
* MISC
  * Update json-iterator to allow compilation with go1.18 (go-gitea#18644) (go-gitea#19100)
  * Update golang.org/x/crypto (go-gitea#19097) (go-gitea#19098)

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath zeripath mentioned this pull request Mar 23, 2022
zjjhot added a commit to zjjhot/gitea that referenced this issue Mar 25, 2022
…se/v1.16

* giteaofficial/release/v1.16: (53 commits)
  Bump goldmark to v1.4.11 (go-gitea#19201) (go-gitea#19203)
  Changelog for 1.16.5 (go-gitea#19189)
  Fix showing issues in your repositories (go-gitea#18916) (go-gitea#19191)
  Prevent redirect to Host (2) (go-gitea#19175) (go-gitea#19186)
  Fix compare link in active feeds for new branch (go-gitea#19149) (go-gitea#19185)
  Redirect .wiki/* ui link to /wiki (go-gitea#18831) (go-gitea#19184)
  Prevent start panic due to missing DotEscape function
  Fix the bug: deploy key with write access can not push (go-gitea#19010) (go-gitea#19182)
  Try to prevent autolinking of displaynames by email readers (go-gitea#19169) (go-gitea#19183)
  Clean paths when looking in Storage (go-gitea#19124) (go-gitea#19179)
  Cleanup protected branches when deleting users & teams (go-gitea#19158) (go-gitea#19174)
  Ensure that setting.LocalURL always has a trailing slash (go-gitea#19171) (go-gitea#19177)
  Use the new/choose link for New Issue on project page (go-gitea#19172) (go-gitea#19176)
  Use IterateBufferSize whilst querying repositories during adoption check (go-gitea#19140) (go-gitea#19160)
  Ensure isSSH is set whenever DISABLE_HTTP_GIT is set (go-gitea#19028) (go-gitea#19146)
  Use custom favicon when viewing static files if it exists (go-gitea#19130) (go-gitea#19152)
  Fix NPE /repos/issues/search when not signed in (go-gitea#19154) (go-gitea#19155)
  Fix wrong scopes caused by empty scope input (go-gitea#19029) (go-gitea#19145)
  Fix the editor height in review box (go-gitea#19003) (go-gitea#19147)
  Do not send notification emails to inactive users (go-gitea#19131) (go-gitea#19139)
  ...
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…9130)

Redirect `/favicon.ico` to `/assets/img/favicon.png`.

Fix go-gitea#19109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

7 participants