Sha256: 9a858c2064bb525d2b15f54d67d1226150b38027f6f421bdbaa3e33d73d635a0

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module Jekyll
  module Zettel
    # Generate tags.json from page front matter
    class Zettelkasten < Jekyll::Generator
      include Jekyll::Zettel

      priority :low

      SLUG_FORMAT = %r{zettel/(?<uuid>.*)/index.(?<ext>html|md)}i.freeze

      attr_reader :site

      def generate(site)
        @site = site
        @site.data['zettelkasten'] = {}
        @site.data['tag2zettel'] = {}

        site.pages.each do |page|
          next unless SLUG_FORMAT.match?(page.path.to_s)

          register_zettel(page)
          register_tags(page)
        end

        write_catalog 'zettelkasten'
        write_catalog 'tag2zettel'
      end

      def register_zettel(doc)
        @site.data['zettelkasten'][doc.data['id']] = {
          'zettel' => doc.data['id'],
          'title' => doc.data['title'],
          'description' => doc.data['description'],
          'author' => doc.data['author'],
          'tags' => doc.data['tags'],
          'folgezettel' => doc.data['folgezettel'],
          'via' => doc.data['via'],
          'citekey' => doc.data['citekey']
        }
      end

      def register_tags(doc)
        return unless doc.data.key?('tags')

        doc.data['tags'].each { |tag|
          @site.data['tag2zettel'][tag] = [] unless @site.data['tag2zettel'].key?(tag)

          @site.data['tag2zettel'][tag] << doc.data['zettel']
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-zettel-0.6.8 lib/jekyll/zettel/zettelkasten.rb
jekyll-zettel-0.6.7 lib/jekyll/zettel/zettelkasten.rb
jekyll-zettel-0.6.5 lib/jekyll/zettel/zettelkasten.rb
jekyll-zettel-0.6.4 lib/jekyll/zettel/zettelkasten.rb