File: file_info.rb

package info (click to toggle)
ruby-jekyll-compose 0.12.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 108 kB
  • sloc: ruby: 712; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 676 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
28
29
30
31
32
# frozen_string_literal: true

module Jekyll
  module Compose
    class FileInfo
      attr_reader :params
      def initialize(params)
        @params = params
      end

      def file_name
        name = Jekyll::Utils.slugify params.title
        "#{name}.#{params.type}"
      end

      def content(custom_front_matter = {})
        front_matter = YAML.dump({
          "layout" => params.layout,
          "title"  => params.title,
        }.merge(custom_front_matter))

        front_matter + "---\n"
      end

      private

      def front_matter_defaults_for(key)
        params.config.dig("jekyll_compose", "default_front_matter", key)
      end
    end
  end
end