jekyll-docs 3.6.1.0 → 3.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll.rb +195 -0
- data/lib/jekyll/cleaner.rb +110 -0
- data/lib/jekyll/collection.rb +230 -0
- data/lib/jekyll/command.rb +78 -0
- data/lib/jekyll/commands/build.rb +102 -0
- data/lib/jekyll/commands/clean.rb +43 -0
- data/lib/jekyll/commands/doctor.rb +153 -0
- data/lib/jekyll/commands/help.rb +34 -0
- data/lib/jekyll/commands/new.rb +156 -0
- data/lib/jekyll/commands/new_theme.rb +40 -0
- data/lib/jekyll/commands/serve.rb +245 -0
- data/lib/jekyll/commands/serve/servlet.rb +62 -0
- data/lib/jekyll/configuration.rb +410 -0
- data/lib/jekyll/converter.rb +54 -0
- data/lib/jekyll/converters/identity.rb +23 -0
- data/lib/jekyll/converters/markdown.rb +104 -0
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +123 -0
- data/lib/jekyll/converters/markdown/rdiscount_parser.rb +35 -0
- data/lib/jekyll/converters/markdown/redcarpet_parser.rb +108 -0
- data/lib/jekyll/converters/smartypants.rb +36 -0
- data/lib/jekyll/convertible.rb +251 -0
- data/lib/jekyll/deprecator.rb +52 -0
- data/lib/jekyll/document.rb +507 -0
- data/lib/jekyll/drops/collection_drop.rb +22 -0
- data/lib/jekyll/drops/document_drop.rb +69 -0
- data/lib/jekyll/drops/drop.rb +214 -0
- data/lib/jekyll/drops/excerpt_drop.rb +15 -0
- data/lib/jekyll/drops/jekyll_drop.rb +33 -0
- data/lib/jekyll/drops/site_drop.rb +47 -0
- data/lib/jekyll/drops/static_file_drop.rb +13 -0
- data/lib/jekyll/drops/unified_payload_drop.rb +25 -0
- data/lib/jekyll/drops/url_drop.rb +88 -0
- data/lib/jekyll/entry_filter.rb +123 -0
- data/lib/jekyll/errors.rb +20 -0
- data/lib/jekyll/excerpt.rb +126 -0
- data/lib/jekyll/external.rb +74 -0
- data/lib/jekyll/filters.rb +430 -0
- data/lib/jekyll/filters/grouping_filters.rb +65 -0
- data/lib/jekyll/filters/url_filters.rb +60 -0
- data/lib/jekyll/frontmatter_defaults.rb +197 -0
- data/lib/jekyll/generator.rb +5 -0
- data/lib/jekyll/hooks.rb +104 -0
- data/lib/jekyll/layout.rb +62 -0
- data/lib/jekyll/liquid_extensions.rb +24 -0
- data/lib/jekyll/liquid_renderer.rb +49 -0
- data/lib/jekyll/liquid_renderer/file.rb +56 -0
- data/lib/jekyll/liquid_renderer/table.rb +96 -0
- data/lib/jekyll/log_adapter.rb +147 -0
- data/lib/jekyll/mime.types +825 -0
- data/lib/jekyll/page.rb +187 -0
- data/lib/jekyll/plugin.rb +98 -0
- data/lib/jekyll/plugin_manager.rb +113 -0
- data/lib/jekyll/publisher.rb +23 -0
- data/lib/jekyll/reader.rb +134 -0
- data/lib/jekyll/readers/collection_reader.rb +22 -0
- data/lib/jekyll/readers/data_reader.rb +77 -0
- data/lib/jekyll/readers/layout_reader.rb +71 -0
- data/lib/jekyll/readers/page_reader.rb +25 -0
- data/lib/jekyll/readers/post_reader.rb +72 -0
- data/lib/jekyll/readers/static_file_reader.rb +25 -0
- data/lib/jekyll/readers/theme_assets_reader.rb +49 -0
- data/lib/jekyll/regenerator.rb +201 -0
- data/lib/jekyll/related_posts.rb +52 -0
- data/lib/jekyll/renderer.rb +269 -0
- data/lib/jekyll/site.rb +472 -0
- data/lib/jekyll/static_file.rb +162 -0
- data/lib/jekyll/stevenson.rb +61 -0
- data/lib/jekyll/tags/highlight.rb +141 -0
- data/lib/jekyll/tags/include.rb +215 -0
- data/lib/jekyll/tags/link.rb +37 -0
- data/lib/jekyll/tags/post_url.rb +103 -0
- data/lib/jekyll/theme.rb +68 -0
- data/lib/jekyll/theme_builder.rb +119 -0
- data/lib/jekyll/url.rb +161 -0
- data/lib/jekyll/utils.rb +340 -0
- data/lib/jekyll/utils/ansi.rb +59 -0
- data/lib/jekyll/utils/exec.rb +27 -0
- data/lib/jekyll/utils/platforms.rb +82 -0
- data/lib/jekyll/utils/rouge.rb +21 -0
- data/lib/jekyll/utils/win_tz.rb +75 -0
- data/lib/jekyll/version.rb +5 -0
- data/lib/site_template/404.html +24 -0
- data/lib/site_template/_config.yml +43 -0
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +25 -0
- data/lib/site_template/about.md +18 -0
- data/lib/site_template/index.md +6 -0
- data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -0
- data/lib/theme_template/Gemfile +4 -0
- data/lib/theme_template/LICENSE.txt.erb +21 -0
- data/lib/theme_template/README.md.erb +52 -0
- data/lib/theme_template/_layouts/default.html +1 -0
- data/lib/theme_template/_layouts/page.html +5 -0
- data/lib/theme_template/_layouts/post.html +5 -0
- data/lib/theme_template/example/_config.yml.erb +1 -0
- data/lib/theme_template/example/_post.md +12 -0
- data/lib/theme_template/example/index.html +14 -0
- data/lib/theme_template/example/style.scss +7 -0
- data/lib/theme_template/gitignore.erb +5 -0
- data/lib/theme_template/theme.gemspec.erb +19 -0
- metadata +103 -156
- data/lib/jekyll-docs.rb +0 -31
- data/site/404.html +0 -153
- data/site/CNAME +0 -1
- data/site/community/index.html +0 -299
- data/site/conduct/index.html +0 -10
- data/site/css/screen.css +0 -1
- data/site/docs/assets/index.html +0 -724
- data/site/docs/code_of_conduct/index.html +0 -730
- data/site/docs/collections/index.html +0 -1097
- data/site/docs/conduct/index.html +0 -744
- data/site/docs/configuration/index.html +0 -1403
- data/site/docs/continuous-integration/buddyworks/index.html +0 -726
- data/site/docs/continuous-integration/circleci/index.html +0 -757
- data/site/docs/continuous-integration/index.html +0 -681
- data/site/docs/continuous-integration/travis-ci/index.html +0 -891
- data/site/docs/contributing/index.html +0 -863
- data/site/docs/datafiles/index.html +0 -780
- data/site/docs/deployment-methods/index.html +0 -875
- data/site/docs/drafts/index.html +0 -636
- data/site/docs/extras/index.html +0 -689
- data/site/docs/frontmatter/index.html +0 -821
- data/site/docs/github-pages/index.html +0 -819
- data/site/docs/history/index.html +0 -3955
- data/site/docs/home/index.html +0 -644
- data/site/docs/includes/index.html +0 -800
- data/site/docs/index.html +0 -10
- data/site/docs/installation/index.html +0 -732
- data/site/docs/maintaining/affinity-team-captain/index.html +0 -706
- data/site/docs/maintaining/avoiding-burnout/index.html +0 -709
- data/site/docs/maintaining/becoming-a-maintainer/index.html +0 -717
- data/site/docs/maintaining/index.html +0 -713
- data/site/docs/maintaining/merging-a-pull-request/index.html +0 -747
- data/site/docs/maintaining/reviewing-a-pull-request/index.html +0 -725
- data/site/docs/maintaining/special-labels/index.html +0 -705
- data/site/docs/maintaining/triaging-an-issue/index.html +0 -735
- data/site/docs/migrations/index.html +0 -647
- data/site/docs/pages/index.html +0 -695
- data/site/docs/pagination/index.html +0 -870
- data/site/docs/permalinks/index.html +0 -1035
- data/site/docs/plugins/index.html +0 -1800
- data/site/docs/posts/index.html +0 -858
- data/site/docs/quickstart/index.html +0 -650
- data/site/docs/resources/index.html +0 -769
- data/site/docs/sites/index.html +0 -702
- data/site/docs/static-files/index.html +0 -720
- data/site/docs/structure/index.html +0 -822
- data/site/docs/templates/index.html +0 -1208
- data/site/docs/themes/index.html +0 -935
- data/site/docs/troubleshooting/index.html +0 -916
- data/site/docs/upgrading/0-to-2/index.html +0 -826
- data/site/docs/upgrading/2-to-3/index.html +0 -824
- data/site/docs/upgrading/index.html +0 -693
- data/site/docs/usage/index.html +0 -705
- data/site/docs/variables/index.html +0 -1048
- data/site/docs/windows/index.html +0 -799
- data/site/favicon.ico +0 -0
- data/site/feed.xml +0 -372
- data/site/fonts/FontAwesome.eot +0 -0
- data/site/fonts/FontAwesome.svg +0 -12
- data/site/fonts/FontAwesome.ttf +0 -0
- data/site/fonts/FontAwesome.woff +0 -0
- data/site/github.html +0 -10
- data/site/help/index.html +0 -244
- data/site/icomoon-selection.json +0 -96
- data/site/img/article-footer.png +0 -0
- data/site/img/footer-arrow.png +0 -0
- data/site/img/footer-logo.png +0 -0
- data/site/img/jekyll-sticker.jpg +0 -0
- data/site/img/jekylllayoutconcept.png +0 -0
- data/site/img/logo-2x.png +0 -0
- data/site/img/logo-rss.png +0 -0
- data/site/img/octojekyll.png +0 -0
- data/site/index.html +0 -267
- data/site/issues.html +0 -10
- data/site/js/html5shiv.min.js +0 -4
- data/site/js/respond.min.js +0 -5
- data/site/latest_version.txt +0 -1
- data/site/news/2013/05/05/jekyll-1-0-0-released/index.html +0 -570
- data/site/news/2013/05/08/jekyll-1-0-1-released/index.html +0 -570
- data/site/news/2013/05/12/jekyll-1-0-2-released/index.html +0 -571
- data/site/news/2013/06/07/jekyll-1-0-3-released/index.html +0 -568
- data/site/news/2013/07/14/jekyll-1-1-0-released/index.html +0 -570
- data/site/news/2013/07/24/jekyll-1-1-1-released/index.html +0 -569
- data/site/news/2013/07/25/jekyll-1-0-4-released/index.html +0 -565
- data/site/news/2013/07/25/jekyll-1-1-2-released/index.html +0 -565
- data/site/news/2013/09/06/jekyll-1-2-0-released/index.html +0 -572
- data/site/news/2013/09/14/jekyll-1-2-1-released/index.html +0 -566
- data/site/news/2013/10/28/jekyll-1-3-0-rc1-released/index.html +0 -564
- data/site/news/2013/11/04/jekyll-1-3-0-released/index.html +0 -599
- data/site/news/2013/11/26/jekyll-1-3-1-released/index.html +0 -568
- data/site/news/2013/12/07/jekyll-1-4-0-released/index.html +0 -583
- data/site/news/2013/12/09/jekyll-1-4-1-released/index.html +0 -565
- data/site/news/2013/12/16/jekyll-1-4-2-released/index.html +0 -564
- data/site/news/2014/01/13/jekyll-1-4-3-released/index.html +0 -573
- data/site/news/2014/03/24/jekyll-1-5-0-released/index.html +0 -564
- data/site/news/2014/03/27/jekyll-1-5-1-released/index.html +0 -569
- data/site/news/2014/05/06/jekyll-turns-2-0-0/index.html +0 -585
- data/site/news/2014/05/08/jekyll-2-0-3-released/index.html +0 -565
- data/site/news/2014/06/04/jekyll-stickers-1-dollar-stickermule/index.html +0 -567
- data/site/news/2014/06/28/jekyll-turns-21-i-mean-2-1-0/index.html +0 -582
- data/site/news/2014/07/01/jekyll-2-1-1-released/index.html +0 -579
- data/site/news/2014/07/29/jekyll-2-2-0-released/index.html +0 -568
- data/site/news/2014/08/10/jekyll-2-3-0-released/index.html +0 -588
- data/site/news/2014/09/09/jekyll-2-4-0-released/index.html +0 -574
- data/site/news/2014/11/05/jekylls-midlife-crisis-jekyll-turns-2-5-0/index.html +0 -597
- data/site/news/2014/11/09/jekyll-2-5-1-released/index.html +0 -575
- data/site/news/2014/11/12/jekyll-2-5-2-released/index.html +0 -565
- data/site/news/2014/12/17/alfredxing-welcome-to-jekyll-core/index.html +0 -572
- data/site/news/2014/12/22/jekyll-2-5-3-released/index.html +0 -567
- data/site/news/2015/01/20/jekyll-meet-and-greet/index.html +0 -568
- data/site/news/2015/01/24/jekyll-3-0-0-beta1-released/index.html +0 -588
- data/site/news/2015/02/26/introducing-jekyll-talk/index.html +0 -563
- data/site/news/2015/10/26/jekyll-3-0-released/index.html +0 -592
- data/site/news/2015/11/17/jekyll-3-0-1-released/index.html +0 -576
- data/site/news/2016/01/20/jekyll-3-0-2-released/index.html +0 -566
- data/site/news/2016/01/24/jekyll-3-1-0-released/index.html +0 -599
- data/site/news/2016/01/28/jekyll-3-1-1-released/index.html +0 -583
- data/site/news/2016/02/08/jekyll-3-0-3-released/index.html +0 -578
- data/site/news/2016/02/19/jekyll-3-1-2-released/index.html +0 -569
- data/site/news/2016/03/10/making-it-easier-to-contribute-to-jekyll/index.html +0 -565
- data/site/news/2016/04/19/jekyll-3-0-4-released/index.html +0 -571
- data/site/news/2016/04/19/jekyll-3-1-3-released/index.html +0 -566
- data/site/news/2016/04/26/jekyll-3-0-5-released/index.html +0 -572
- data/site/news/2016/05/18/jekyll-3-1-4-released/index.html +0 -576
- data/site/news/2016/05/18/jekyll-3-1-5-released/index.html +0 -564
- data/site/news/2016/05/19/jekyll-3-1-6-released/index.html +0 -566
- data/site/news/2016/06/03/update-on-jekyll-s-google-summer-of-code-projects/index.html +0 -567
- data/site/news/2016/07/26/jekyll-3-2-0-released/index.html +0 -676
- data/site/news/2016/08/02/jekyll-3-2-1-released/index.html +0 -571
- data/site/news/2016/08/24/jekyll-admin-initial-release/index.html +0 -566
- data/site/news/2016/10/06/jekyll-3-3-is-here/index.html +0 -645
- data/site/news/2016/11/14/jekyll-3-3-1-released/index.html +0 -569
- data/site/news/2017/01/18/jekyll-3-4-0-released/index.html +0 -592
- data/site/news/2017/03/02/jekyll-3-4-1-released/index.html +0 -649
- data/site/news/2017/03/09/jekyll-3-4-2-released/index.html +0 -598
- data/site/news/2017/03/21/jekyll-3-4-3-released/index.html +0 -594
- data/site/news/2017/06/15/jekyll-3-5-0-released/index.html +0 -589
- data/site/news/2017/07/17/jekyll-3-5-1-released/index.html +0 -569
- data/site/news/2017/08/12/jekyll-3-5-2-released/index.html +0 -573
- data/site/news/2017/09/21/jekyll-3-6-0-released/index.html +0 -565
- data/site/news/index.html +0 -3609
- data/site/news/releases/index.html +0 -3344
- data/site/philosophy.html +0 -46
- data/site/readme.md +0 -23
- data/site/robots.txt +0 -1
- data/site/sitemap.xml +0 -485
- data/site/tutorials/convert-site-to-jekyll/index.html +0 -793
- data/site/tutorials/custom-404-page/index.html +0 -358
- data/site/tutorials/home/index.html +0 -323
- data/site/tutorials/index.html +0 -10
- data/site/tutorials/navigation/index.html +0 -872
- data/site/tutorials/orderofinterpretation/index.html +0 -441
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
module GroupingFilters
|
6
|
+
# Group an array of items by a property
|
7
|
+
#
|
8
|
+
# input - the inputted Enumerable
|
9
|
+
# property - the property
|
10
|
+
#
|
11
|
+
# Returns an array of Hashes, each looking something like this:
|
12
|
+
# {"name" => "larry"
|
13
|
+
# "items" => [...] } # all the items where `property` == "larry"
|
14
|
+
def group_by(input, property)
|
15
|
+
if groupable?(input)
|
16
|
+
groups = input.group_by { |item| item_property(item, property).to_s }
|
17
|
+
grouped_array(groups)
|
18
|
+
else
|
19
|
+
input
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Group an array of items by an expression
|
24
|
+
#
|
25
|
+
# input - the object array
|
26
|
+
# variable - the variable to assign each item to in the expression
|
27
|
+
# expression -a Liquid comparison expression passed in as a string
|
28
|
+
#
|
29
|
+
# Returns the filtered array of objects
|
30
|
+
def group_by_exp(input, variable, expression)
|
31
|
+
return input unless groupable?(input)
|
32
|
+
|
33
|
+
parsed_expr = parse_expression(expression)
|
34
|
+
@context.stack do
|
35
|
+
groups = input.group_by do |item|
|
36
|
+
@context[variable] = item
|
37
|
+
parsed_expr.render(@context)
|
38
|
+
end
|
39
|
+
grouped_array(groups)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def parse_expression(str)
|
45
|
+
Liquid::Variable.new(str, Liquid::ParseContext.new)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def groupable?(element)
|
50
|
+
element.respond_to?(:group_by)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def grouped_array(groups)
|
55
|
+
groups.each_with_object([]) do |item, array|
|
56
|
+
array << {
|
57
|
+
"name" => item.first,
|
58
|
+
"items" => item.last,
|
59
|
+
"size" => item.last.size,
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "addressable/uri"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Filters
|
7
|
+
module URLFilters
|
8
|
+
# Produces an absolute URL based on site.url and site.baseurl.
|
9
|
+
#
|
10
|
+
# input - the URL to make absolute.
|
11
|
+
#
|
12
|
+
# Returns the absolute URL as a String.
|
13
|
+
def absolute_url(input)
|
14
|
+
return if input.nil?
|
15
|
+
return input if Addressable::URI.parse(input.to_s).absolute?
|
16
|
+
site = @context.registers[:site]
|
17
|
+
return relative_url(input) if site.config["url"].nil?
|
18
|
+
Addressable::URI.parse(
|
19
|
+
site.config["url"].to_s + relative_url(input)
|
20
|
+
).normalize.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
# Produces a URL relative to the domain root based on site.baseurl.
|
24
|
+
#
|
25
|
+
# input - the URL to make relative to the domain root
|
26
|
+
#
|
27
|
+
# Returns a URL relative to the domain root as a String.
|
28
|
+
def relative_url(input)
|
29
|
+
return if input.nil?
|
30
|
+
parts = [sanitized_baseurl, input]
|
31
|
+
Addressable::URI.parse(
|
32
|
+
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
|
33
|
+
).normalize.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
# Strips trailing `/index.html` from URLs to create pretty permalinks
|
37
|
+
#
|
38
|
+
# input - the URL with a possible `/index.html`
|
39
|
+
#
|
40
|
+
# Returns a URL with the trailing `/index.html` removed
|
41
|
+
def strip_index(input)
|
42
|
+
return if input.nil? || input.to_s.empty?
|
43
|
+
input.sub(%r!/index\.html?$!, "/")
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def sanitized_baseurl
|
49
|
+
site = @context.registers[:site]
|
50
|
+
site.config["baseurl"].to_s.chomp("/")
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_leading_slash(input)
|
54
|
+
return input if input.nil? || input.empty? || input.start_with?("/")
|
55
|
+
"/#{input}"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
# This class handles custom defaults for YAML frontmatter settings.
|
5
|
+
# These are set in _config.yml and apply both to internal use (e.g. layout)
|
6
|
+
# and the data available to liquid.
|
7
|
+
#
|
8
|
+
# It is exposed via the frontmatter_defaults method on the site class.
|
9
|
+
class FrontmatterDefaults
|
10
|
+
# Initializes a new instance.
|
11
|
+
def initialize(site)
|
12
|
+
@site = site
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_deprecated_types(set)
|
16
|
+
return set unless set.key?("scope") && set["scope"].key?("type")
|
17
|
+
|
18
|
+
set["scope"]["type"] =
|
19
|
+
case set["scope"]["type"]
|
20
|
+
when "page"
|
21
|
+
Deprecator.defaults_deprecate_type("page", "pages")
|
22
|
+
"pages"
|
23
|
+
when "post"
|
24
|
+
Deprecator.defaults_deprecate_type("post", "posts")
|
25
|
+
"posts"
|
26
|
+
when "draft"
|
27
|
+
Deprecator.defaults_deprecate_type("draft", "drafts")
|
28
|
+
"drafts"
|
29
|
+
else
|
30
|
+
set["scope"]["type"]
|
31
|
+
end
|
32
|
+
|
33
|
+
set
|
34
|
+
end
|
35
|
+
|
36
|
+
def ensure_time!(set)
|
37
|
+
return set unless set.key?("values") && set["values"].key?("date")
|
38
|
+
return set if set["values"]["date"].is_a?(Time)
|
39
|
+
set["values"]["date"] = Utils.parse_date(
|
40
|
+
set["values"]["date"],
|
41
|
+
"An invalid date format was found in a front-matter default set: #{set}"
|
42
|
+
)
|
43
|
+
set
|
44
|
+
end
|
45
|
+
|
46
|
+
# Finds a default value for a given setting, filtered by path and type
|
47
|
+
#
|
48
|
+
# path - the path (relative to the source) of the page,
|
49
|
+
# post or :draft the default is used in
|
50
|
+
# type - a symbol indicating whether a :page,
|
51
|
+
# a :post or a :draft calls this method
|
52
|
+
#
|
53
|
+
# Returns the default value or nil if none was found
|
54
|
+
def find(path, type, setting)
|
55
|
+
value = nil
|
56
|
+
old_scope = nil
|
57
|
+
|
58
|
+
matching_sets(path, type).each do |set|
|
59
|
+
if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"])
|
60
|
+
value = set["values"][setting]
|
61
|
+
old_scope = set["scope"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
value
|
65
|
+
end
|
66
|
+
|
67
|
+
# Collects a hash with all default values for a page or post
|
68
|
+
#
|
69
|
+
# path - the relative path of the page or post
|
70
|
+
# type - a symbol indicating the type (:post, :page or :draft)
|
71
|
+
#
|
72
|
+
# Returns a hash with all default values (an empty hash if there are none)
|
73
|
+
def all(path, type)
|
74
|
+
defaults = {}
|
75
|
+
old_scope = nil
|
76
|
+
matching_sets(path, type).each do |set|
|
77
|
+
if has_precedence?(old_scope, set["scope"])
|
78
|
+
defaults = Utils.deep_merge_hashes(defaults, set["values"])
|
79
|
+
old_scope = set["scope"]
|
80
|
+
else
|
81
|
+
defaults = Utils.deep_merge_hashes(set["values"], defaults)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
defaults
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# Checks if a given default setting scope matches the given path and type
|
90
|
+
#
|
91
|
+
# scope - the hash indicating the scope, as defined in _config.yml
|
92
|
+
# path - the path to check for
|
93
|
+
# type - the type (:post, :page or :draft) to check for
|
94
|
+
#
|
95
|
+
# Returns true if the scope applies to the given path and type
|
96
|
+
def applies?(scope, path, type)
|
97
|
+
applies_path?(scope, path) && applies_type?(scope, type)
|
98
|
+
end
|
99
|
+
|
100
|
+
def applies_path?(scope, path)
|
101
|
+
return true if !scope.key?("path") || scope["path"].empty?
|
102
|
+
|
103
|
+
scope_path = Pathname.new(scope["path"])
|
104
|
+
Pathname.new(sanitize_path(path)).ascend do |ascended_path|
|
105
|
+
if ascended_path.to_s == scope_path.to_s
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Determines whether the scope applies to type.
|
112
|
+
# The scope applies to the type if:
|
113
|
+
# 1. no 'type' is specified
|
114
|
+
# 2. the 'type' in the scope is the same as the type asked about
|
115
|
+
#
|
116
|
+
# scope - the Hash defaults set being asked about application
|
117
|
+
# type - the type of the document being processed / asked about
|
118
|
+
# its defaults.
|
119
|
+
#
|
120
|
+
# Returns true if either of the above conditions are satisfied,
|
121
|
+
# otherwise returns false
|
122
|
+
def applies_type?(scope, type)
|
123
|
+
!scope.key?("type") || scope["type"].eql?(type.to_s)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Checks if a given set of default values is valid
|
127
|
+
#
|
128
|
+
# set - the default value hash, as defined in _config.yml
|
129
|
+
#
|
130
|
+
# Returns true if the set is valid and can be used in this class
|
131
|
+
def valid?(set)
|
132
|
+
set.is_a?(Hash) && set["values"].is_a?(Hash)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Determines if a new scope has precedence over an old one
|
136
|
+
#
|
137
|
+
# old_scope - the old scope hash, or nil if there's none
|
138
|
+
# new_scope - the new scope hash
|
139
|
+
#
|
140
|
+
# Returns true if the new scope has precedence over the older
|
141
|
+
# rubocop: disable PredicateName
|
142
|
+
def has_precedence?(old_scope, new_scope)
|
143
|
+
return true if old_scope.nil?
|
144
|
+
|
145
|
+
new_path = sanitize_path(new_scope["path"])
|
146
|
+
old_path = sanitize_path(old_scope["path"])
|
147
|
+
|
148
|
+
if new_path.length != old_path.length
|
149
|
+
new_path.length >= old_path.length
|
150
|
+
elsif new_scope.key?("type")
|
151
|
+
true
|
152
|
+
else
|
153
|
+
!old_scope.key? "type"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
# rubocop: enable PredicateName
|
157
|
+
|
158
|
+
# Collects a list of sets that match the given path and type
|
159
|
+
#
|
160
|
+
# Returns an array of hashes
|
161
|
+
def matching_sets(path, type)
|
162
|
+
valid_sets.select do |set|
|
163
|
+
!set.key?("scope") || applies?(set["scope"], path, type)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns a list of valid sets
|
168
|
+
#
|
169
|
+
# This is not cached to allow plugins to modify the configuration
|
170
|
+
# and have their changes take effect
|
171
|
+
#
|
172
|
+
# Returns an array of hashes
|
173
|
+
def valid_sets
|
174
|
+
sets = @site.config["defaults"]
|
175
|
+
return [] unless sets.is_a?(Array)
|
176
|
+
|
177
|
+
sets.map do |set|
|
178
|
+
if valid?(set)
|
179
|
+
ensure_time!(update_deprecated_types(set))
|
180
|
+
else
|
181
|
+
Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
|
182
|
+
Jekyll.logger.warn set.to_s
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
end.compact
|
186
|
+
end
|
187
|
+
|
188
|
+
# Sanitizes the given path by removing a leading and adding a trailing slash
|
189
|
+
def sanitize_path(path)
|
190
|
+
if path.nil? || path.empty?
|
191
|
+
""
|
192
|
+
else
|
193
|
+
path.gsub(%r!\A/|(?<=[^/])\z!, "".freeze)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
data/lib/jekyll/hooks.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Hooks
|
5
|
+
DEFAULT_PRIORITY = 20
|
6
|
+
|
7
|
+
# compatibility layer for octopress-hooks users
|
8
|
+
PRIORITY_MAP = {
|
9
|
+
:low => 10,
|
10
|
+
:normal => 20,
|
11
|
+
:high => 30,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
# initial empty hooks
|
15
|
+
@registry = {
|
16
|
+
:site => {
|
17
|
+
:after_init => [],
|
18
|
+
:after_reset => [],
|
19
|
+
:post_read => [],
|
20
|
+
:pre_render => [],
|
21
|
+
:post_render => [],
|
22
|
+
:post_write => [],
|
23
|
+
},
|
24
|
+
:pages => {
|
25
|
+
:post_init => [],
|
26
|
+
:pre_render => [],
|
27
|
+
:post_render => [],
|
28
|
+
:post_write => [],
|
29
|
+
},
|
30
|
+
:posts => {
|
31
|
+
:post_init => [],
|
32
|
+
:pre_render => [],
|
33
|
+
:post_render => [],
|
34
|
+
:post_write => [],
|
35
|
+
},
|
36
|
+
:documents => {
|
37
|
+
:post_init => [],
|
38
|
+
:pre_render => [],
|
39
|
+
:post_render => [],
|
40
|
+
:post_write => [],
|
41
|
+
},
|
42
|
+
}
|
43
|
+
|
44
|
+
# map of all hooks and their priorities
|
45
|
+
@hook_priority = {}
|
46
|
+
|
47
|
+
NotAvailable = Class.new(RuntimeError)
|
48
|
+
Uncallable = Class.new(RuntimeError)
|
49
|
+
|
50
|
+
# register hook(s) to be called later, public API
|
51
|
+
def self.register(owners, event, priority: DEFAULT_PRIORITY, &block)
|
52
|
+
Array(owners).each do |owner|
|
53
|
+
register_one(owner, event, priority_value(priority), &block)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Ensure the priority is a Fixnum
|
58
|
+
def self.priority_value(priority)
|
59
|
+
return priority if priority.is_a?(Integer)
|
60
|
+
PRIORITY_MAP[priority] || DEFAULT_PRIORITY
|
61
|
+
end
|
62
|
+
|
63
|
+
# register a single hook to be called later, internal API
|
64
|
+
def self.register_one(owner, event, priority, &block)
|
65
|
+
@registry[owner] ||= {
|
66
|
+
:post_init => [],
|
67
|
+
:pre_render => [],
|
68
|
+
:post_render => [],
|
69
|
+
:post_write => [],
|
70
|
+
}
|
71
|
+
|
72
|
+
unless @registry[owner][event]
|
73
|
+
raise NotAvailable, "Invalid hook. #{owner} supports only the " \
|
74
|
+
"following hooks #{@registry[owner].keys.inspect}"
|
75
|
+
end
|
76
|
+
|
77
|
+
unless block.respond_to? :call
|
78
|
+
raise Uncallable, "Hooks must respond to :call"
|
79
|
+
end
|
80
|
+
|
81
|
+
insert_hook owner, event, priority, &block
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.insert_hook(owner, event, priority, &block)
|
85
|
+
@hook_priority[block] = [-priority, @hook_priority.size]
|
86
|
+
@registry[owner][event] << block
|
87
|
+
end
|
88
|
+
|
89
|
+
# interface for Jekyll core components to trigger hooks
|
90
|
+
def self.trigger(owner, event, *args)
|
91
|
+
# proceed only if there are hooks to call
|
92
|
+
return unless @registry[owner]
|
93
|
+
return unless @registry[owner][event]
|
94
|
+
|
95
|
+
# hooks to call for this owner and event
|
96
|
+
hooks = @registry[owner][event]
|
97
|
+
|
98
|
+
# sort and call hooks according to priority and load order
|
99
|
+
hooks.sort_by { |h| @hook_priority[h] }.each do |hook|
|
100
|
+
hook.call(*args)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Layout
|
5
|
+
include Convertible
|
6
|
+
|
7
|
+
# Gets the Site object.
|
8
|
+
attr_reader :site
|
9
|
+
|
10
|
+
# Gets the name of this layout.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# Gets the path to this layout.
|
14
|
+
attr_reader :path
|
15
|
+
|
16
|
+
# Gets the path to this layout relative to its base
|
17
|
+
attr_reader :relative_path
|
18
|
+
|
19
|
+
# Gets/Sets the extension of this layout.
|
20
|
+
attr_accessor :ext
|
21
|
+
|
22
|
+
# Gets/Sets the Hash that holds the metadata for this layout.
|
23
|
+
attr_accessor :data
|
24
|
+
|
25
|
+
# Gets/Sets the content of this layout.
|
26
|
+
attr_accessor :content
|
27
|
+
|
28
|
+
# Initialize a new Layout.
|
29
|
+
#
|
30
|
+
# site - The Site.
|
31
|
+
# base - The String path to the source.
|
32
|
+
# name - The String filename of the post file.
|
33
|
+
def initialize(site, base, name)
|
34
|
+
@site = site
|
35
|
+
@base = base
|
36
|
+
@name = name
|
37
|
+
|
38
|
+
if site.theme && site.theme.layouts_path.eql?(base)
|
39
|
+
@base_dir = site.theme.root
|
40
|
+
@path = site.in_theme_dir(base, name)
|
41
|
+
else
|
42
|
+
@base_dir = site.source
|
43
|
+
@path = site.in_source_dir(base, name)
|
44
|
+
end
|
45
|
+
@relative_path = @path.sub(@base_dir, "")
|
46
|
+
|
47
|
+
self.data = {}
|
48
|
+
|
49
|
+
process(name)
|
50
|
+
read_yaml(base, name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Extract information from the layout filename.
|
54
|
+
#
|
55
|
+
# name - The String filename of the layout file.
|
56
|
+
#
|
57
|
+
# Returns nothing.
|
58
|
+
def process(name)
|
59
|
+
self.ext = File.extname(name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|