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

Commit b7e657f9c58ed925aa4b58329fed2ff1daa15c39
Parent: 836186342e24230b79697af55efd8e2cb50692a6
Author: mcol <mcol@posteo.net>
Date: 2019-10-19 18:15:20 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2019-10-19 18:15:20 +0100

add :fa: context for rst to generate html spans where we want glyphs

minify_fontawesome.py Modified

@@ -1,28 +1,31 @@
 # -*- coding: utf-8 -*-
 #
 # pelican-minify-fontawesome
-# 
+#
 # Copyright (C) 2019 mcol@posteo.net
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 
 import fontforge
 import os
-from pelican import signals
 import re
 
+from docutils import nodes
+from docutils.parsers.rst import roles
+from pelican import signals
+
 
 def copy_glyphs(source, dest, css_blocks):
     """
@@ -69,7 +72,7 @@
                     if matches:
                         for match in matches:
                             all_classes.extend(match.split())
-    
+
     for cls in set(all_classes):
         if cls.startswith('fa'):
             fa_classes.append(cls)
@@ -108,7 +111,7 @@
     return css_blocks
 
 
-def main(instance):
+def output_font(instance):
     FONT_PATH = instance.settings.get('MINIFY_FONTAWESOME', None)
     if not FONT_PATH or not os.path.isdir(FONT_PATH):
         return
@@ -128,5 +131,9 @@
     )
 
 
+def rst_span(name, rawtext, text, lineno, inliner, options={}, content=[]):
+    return [nodes.raw('', f'<span class="{text}"></span>', format='html')], []
+
 def register():
-    signals.finalized.connect(main)
+    roles.register_local_role('fa', rst_span)
+    signals.finalized.connect(output_font)