add favicon support

This commit is contained in:
Laura Klünder 2017-12-19 19:32:58 +01:00
parent 2587f5f8ba
commit a006d8a9ec
6 changed files with 49 additions and 18 deletions

View file

@ -9,6 +9,9 @@
{% block meta %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="NONE,NOARCHIVE" />
{% if favicon %}
<link href="{% static favicon %}" rel="icon">
{% endif %}
{% endblock %}
{% block style %}

View file

@ -7,6 +7,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>{% trans 'c3nav map editor' %}</title>
{% if favicon %}
<link href="{% static favicon %}" rel="icon">
{% endif %}
{% compress css %}
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'leaflet/leaflet.css' %}" rel="stylesheet">

View file

@ -280,7 +280,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'c3nav.site.context_processors.header_logo',
'c3nav.site.context_processors.logos',
],
'loaders': template_loaders
},
@ -292,7 +292,7 @@ STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
'c3nav.site.finders.HeaderLogoFinder',
'c3nav.site.finders.LogoFinder',
)
BOOTSTRAP3 = {
@ -315,7 +315,8 @@ COMPRESS_CSS_FILTERS = (
)
HEADER_LOGO = config.get('c3nav', 'header_logo', fallback=None)
HEADER_LOGO_NAME = ('logo/'+os.path.basename(HEADER_LOGO)) if HEADER_LOGO else None
FAVICON = config.get('c3nav', 'favicon', fallback=None)
PRIMARY_COLOR = config.get('c3nav', 'primary_color', fallback='')
HEADER_BACKGROUND_COLOR = config.get('c3nav', 'header_background_color', fallback='')
HEADER_TEXT_COLOR = config.get('c3nav', 'header_text_color', fallback='')

View file

@ -1,7 +1,12 @@
from django.conf import settings
import os
from c3nav.site.finders import logo_paths
def header_logo(request):
return {
'header_logo': settings.HEADER_LOGO_NAME
logos_result = {
prefix: os.path.join(prefix, os.path.basename(path)) if path else None
for prefix, path in logo_paths.items()
}
def logos(request):
return logos_result

View file

@ -4,17 +4,33 @@ from django.conf import settings
from django.contrib.staticfiles.finders import BaseFinder
from django.core.files.storage import FileSystemStorage
logo_paths = {
'header_logo': settings.HEADER_LOGO,
'favicon': settings.FAVICON,
}
class HeaderLogoFinder(BaseFinder):
logofinder_results = {
os.path.join(prefix, os.path.basename(path)): path
for prefix, path in logo_paths.items()
}
class LogoFinder(BaseFinder):
def find(self, path, all=False):
if path == settings.HEADER_LOGO_NAME:
return [settings.HEADER_LOGO] if all else settings.HEADER_LOGO
result = logofinder_results.get(path)
if not result:
return []
if all:
return [result]
return result
def list(self, ignore_patterns):
if not settings.HEADER_LOGO:
return []
basedir, filename = os.path.split(settings.HEADER_LOGO)
result = []
for prefix, path in logo_paths.items():
if not path:
continue
basedir, filename = os.path.split(path)
storage = FileSystemStorage(location=basedir)
storage.prefix = 'logo'
return [(filename, storage)]
storage.prefix = prefix
result.append((filename, storage))
return result

View file

@ -7,6 +7,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>{% block title %}c3nav{% endblock %}</title>
{% if favicon %}
<link href="{% static favicon %}" rel="icon">
{% endif %}
{% compress css %}
<link href="{% static 'fonts/fonts.css' %}" rel="stylesheet">
<link href="{% static 'normalize/normalize.css' %}" rel="stylesheet">