Class: Jekyll::Documents::Generator
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Documents::Generator
- Defined in:
- lib/jekyll/documents/generator.rb
Overview
Main generator that scans document files and creates Jekyll collection items
Instance Method Summary collapse
-
#generate(site) ⇒ void
Generates document collection from files in configured root directory.
Instance Method Details
#generate(site) ⇒ void
This method returns an undefined value.
Generates document collection from files in configured root directory
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jekyll/documents/generator.rb', line 28 def generate(site) @site = site @config = Configuration.read(site) root = File.join(site.source, @config["root"]) unless Dir.exist?(root) ::Jekyll.logger.warn "jekyll-documents", "Directory not found: #{root}" return end collection = ensure_collection(site, "documents") current_paths = [] Dir.glob("#{root}/**/*").each do |path| next unless File.file?(path) ext = File.extname(path).downcase if @config["strict_extensions"] && !@config["include_extensions"].include?(ext) ::Jekyll.logger.abort_with "jekyll-documents", "Unsupported file type: #{path} (#{ext})" end next unless @config["include_extensions"].include?(ext) rel_path = path.delete_prefix("#{site.source}/") current_paths << rel_path category = infer_category_from(rel_path) basename = File.basename(path, ext) date, title, valid = parse_filename(basename) if !valid && @config["strict_filename"] ::Jekyll.logger.abort_with "jekyll-documents", "Filename must be 'YYYY-MM-DD_Title.ext' → #{rel_path}" end slug = build_slug(basename) file_type = ext.sub(".", "").downcase icon_set = @config["icon_set"] doc = ::Jekyll::Document.new( source_stub_for(basename, category), site: site, collection: collection ) file_info = { title: title, date: date, category: category, rel_path: rel_path, ext: ext, file_type: file_type, icon_set: icon_set, slug: slug, path: path } bake_document_data(doc, file_info) collection.docs << doc end cleanup_manifest(current_paths) if @config["extract_text"] configure_client_search(site) end |