Commit 4e0dad8c authored by gijs's avatar gijs

Unifing strokewidths in generation rather than with javascript

parent 12e33b9d
......@@ -25,9 +25,9 @@ Visit the project steps
<aside markdown="true" id="office-bio">
<div class="portraits">
<object data="/images/portrait-koen.svg" type="image/svg+xml"></object>
<object data="/images/portrait-bernardo.svg" type="image/svg+xml"></object>
<div class="portraits" markdown="true">
![](/images/portrait-koen.svg)
![](/images/portrait-bernardo.svg)
</div>
Koen Berghmans (1983, Sint-Lucas) and Bernardo Robles Hidalgo (1984, ENSAPB)
......
......@@ -46,4 +46,7 @@ MENUITEMS = [
# Uncomment following line if you want document-relative URLs when developing
#RELATIVE_URLS = True
SUMMARY_MAX_LENGTH = 12
SUMMARY_MAX_LENGTH = 25
PLUGIN_PATHS = ["plugins"]
PLUGINS = ["unify_svg_strokes"]
\ No newline at end of file
This diff is collapsed.
Heavily modified version of the imageprocess plugin: https://github.com/whiskyechobravo/image_process
\ No newline at end of file
from .unify_svg_strokes import *
# -*- coding: utf-8 -*- #
"""
UNIFY SVG STROKES
=============
This plugin processes svg pictures to unify their stroke widths
"""
from __future__ import unicode_literals
import copy
import collections
import functools
import os.path
import re
import six
from xml.dom import minidom
from bs4 import BeautifulSoup
from pelican import signals
def harvest_images(path, context):
# Set default value for 'IMAGE_PROCESS_DIR'.
if 'UNIFIED_OUTPUT_DIR' not in context:
context['UNIFIED_OUTPUT_DIR'] = 'unified'
if 'UNIFIED_STROKE_WIDTH' not in context:
context['UNIFIED_STROKE_WIDTH'] = '2px'
with open(path, 'r+') as f:
res = harvest_images_in_fragment(f, context)
f.seek(0)
f.truncate()
f.write(res)
def harvest_images_in_fragment(fragment, settings):
parser = settings.get("UNIFIED_PARSER", "html.parser")
soup = BeautifulSoup(fragment, parser)
for img in soup.find_all('img'):
if os.path.splitext(img['src'])[1] == '.svg':
process_img_tag(img, settings)
return str(soup)
def process_img_tag(img, settings):
process_dir = settings['UNIFIED_OUTPUT_DIR']
url_path, filename = os.path.split(img['src'])
base_url = os.path.join(url_path, process_dir)
source = os.path.join(settings['PATH'], img['src'][1:])
base_path = os.path.join(settings['OUTPUT_PATH'], base_url[1:])
img['src'] = os.path.join(base_url, filename)
destination = os.path.join(base_path, filename)
unify_strokes(source, destination, settings['UNIFIED_STROKE_WIDTH'])
def set_vector_scale (node, width):
if node.hasAttribute('style'):
node.setAttribute('style', node.getAttribute('style') + ';vector-effect:non-scaling-stroke;stroke-width: {};'.format(width))
else:
node.setAttribute('style', 'vector-effect:non-scaling-stroke;stroke-width: {};'.format(width))
def unify_strokes (source, destination, width):
path, _ = os.path.split(destination)
try:
os.makedirs(path)
except OSError as e:
if e.errno == 17:
# Already exists
pass
# If original image is older than existing derivative, skip
# processing to save time, unless user explicitely forced
# image generation.
if (not os.path.exists(destination) or
os.path.getmtime(source) > os.path.getmtime(destination)):
doc = minidom.parse(source) # parseString also exists
paths = doc.getElementsByTagName('path')
for path in paths:
set_vector_scale(path, width)
lines = doc.getElementsByTagName('line')
for line in lines:
set_vector_scale(line, width)
with open(destination, 'w') as o:
doc.writexml(o)
def register():
signals.content_written.connect(harvest_images)
......@@ -78,17 +78,22 @@ h1 a {
#sticky-title {
padding: 1em 0;
position: -webkit-sticky;
position: sticky;
top: 0em;
background: white;
z-index: 1;
margin-bottom: 0;
margin-top: -2.5em;
}
.filter-active #sticky-title {
background: white;
}
#sticky-title h1 {
margin-top: 0;
margin-bottom: 0;
margin-bottom: 0.5em;
font-size: 150%;
line-height: initial;
}
......@@ -107,6 +112,7 @@ h1 a {
}
#title {
position: -webkit-sticky;
position: sticky;
z-index: 2;
top: 0em;
......@@ -321,6 +327,7 @@ li.active {
#back-to-top {
font-family: 'Poppins';
float: right;
position: -webkit-sticky;
position: sticky;
bottom: 2em;
font-size: 80%;
......@@ -426,6 +433,7 @@ section.page-content.office .portraits object, section.page-content.office .port
.entry .entry-content {
margin: 0 1.5em 0 0;
flex: 2 0;
position: -webkit-sticky;
position: sticky;
max-height: calc(100vh - 2em);
top: 1em;
......@@ -487,12 +495,6 @@ section.page-content.office .portraits object, section.page-content.office .port
font-size: initial;
}
.page-content.office .portraits * {
display: inline-block;
vertical-align: bottom;
width: 49%;
}
}
......
......@@ -59,6 +59,5 @@
<footer id="contentinfo" class="body">
<!-- /#about -->
</footer><!-- /#contentinfo -->
<script src="{{ SITEURL }}/theme/js/unifyStrokes.js"></script>
</body>
</html>
......@@ -26,7 +26,8 @@
<article class="entry" data-slug="{{ article.slug }}" data-expanded="true">
<div class="entry-content">
{% if article.image %}
<object data="{{ SITEURL }}/images/{{ article.image }}" class="entry-img" type="image/svg+xml"></object>
<!-- <object data="{{ SITEURL }}/images/{{ article.image }}" class="entry-img" type="image/svg+xml"></object> -->
<img src="/images/{{ article.image }}" class="entry-img" />
{% endif %}
</div><!-- /.entry-content -->
<section class="metadata">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment