Class: Abqari::FontPipeline
- Inherits:
-
Object
- Object
- Abqari::FontPipeline
- Defined in:
- lib/abqari/font_pipeline.rb
Constant Summary collapse
- GOOGLE_CSS_API =
'https://fonts.googleapis.com/css2'- USER_AGENT =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' \ '(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
- OPEN_TIMEOUT =
Timeouts and per-response cap. CSS responses are <10 KB and woff2 files <500 KB typically; 8 MB is far above worst-case and exists so a misbehaving upstream can't hang the build or fill memory.
5- READ_TIMEOUT =
10- MAX_RESPONSE_BYTES =
8 * 1024 * 1024
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(site) ⇒ FontPipeline
constructor
A new instance of FontPipeline.
Constructor Details
#initialize(site) ⇒ FontPipeline
Returns a new instance of FontPipeline.
19 20 21 22 23 24 |
# File 'lib/abqari/font_pipeline.rb', line 19 def initialize(site) @site = site # Font cache is site-specific — populated from the site's own # `fonts:` config. @cache_dir = File.join(@site.site_root, 'vendor', 'fonts') end |
Instance Method Details
#fetch ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/abqari/font_pipeline.rb', line 26 def fetch fonts = Array(@site.config['fonts']) if fonts.empty? Log.info 'No fonts configured. Add a `fonts:` array to config/site.yml.' return end FileUtils.mkdir_p(@cache_dir) generated = fonts.map { |font| download_font(font) } File.write(File.join(@cache_dir, 'fonts.css'), generated.join("\n\n")) Log.info "Fetched #{fonts.size} font family/families → vendor/fonts/" end |