Class: Hyde::FontProviderGoogle

Inherits:
Object
  • Object
show all
Defined in:
lib/hyde_fonts/provider_google.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, config) ⇒ FontProviderGoogle

Returns a new instance of FontProviderGoogle.



6
7
8
9
# File 'lib/hyde_fonts/provider_google.rb', line 6

def initialize(site, config)
  @site = site
  @config = config
end

Instance Method Details

#fetch(face) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hyde_fonts/provider_google.rb', line 11

def fetch(face)
  @face = face

  begin
    uri_payload = Net::HTTP.get(face_uri, {
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0"
    })
  rescue
    Jekyll.logger.warn("Fonts Warning:", "Unable to reach Google Fonts service.")
    return
  end

  rulesets = parse_css_payload(uri_payload)

  # TODO if @config['fetch_fonts'] is false, don't download the files

  for ruleset in rulesets
    fetch_font_from_ruleset(ruleset)
    face.css.push(rewrite_ruleset_to_local(ruleset))
  end
end