File: meta-tag.rb

package info (click to toggle)
ruby-jekyll-feed 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 308 kB
  • sloc: ruby: 811; xml: 100; sh: 18; makefile: 9
file content (27 lines) | stat: -rw-r--r-- 768 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module JekyllFeed
  class MetaTag < Liquid::Tag
    # Use Jekyll's native relative_url filter
    include Jekyll::Filters::URLFilters

    def render(context)
      # Jekyll::Filters::URLFilters requires `@context` to be set in the environment.
      @context = context

      config = context.registers[:site].config
      path   = config.dig("feed", "path") || "feed.xml"
      title  = config["title"] || config["name"]

      attributes = {
        :type => "application/atom+xml",
        :rel  => "alternate",
        :href => absolute_url(path),
      }
      attributes[:title] = title if title

      attrs = attributes.map { |k, v| "#{k}=#{v.to_s.encode(:xml => :attr)}" }.join(" ")
      "<link #{attrs} />"
    end
  end
end