Module: Coradoc::Html::FrontmatterMeta
- Defined in:
- lib/coradoc/html/frontmatter_meta.rb
Overview
Single source of truth for FrontmatterBlock -> HTML ‘<meta>` and `<link>` tag mapping. (MECE: HTML-specific concerns live in the HTML gem; CoreModel has no knowledge of HTML.)
The module produces a small data structure that layout templates and Nokogiri::HTML::Builder fallbacks both consume, so we never duplicate the mapping rule across output paths (DRY).
Mapping table (single source of truth — extend here only):
| Frontmatter key | Output |
|-----------------------|-----------------------------------------|
| title | <title> (caller decides title priority) |
| author | <meta name="author"> |
| description, excerpt | <meta name="description"> |
| date | <meta name="date"> (ISO 8601) |
| subject | <meta name="subject"> |
| tags, categories | <meta name="keywords"> (comma-joined) |
| $schema | <link rel="schema.X" href="..."> |
| (any other scalar) | <meta name="<key>" content="<value>"> |
Defined Under Namespace
Constant Summary collapse
- DESCRIPTION_KEYS =
%w[description excerpt].freeze
- KEYWORDS_KEYS =
%w[tags categories].freeze
Class Method Summary collapse
-
.emit_into_builder(builder_doc, block) ⇒ Object
Emit meta + link tags into a Nokogiri head builder context.
-
.extract(block) ⇒ Hash{Symbol=>Array<Meta>,Array<LinkTag>,String,nil}
Extract a meta-tag list and link-tag list from a FrontmatterBlock.
Class Method Details
.emit_into_builder(builder_doc, block) ⇒ Object
Emit meta + link tags into a Nokogiri head builder context.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/coradoc/html/frontmatter_meta.rb', line 54 def emit_into_builder(builder_doc, block) data = extract(block) Array(data[:metas]).each do || builder_doc.(name: .name, content: .content) end Array(data[:links]).each do |link| builder_doc.link(rel: link.rel, href: link.href) end data end |
.extract(block) ⇒ Hash{Symbol=>Array<Meta>,Array<LinkTag>,String,nil}
Extract a meta-tag list and link-tag list from a FrontmatterBlock. ‘title` is returned separately so the caller can decide precedence (e.g., document title vs. frontmatter).
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/coradoc/html/frontmatter_meta.rb', line 42 def extract(block) return empty_result unless block.is_a?(Coradoc::CoreModel::FrontmatterBlock) data = block.data || {} { metas: (data), links: build_links(block.schema), title: scalar_value(data['title']) } end |