Class: Jekyll::Generators::AsciiDocPreprocessor
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Generators::AsciiDocPreprocessor
- Defined in:
- lib/jekyll-asciidoc.rb
Overview
Promotes select AsciiDoc attributes to Jekyll front matter
Instance Method Summary collapse
Instance Method Details
#generate(site) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/jekyll-asciidoc.rb', line 85 def generate(site) asciidoc_converter = JEKYLL_MIN_VERSION_3 ? site.find_converter_instance(Jekyll::Converters::AsciiDocConverter) : site.getConverterImpl(Jekyll::Converters::AsciiDocConverter) asciidoc_converter.setup key_prefix = (site.config['asciidoc_key_prefix'] || 'jekyll-') key_prefix_len = key_prefix.length site.pages.each do |page| if asciidoc_converter.matches(page.ext) doc = asciidoc_converter.load(page.content) next if doc.nil? page.data['title'] ||= doc.doctitle page.data['author'] = doc. unless doc..nil? doc.attributes.each do |key, val| if key.start_with?(key_prefix) page.data[key[key_prefix_len..-1]] ||= val end end unless page.data.has_key? 'layout' if doc.attr? 'page-layout' page.data['layout'] ||= doc.attr 'page-layout' else page.data['layout'] ||= 'default' end end end end (JEKYLL_MIN_VERSION_3 ? site.posts.docs : site.posts).each do |post| if asciidoc_converter.matches(JEKYLL_MIN_VERSION_3 ? post.data['ext'] : post.ext) doc = asciidoc_converter.load(post.content) next if doc.nil? post.data['title'] ||= doc.doctitle post.data['author'] = doc. unless doc..nil? # TODO carry over date # setting categories doesn't work here, we lose the post #post.data['categories'] ||= (doc.attr 'categories') if (doc.attr? 'categories') doc.attributes.each do |key, val| if key.start_with?(key_prefix) post.data[key[key_prefix_len..-1]] ||= val end end unless post.data.has_key? 'layout' if doc.attr? 'page-layout' post.data['layout'] ||= doc.attr 'page-layout' else post.data['layout'] ||= 'post' end end end end end |