Add a favicon to redmine theme

时间秒杀一切 提交于 2019-12-10 20:06:41

问题


redmine uses the favicon placed at /usr/share/redmine/public/favicon.ico

I found a lot of code snippets using cd /usr/share/redmine/; grep -HR favicon app/

app/helpers/application_helper.rb:  def favicon
app/helpers/application_helper.rb:    "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe
app/helpers/application_helper.rb:  # Returns the path to the favicon
app/helpers/application_helper.rb:  def favicon_path
app/helpers/application_helper.rb:    icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
app/helpers/application_helper.rb:  # Returns the full URL to the favicon
app/helpers/application_helper.rb:  def favicon_url
app/helpers/application_helper.rb:    path = favicon_path
app/views/journals/index.builder:  xml.icon    favicon_url
app/views/common/feed.atom.builder:  xml.icon    favicon_url
app/views/layouts/base.html.erb:<%= favicon %>

But no luck finding more info about how to set the favicon_path or favicon_url.

Workaround:

I added a small javascript in the theme folder: javascripts/theme.js:

document.head = document.head || document.getElementsByTagName('head')[0];

function changeFavicon(src) {
 var link = document.createElement('link'),
     oldLink = document.getElementById('dynamic-favicon');
 link.id = 'dynamic-favicon';
 link.rel = 'shortcut icon';
 link.href = src;
 if (oldLink) {
  document.head.removeChild(oldLink);
 }
 document.head.appendChild(link);
}

changeFavicon('../themes/freifunk-red-andy/images/favicon.ico');

(But that workaround only works if the visitor uses javascript)


回答1:


Redmine automatically loads the first file it finds inside the favicon sub-directory of your theme. Thus, if you put your favicon into e.g. favicon/favicon.ico, it will be automatically used by Redmine.




回答2:


I think this question is ambiguous as there are 2 places you have to consider depending what you really want to do.

If you want to change the favicon of ...

  1. ... an additionally installed theme you have to go with @Holger Just 's answer (https://stackoverflow.com/a/27440983/887930) and copy your own favicon into the folder redmine/htdocs/public/themes/YOURTHEME/favicon/ (overwrite an existing favicon.ico or create the folder favicon inside the theme's folder if necessary).
  2. ... the standard preinstalled redmine theme you have to copy your own favicon into the folder redmine/htdocs/public (overwriting the existing favicon.ico)


来源:https://stackoverflow.com/questions/27417402/add-a-favicon-to-redmine-theme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!