class Jekyll::OpenProjectHelpers::CollectionDocReader
Public Instance Methods
read(dir, collection)
click to toggle source
# File lib/jekyll-theme-open-project-helpers/project_data_reader.rb, line 21 def read(dir, collection) read_project_subdir(dir, collection) end
read_project_subdir(dir, collection, nested=false)
click to toggle source
# File lib/jekyll-theme-open-project-helpers/project_data_reader.rb, line 25 def read_project_subdir(dir, collection, nested=false) return unless File.directory?(dir) && !@entry_filter.symlink?(dir) entries = Dir.chdir(dir) do Dir["*.{adoc,md,markdown,html,svg,png}"] + Dir["*"].select { |fn| File.directory?(fn) } end entries.each do |entry| path = File.join(dir, entry) Jekyll.logger.debug("OPF:", "Reading entry #{path}") if File.directory?(path) read_project_subdir(path, collection, nested=true) elsif nested or (File.basename(entry, '.*') != 'index') ext = File.extname(path) if ['.adoc', '.md', '.markdown'].include? ext doc = NonLiquidDocument.new(path, :site => @site, :collection => collection) doc.read # Add document to Jekyll document database if it refers to software or spec # (as opposed to be some random nested document within repository source, like a README) doc_url_parts = doc.url.split('/') Jekyll.logger.debug("OPF:", "Reading document in collection #{collection.label} with URL #{doc.url} (#{doc_url_parts.size} parts)") if collection.label != 'projects' or doc_url_parts.size == 5 Jekyll.logger.debug("OPF:", "Adding document with URL: #{doc.url}") collection.docs << doc else Jekyll.logger.debug("OPF:", "Did NOT add document with URL (possibly nesting level doesn’t match): #{doc.url}") end else Jekyll.logger.debug("OPF:", "Adding static file: #{path}") collection.files << Jekyll::StaticFile.new( @site, @site.source, Pathname.new(File.dirname(path)).relative_path_from(Pathname.new(@site.source)).to_s, File.basename(path), collection) end end end end