Add user_css option

This commit is contained in:
Simon Conseil
2020-12-19 23:38:37 -03:00
parent 40a4a680ac
commit b0dcc65f5b
7 changed files with 32 additions and 1 deletions

View File

@@ -74,6 +74,7 @@ _DEFAULT_CONFIG = {
'thumb_video_delay': '0',
'title': '',
'use_orig': False,
'user_css': None,
'video_converter': 'ffmpeg',
'video_extensions': ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp'],
'video_format': 'webm',

View File

@@ -36,6 +36,9 @@ theme = 'galleria'
# Originals will be symlinked if orig_link = True, else they will be copied.
# use_orig = False
# Path to a CSS file that can be used to customize themes
# user_css =
# ----------------
# Image processing (ignored if use_orig = True)
# ----------------

View File

@@ -11,6 +11,9 @@
<link rel="stylesheet" href="{{ theme.url }}/css/skeleton.css">
<link rel="stylesheet" href="{{ theme.url }}/css/colorbox.css">
<link rel="stylesheet" href="{{ theme.url }}/css/style.css">
{% if settings.user_css %}
<link rel="stylesheet" href="{{ theme.url }}/{{ user_css }}">
{% endif %}
{% block extra_head %}{% endblock extra_head %}
{% include 'analytics.html' %}
</head>

View File

@@ -12,6 +12,9 @@
<link rel="stylesheet" href="{{ theme.url }}/css/normalize.css">
<link rel="stylesheet" href="{{ theme.url }}/themes/{{ settings.galleria_theme }}/galleria.{{ settings.galleria_theme }}.css">
<link rel="stylesheet" href="{{ theme.url }}/css/style.css">
{% if settings.user_css %}
<link rel="stylesheet" href="{{ theme.url }}/{{ settings.user_css }}">
{% endif %}
{% block extra_head %}{% endblock extra_head %}
{% include 'analytics.html' %}
</head>

View File

@@ -10,6 +10,9 @@
<meta name="viewport" content="width=device-width">
{% block extra_head %}{% endblock extra_head %}
<link rel="stylesheet" href="{{ theme.url }}/styles.css">
{% if settings.user_css %}
<link rel="stylesheet" href="{{ theme.url }}/{{ user_css }}">
{% endif %}
{% include 'analytics.html' %}
</head>
<body>

View File

@@ -100,12 +100,19 @@ class AbstractWriter:
# FIXME: use dirs_exist_ok when minimum Python is 3.8
shutil.copytree(os.path.join(self.theme, 'static'), self.theme_path)
if self.settings['user_css']:
if not os.path.exists(self.settings['user_css']):
self.logger.error('CSS file %s could not be found',
self.settings['user_css'])
else:
shutil.copy(self.settings['user_css'], self.theme_path)
def generate_context(self, album):
"""Generate the context dict for the given path."""
from . import __url__ as sigal_link
self.logger.info("Output album : %r", album)
return {
ctx = {
'album': album,
'index_title': self.index_title,
'settings': self.settings,
@@ -114,6 +121,9 @@ class AbstractWriter:
'url': url_from_path(os.path.relpath(self.theme_path,
album.dst_path))},
}
if self.settings['user_css']:
ctx['user_css'] = os.path.basename(self.settings['user_css'])
return ctx
def write(self, album):
"""Generate the HTML page and save it."""

View File

@@ -236,12 +236,19 @@ def test_medias_sort(settings):
def test_gallery(settings, tmpdir):
"Test the Gallery class."
with open(str(tmpdir.join('my.css')), mode='w') as f:
f.write('color: red')
settings['destination'] = str(tmpdir)
settings['user_css'] = str(tmpdir.join('my.css'))
settings['webm_options'] = ['-missing-option', 'foobar']
gal = Gallery(settings, ncpu=1)
gal.build()
mycss = os.path.join(settings['destination'], 'static', 'my.css')
assert os.path.isfile(mycss)
out_html = os.path.join(settings['destination'], 'index.html')
assert os.path.isfile(out_html)
@@ -249,6 +256,7 @@ def test_gallery(settings, tmpdir):
html = f.read()
assert '<title>Sigal test gallery</title>' in html
assert '<link rel="stylesheet" href="static/my.css">' in html
logger = logging.getLogger('sigal')
logger.setLevel(logging.DEBUG)