Commit 1ed9acda authored by Emma's avatar Emma 🦉

move icon sprites to external, cacheable resource

parent 7f787a11
Pipeline #54147780 passed with stages
in 8 minutes and 18 seconds
#!/bin/sh
# Download icons, create sprite sheet, save to templates/_includes/icons.svg.
# Download icons, create sprite sheet, save to assets/icons/icons.svg.
# The generated sprite sheet should be committed to the git repository.
# Note: this must be kept compatible with regular /bin/sh so it runs under the
......@@ -11,7 +11,7 @@ set -e
PROJECT_ROOT=$(dirname $(dirname $(realpath $0)))
PATH="$PROJECT_ROOT/node_modules/.bin:$PATH"
TEMP=$(mktemp -d)
OUT="$PROJECT_ROOT/templates/_includes/icons.svg"
OUT="$PROJECT_ROOT/assets/icons/icons.svg"
trap 'rm -rf "$TEMP"' EXIT
......
{% macro icon(name, alt_text = '') -%}
{% macro icon(name, alt_text = '') %}
{#- prevent preloading sprite sheet more than once -#}
{%- set icon_asset = asset('build/images/icons.svg') -%}
{%- if not app.request.attributes.get('icons_are_linked') -%}
{%- set icon_asset = preload(icon_asset) -%}
{%- endif -%}
{%- do app.request.attributes.set('icons_are_linked', true) -%}
{%- filter spaceless -%}
<span class="icon {{ alt_text ? 'icon--with-alt-text' }}">
{%- if alt_text is not empty -%}
......@@ -15,7 +22,7 @@
width="0"
height="0">
{%- endif -%}
<svg width="16" height="16"><use xlink:href="#{{ name }}"/></svg>
<svg width="16" height="16"><use xlink:href="{{ icon_asset }}#{{ name }}"/></svg>
</span>
{%- endfilter -%}
{%- endmacro %}
{% endmacro icon %}
......@@ -81,9 +81,5 @@
<script src="{{ preload(asset('js/translations/en.js', 'static_asset')) }}"></script>
{% endif %}
{% endblock %}
{% block svg_sprites %}
{{ source('_includes/icons.svg') }}
{% endblock %}
</body>
</html>
......@@ -9,6 +9,11 @@ Encore
.addStyleEntry('postmill', './assets/css/postmill.css')
.addStyleEntry('postmill-night', './assets/css/postmill-night.css')
.cleanupOutputBeforeBuild()
.copyFiles({
from: './assets/icons',
to: 'images/[path][name].[hash:8].[ext]',
pattern: /\.svg$/i,
})
.enableLessLoader()
.enableSingleRuntimeChunk()
.enableSourceMaps(!Encore.isProduction())
......
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