Compare commits
3 Commits
07408d01a9
...
0b33d03b73
Author | SHA1 | Date | |
---|---|---|---|
0b33d03b73 | |||
804147caef | |||
d847d20666 |
@ -5,7 +5,8 @@ require 'nokogiri'
|
||||
require 'set'
|
||||
|
||||
# 1) Process all files passed in from the command line
|
||||
files = ARGV
|
||||
svgpath = ARGV[0]
|
||||
files = ARGV[1..]
|
||||
|
||||
# 2) Extract used Feather icons
|
||||
used_icons = Set.new
|
||||
@ -27,7 +28,7 @@ end
|
||||
puts "Found #{used_icons.size} unique icons: #{used_icons.to_a.join(', ')}"
|
||||
|
||||
# 3) Load the full feather-sprite.svg as XML
|
||||
sprite_doc = File.open("feather-sprite.svg", "r:UTF-8") { |f| Nokogiri::XML(f) }
|
||||
sprite_doc = File.open(svgpath, "r:UTF-8") { |f| Nokogiri::XML(f) }
|
||||
|
||||
# 4) Create a new SVG with only the required symbols
|
||||
new_svg = Nokogiri::XML::Document.new
|
||||
@ -43,7 +44,7 @@ sprite_doc.css("symbol").each do |symbol_node|
|
||||
end
|
||||
|
||||
# 5) Save the subset sprite
|
||||
File.open("custom-sprite.svg", "w:UTF-8") do |f|
|
||||
File.open(svgpath, "w:UTF-8") do |f|
|
||||
f.write(new_svg.to_xml)
|
||||
end
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
from bs4 import BeautifulSoup
|
||||
from fontTools.subset import Subsetter, Options
|
||||
from fontTools.ttLib import TTFont
|
||||
|
||||
# Directories
|
||||
HTML_DIR = "." # Directory with .html files
|
||||
FONT_DIR = "." # Directory containing fonts to be modified
|
||||
|
||||
FONT_EXTENSIONS = (".ttf", ".woff", ".woff2", ".otf") # Font file types
|
||||
|
||||
def extract_text_from_html(file_path):
|
||||
@ -15,15 +12,13 @@ def extract_text_from_html(file_path):
|
||||
soup = BeautifulSoup(f.read(), "html.parser")
|
||||
return soup.get_text()
|
||||
|
||||
def get_used_characters(directory):
|
||||
def get_used_characters(files):
|
||||
"""Collect unique characters from all .html files in the given directory."""
|
||||
char_set = set()
|
||||
for root, _, files in os.walk(directory):
|
||||
for file in files:
|
||||
if file.endswith(".html"):
|
||||
full_path = os.path.join(root, file)
|
||||
text = extract_text_from_html(full_path)
|
||||
char_set.update(text)
|
||||
for file in files:
|
||||
full_path = os.path.join(root, file)
|
||||
text = extract_text_from_html(full_path)
|
||||
char_set.update(text)
|
||||
return "".join(sorted(char_set))
|
||||
|
||||
def find_font_files(directory):
|
||||
@ -65,10 +60,10 @@ def subset_font_in_place(font_path, characters):
|
||||
print(f"Subsetted font in place: {font_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
used_chars = get_used_characters(HTML_DIR)
|
||||
used_chars = get_used_characters(sys.argv[2:])
|
||||
print(f"Extracted {len(used_chars)} unique characters from HTML files.")
|
||||
|
||||
font_files = find_font_files(FONT_DIR)
|
||||
font_files = find_font_files(sys.argv[1])
|
||||
print(f"Found {len(font_files)} font files to subset.")
|
||||
|
||||
for font_file in font_files:
|
||||
|
Loading…
Reference in New Issue
Block a user