class

Hwaro::Content::Seo::Amp

Inherits Reference / Object

Constants

AMP_FONT_PROVIDERS = ["cloud.typography.com", "fast.fonts.net", "fonts.googleapis.com", "use.typekit.net", "maxcdn.bootstrapcdn.com", "use.fontawesome.com", "fonts.bunny.net"] of ::String

Font providers AMP allows via <link rel="stylesheet">. Every other external stylesheet is disallowed and is stripped during conversion.

Class methods

convert_to_amp(html : String, page : Models::Page, config : Models::Config) : String

Convert standard HTML to AMP-compliant HTML

Source
generate(pages : Array(Models::Page), config : Models::Config, output_dir : String, verbose : Bool = false)

Generate AMP versions of rendered pages. Reads the already-rendered HTML files, converts to AMP-compliant HTML, and writes them under the configured path prefix.

Source
same_origin_src?(src : String, base_url : String) : Bool

True when src resolves to the same origin as the AMP document.

Unknown means same-origin. An empty or unreadable src is the one case we must not guess cross-origin on: guessing wrong there hands allow-same-origin to a same-origin frame, which is precisely the AMP violation this function exists to prevent. Guessing the other way only drops a privilege.

Source
sandbox_for(src : String, base_url : String) : String

Default sandbox for a converted iframe.

AMP: "An amp-iframe must not be in the same origin as the container unless they do not allow allow-same-origin in the sandbox attribute." Third-party embeds (YouTube, CodePen, Gist) are cross-origin and need allow-same-origin to function, but adding it unconditionally makes any iframe pointing back at the site itself fail AMP validation outright.

Source