Pelican plugin to minify fontawesome assets to include used icons.
git clone https://github.com/m-col/pelican-minify-fontawesome
Files | Refs | Readme

Commit 5ebecd52679ebf6557f57e5f64ad595aba7d4ad8
Parent: 323c4b1bc6ff6f266cd9330c8d97fcb4e796fc52
Author: mcol <mcol@posteo.net>
Date: 2020-08-05 21:43:52 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2020-08-05 21:43:52 +0100

Allow inclusion of extra icons with FONTAWESOME_EXTRA

readme.rst Modified

@@ -32,6 +32,16 @@
 
     <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
 ---------
 

minify_fontawesome.py Modified

@@ -59,12 +59,12 @@
 
     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 @@
     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 @@
         )
 
     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 @@
     css_blocks = copy_css(
         output_path,
         css_file,
+        instance.settings.get('FONTAWESOME_EXTRA', None)
     )
 
     copy_glyphs(