lib/jekyll/zettel/zettelkasten.rb in jekyll-zettel-0.4.0 vs lib/jekyll/zettel/zettelkasten.rb in jekyll-zettel-0.4.1

- old
+ new

@@ -11,18 +11,21 @@ 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['zettel']] = { 'zettel' => doc.data['zettel'], @@ -34,8 +37,17 @@ '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