Browse Source

Merge pull request #418 from saimn/user_css

Add user_css option
pull/377/merge
Simon Conseil 5 years ago committed by GitHub
parent
commit
a1c0c72103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      docs/changelog.rst
  2. 1
      sigal/settings.py
  3. 3
      sigal/templates/sigal.conf.py
  4. 3
      sigal/themes/colorbox/templates/base.html
  5. 3
      sigal/themes/galleria/templates/base.html
  6. 3
      sigal/themes/photoswipe/templates/base.html
  7. 12
      sigal/writer.py
  8. 8
      tests/test_gallery.py

1
docs/changelog.rst

@ -14,6 +14,7 @@ Released on 2020-xx-xx.
- Fix video thumbnail creation when delay > video length [:issue:`411`].
- Update photoswipe to 4.4.0 [:issue:`415`].
- Update galleria to v1.6.1 and add new themes [:issue:`417`].
- Add ``user_css`` option to allow easier css customization [:issue:`418`].
Version 2.1.1
~~~~~~~~~~~~~

1
sigal/settings.py

@ -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',

3
sigal/templates/sigal.conf.py

@ -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)
# ----------------

3
sigal/themes/colorbox/templates/base.html

@ -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>

3
sigal/themes/galleria/templates/base.html

@ -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>

3
sigal/themes/photoswipe/templates/base.html

@ -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>

12
sigal/writer.py

@ -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."""

8
tests/test_gallery.py

@ -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)

Loading…
Cancel
Save