Add ThemeAssetsReader which reads assets from a theme

If the theme includes the 'assets' directory, it will be walked and items will be added to the site based
on the normal rules of Jekyll: if there is YAML front matter, it will be added as a (convertible) Page,
otherwise it will be added as a StaticFile.
This commit is contained in:
Parker Moore 2016-09-16 14:40:54 -07:00
parent 562ffe7a3f
commit 13aec48137
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
5 changed files with 46 additions and 5 deletions

View File

@ -55,6 +55,7 @@ module Jekyll
autoload :PostReader, "jekyll/readers/post_reader"
autoload :PageReader, "jekyll/readers/page_reader"
autoload :StaticFileReader, "jekyll/readers/static_file_reader"
autoload :ThemeAssetsReader, "jekyll/readers/theme_assets_reader"
autoload :LogAdapter, "jekyll/log_adapter"
autoload :Page, "jekyll/page"
autoload :PluginManager, "jekyll/plugin_manager"

View File

@ -40,7 +40,11 @@ module Jekyll
@base = base
@dir = dir
@name = name
@path = site.in_source_dir(base, dir, name)
if site.in_theme_dir(base) == base # we're in a theme
@path = site.in_theme_dir(base, dir, name)
else
@path = site.in_source_dir(base, dir, name)
end
process(name)
read_yaml(File.join(base, dir), name)

View File

@ -18,6 +18,7 @@ module Jekyll
sort_files!
@site.data = DataReader.new(site).read(site.config["data_dir"])
CollectionReader.new(site).read
ThemeAssetsReader.new(site).read
end
# Sorts posts, pages, and static files.

View File

@ -0,0 +1,31 @@
module Jekyll
class ThemeAssetsReader
attr_reader :site
def initialize(site)
@site = site
end
def read
return unless site.theme && site.theme.assets_path
Find.find(site.theme.assets_path) do |path|
next if File.directory?(path)
if File.symlink?(path)
Jekyll.logger.warn "Theme reader:", "Ignored symlinked asset: #{path}"
else
base = site.theme.root
dir = File.dirname(path.sub("#{site.theme.root}/", ""))
name = File.basename(path)
relative_path = File.join(*[dir, name].compact)
if Utils.has_yaml_header?(path)
next if site.pages.any? { |file| file.relative_path == relative_path }
site.pages << Jekyll::Page.new(site, base, dir, name)
else
next if site.static_files.any? { |file| file.relative_path == relative_path }
site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
end
end
end
end
end
end

View File

@ -18,15 +18,19 @@ module Jekyll
end
def includes_path
path_for :includes
path_for :_includes
end
def layouts_path
path_for :layouts
path_for :_layouts
end
def sass_path
path_for :sass
path_for :_sass
end
def assets_path
path_for :assets
end
def configure_sass
@ -43,7 +47,7 @@ module Jekyll
end
def realpath_for(folder)
File.realpath(Jekyll.sanitized_path(root, "_#{folder}"))
File.realpath(Jekyll.sanitized_path(root, folder.to_s))
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
nil
end