A Pelican plugin that minifies fontawesome css and fonts to include only used icons.
git clone https://mcol.xyz/code/pelican-minify-fontawesome
Log | Files | Refs | README

commit 5ebecd52679ebf6557f57e5f64ad595aba7d4ad8
parent 323c4b1bc6ff6f266cd9330c8d97fcb4e796fc52
Author: mcol <mcol@posteo.net>
Date:   Wed,  5 Aug 2020 21:43:52 +0100

Allow inclusion of extra icons with FONTAWESOME_EXTRA

Diffstat:
Mminify_fontawesome.py | 9+++++----
Mreadme.rst | 10++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/minify_fontawesome.py b/minify_fontawesome.py @@ -59,12 +59,12 @@ def copy_glyphs(source, dest, css_blocks): print(f'Font Awesome icons incorporated: {icons}') -def get_classes(folder): +def get_classes(folder, extra_icons): """ Gets a list of font awesome CSS classes defined in all html files within a folder i.e. those beginning with 'fa'. """ - fa_classes = [] + fa_classes = extra_icons if extra_icons else [] all_classes = [] for root, dirs, files in os.walk(folder): @@ -83,7 +83,7 @@ def get_classes(folder): return fa_classes -def copy_css(output_path, css_file): +def copy_css(output_path, css_file, extra_icons): """ Copy css for only used icons over to output folder. Returns the css blocks corresponding to these icons so we know which icons to copy from the font @@ -101,7 +101,7 @@ def copy_css(output_path, css_file): ) css_blocks = [] - for cls in get_classes(output_path): + for cls in get_classes(output_path, extra_icons): match = re.search(f'\.{cls}:before.*?}}', contents) if match: css_blocks.append(match.group(0)) @@ -129,6 +129,7 @@ def output_font(instance): css_blocks = copy_css( output_path, css_file, + instance.settings.get('FONTAWESOME_EXTRA', None) ) copy_glyphs( diff --git a/readme.rst b/readme.rst @@ -32,6 +32,16 @@ headers, i.e. put this into page templates: <link rel="stylesheet" href="{{ SITEURL }}/theme/css/fa.css"/> +Additional icons +---------------- + +Additional icons that aren't found in your articles can be added using a list +of their corresponding CSS references and this variable name: + +.. code-block:: python + + FONTAWESOME_EXTRA = ['fa-rss', 'fa-poo-storm'] + RST roles ---------