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

Commit 8a84b1f05bfc4fe3cb4cdfdb93a7781ee7b8d101
Parent: a5e9660092709115462c9ac5224881486def9dcf
Author: mcol <mcol@posteo.net>
Date: 2019-10-14 23:52:44 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2019-10-14 23:52:44 +0100

generate subfont into pelican output from used glyphs

minify_fontawesome.py Modified

@@ -18,7 +18,7 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 
-import fontforge as ff
+import fontforge
 import os
 from pelican import signals
 import re
@@ -28,26 +28,28 @@
     """
     Copy only used icons from the font files into the output folder.
     """
-    used_icons = []
+    icons = []
     for block in css_blocks:
-        used_icons.append(re.search('content:"(.*?)"', block).group(0))
+        match = re.findall('\.fa-(.*?):', block)
+        icons.append(match[0])
 
-    return  #TODO
+    os.mkdir(dest)
+    icons = ['rss']
     for root, dirs, files in os.walk(source):
         for f in files:
             if f.endswith('woff'):
-                font = ff.open(os.path.join(root, f))
-                for icon in used_icons:
-                    if font.findEncodingSlot(icon):
-                        font.selection.select(
-                            ("more", None),
-                            icon,
-                        )
-                font.copy()
-                new_font = ff.font()
-                new_font.paste()
-                new_font.fontname = font.fontname
-                new_font.generate(os.path.join(dest, f))
+                font = fontforge.open(os.path.join(root, f))
+
+                try:
+                    font.selection.select(("more",), *icons)
+                except ValueError:
+                    font.close()
+                    continue
+
+                font.selection.invert()
+                font.clear()
+                font.generate(os.path.join(dest, f))
+                font.close()
 
 
 def get_classes(folder):
@@ -113,7 +115,7 @@
 
     copy_glyphs(
         os.path.join(FONT_PATH, 'webfonts'),
-        os.path.join(output_path, 'static', 'webfonts'),
+        os.path.join(output_path, 'theme', 'webfonts'),
         css_blocks,
     )