jekyll-docs 3.6.0 → 3.6.1
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 +471 -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 +337 -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 -807
- 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 -1027
- 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 -893
- 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
data/lib/jekyll/utils.rb
ADDED
@@ -0,0 +1,337 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Utils
|
6
|
+
extend self
|
7
|
+
autoload :Ansi, "jekyll/utils/ansi"
|
8
|
+
autoload :Exec, "jekyll/utils/exec"
|
9
|
+
autoload :Platforms, "jekyll/utils/platforms"
|
10
|
+
autoload :Rouge, "jekyll/utils/rouge"
|
11
|
+
autoload :WinTZ, "jekyll/utils/win_tz"
|
12
|
+
|
13
|
+
# Constants for use in #slugify
|
14
|
+
SLUGIFY_MODES = %w(raw default pretty ascii).freeze
|
15
|
+
SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
|
16
|
+
SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^[:alnum:]]+").freeze
|
17
|
+
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
|
18
|
+
SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
|
19
|
+
|
20
|
+
# Takes an indented string and removes the preceding spaces on each line
|
21
|
+
|
22
|
+
def strip_heredoc(str)
|
23
|
+
str.gsub(%r!^[ \t]{#{(str.scan(%r!^[ \t]*(?=\S)!).min || "").size}}!, "")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Takes a slug and turns it into a simple title.
|
27
|
+
|
28
|
+
def titleize_slug(slug)
|
29
|
+
slug.split("-").map!(&:capitalize).join(" ")
|
30
|
+
end
|
31
|
+
|
32
|
+
# Non-destructive version of deep_merge_hashes! See that method.
|
33
|
+
#
|
34
|
+
# Returns the merged hashes.
|
35
|
+
def deep_merge_hashes(master_hash, other_hash)
|
36
|
+
deep_merge_hashes!(master_hash.dup, other_hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Merges a master hash with another hash, recursively.
|
40
|
+
#
|
41
|
+
# master_hash - the "parent" hash whose values will be overridden
|
42
|
+
# other_hash - the other hash whose values will be persisted after the merge
|
43
|
+
#
|
44
|
+
# This code was lovingly stolen from some random gem:
|
45
|
+
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
46
|
+
#
|
47
|
+
# Thanks to whoever made it.
|
48
|
+
def deep_merge_hashes!(target, overwrite)
|
49
|
+
merge_values(target, overwrite)
|
50
|
+
merge_default_proc(target, overwrite)
|
51
|
+
duplicate_frozen_values(target)
|
52
|
+
|
53
|
+
target
|
54
|
+
end
|
55
|
+
|
56
|
+
def mergable?(value)
|
57
|
+
value.is_a?(Hash) || value.is_a?(Drops::Drop)
|
58
|
+
end
|
59
|
+
|
60
|
+
def duplicable?(obj)
|
61
|
+
case obj
|
62
|
+
when nil, false, true, Symbol, Numeric
|
63
|
+
false
|
64
|
+
else
|
65
|
+
true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Read array from the supplied hash favouring the singular key
|
70
|
+
# and then the plural key, and handling any nil entries.
|
71
|
+
#
|
72
|
+
# hash - the hash to read from
|
73
|
+
# singular_key - the singular key
|
74
|
+
# plural_key - the plural key
|
75
|
+
#
|
76
|
+
# Returns an array
|
77
|
+
def pluralized_array_from_hash(hash, singular_key, plural_key)
|
78
|
+
[].tap do |array|
|
79
|
+
value = value_from_singular_key(hash, singular_key)
|
80
|
+
value ||= value_from_plural_key(hash, plural_key)
|
81
|
+
array << value
|
82
|
+
end.flatten.compact
|
83
|
+
end
|
84
|
+
|
85
|
+
def value_from_singular_key(hash, key)
|
86
|
+
hash[key] if hash.key?(key) || (hash.default_proc && hash[key])
|
87
|
+
end
|
88
|
+
|
89
|
+
def value_from_plural_key(hash, key)
|
90
|
+
if hash.key?(key) || (hash.default_proc && hash[key])
|
91
|
+
val = hash[key]
|
92
|
+
case val
|
93
|
+
when String
|
94
|
+
val.split
|
95
|
+
when Array
|
96
|
+
val.compact
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def transform_keys(hash)
|
102
|
+
result = {}
|
103
|
+
hash.each_key do |key|
|
104
|
+
result[yield(key)] = hash[key]
|
105
|
+
end
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
# Apply #to_sym to all keys in the hash
|
110
|
+
#
|
111
|
+
# hash - the hash to which to apply this transformation
|
112
|
+
#
|
113
|
+
# Returns a new hash with symbolized keys
|
114
|
+
def symbolize_hash_keys(hash)
|
115
|
+
transform_keys(hash) { |key| key.to_sym rescue key }
|
116
|
+
end
|
117
|
+
|
118
|
+
# Apply #to_s to all keys in the Hash
|
119
|
+
#
|
120
|
+
# hash - the hash to which to apply this transformation
|
121
|
+
#
|
122
|
+
# Returns a new hash with stringified keys
|
123
|
+
def stringify_hash_keys(hash)
|
124
|
+
transform_keys(hash) { |key| key.to_s rescue key }
|
125
|
+
end
|
126
|
+
|
127
|
+
# Parse a date/time and throw an error if invalid
|
128
|
+
#
|
129
|
+
# input - the date/time to parse
|
130
|
+
# msg - (optional) the error message to show the user
|
131
|
+
#
|
132
|
+
# Returns the parsed date if successful, throws a FatalException
|
133
|
+
# if not
|
134
|
+
def parse_date(input, msg = "Input could not be parsed.")
|
135
|
+
Time.parse(input).localtime
|
136
|
+
rescue ArgumentError
|
137
|
+
raise Errors::InvalidDateError, "Invalid date '#{input}': #{msg}"
|
138
|
+
end
|
139
|
+
|
140
|
+
# Determines whether a given file has
|
141
|
+
#
|
142
|
+
# Returns true if the YAML front matter is present.
|
143
|
+
# rubocop: disable PredicateName
|
144
|
+
def has_yaml_header?(file)
|
145
|
+
!!(File.open(file, "rb", &:readline) =~ %r!\A---\s*\r?\n!)
|
146
|
+
rescue EOFError
|
147
|
+
false
|
148
|
+
end
|
149
|
+
# rubocop: enable PredicateName
|
150
|
+
|
151
|
+
# Slugify a filename or title.
|
152
|
+
#
|
153
|
+
# string - the filename or title to slugify
|
154
|
+
# mode - how string is slugified
|
155
|
+
# cased - whether to replace all uppercase letters with their
|
156
|
+
# lowercase counterparts
|
157
|
+
#
|
158
|
+
# When mode is "none", return the given string.
|
159
|
+
#
|
160
|
+
# When mode is "raw", return the given string,
|
161
|
+
# with every sequence of spaces characters replaced with a hyphen.
|
162
|
+
#
|
163
|
+
# When mode is "default" or nil, non-alphabetic characters are
|
164
|
+
# replaced with a hyphen too.
|
165
|
+
#
|
166
|
+
# When mode is "pretty", some non-alphabetic characters (._~!$&'()+,;=@)
|
167
|
+
# are not replaced with hyphen.
|
168
|
+
#
|
169
|
+
# When mode is "ascii", some everything else except ASCII characters
|
170
|
+
# a-z (lowercase), A-Z (uppercase) and 0-9 (numbers) are not replaced with hyphen.
|
171
|
+
#
|
172
|
+
# If cased is true, all uppercase letters in the result string are
|
173
|
+
# replaced with their lowercase counterparts.
|
174
|
+
#
|
175
|
+
# Examples:
|
176
|
+
# slugify("The _config.yml file")
|
177
|
+
# # => "the-config-yml-file"
|
178
|
+
#
|
179
|
+
# slugify("The _config.yml file", "pretty")
|
180
|
+
# # => "the-_config.yml-file"
|
181
|
+
#
|
182
|
+
# slugify("The _config.yml file", "pretty", true)
|
183
|
+
# # => "The-_config.yml file"
|
184
|
+
#
|
185
|
+
# slugify("The _config.yml file", "ascii")
|
186
|
+
# # => "the-config.yml-file"
|
187
|
+
#
|
188
|
+
# Returns the slugified string.
|
189
|
+
def slugify(string, mode: nil, cased: false)
|
190
|
+
mode ||= "default"
|
191
|
+
return nil if string.nil?
|
192
|
+
|
193
|
+
unless SLUGIFY_MODES.include?(mode)
|
194
|
+
return cased ? string : string.downcase
|
195
|
+
end
|
196
|
+
|
197
|
+
# Replace each character sequence with a hyphen
|
198
|
+
re =
|
199
|
+
case mode
|
200
|
+
when "raw"
|
201
|
+
SLUGIFY_RAW_REGEXP
|
202
|
+
when "default"
|
203
|
+
SLUGIFY_DEFAULT_REGEXP
|
204
|
+
when "pretty"
|
205
|
+
# "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL
|
206
|
+
# and is allowed in both extN and NTFS.
|
207
|
+
SLUGIFY_PRETTY_REGEXP
|
208
|
+
when "ascii"
|
209
|
+
# For web servers not being able to handle Unicode, the safe
|
210
|
+
# method is to ditch anything else but latin letters and numeric
|
211
|
+
# digits.
|
212
|
+
SLUGIFY_ASCII_REGEXP
|
213
|
+
end
|
214
|
+
|
215
|
+
# Strip according to the mode
|
216
|
+
slug = string.gsub(re, "-")
|
217
|
+
|
218
|
+
# Remove leading/trailing hyphen
|
219
|
+
slug.gsub!(%r!^\-|\-$!i, "")
|
220
|
+
|
221
|
+
slug.downcase! unless cased
|
222
|
+
slug
|
223
|
+
end
|
224
|
+
|
225
|
+
# Add an appropriate suffix to template so that it matches the specified
|
226
|
+
# permalink style.
|
227
|
+
#
|
228
|
+
# template - permalink template without trailing slash or file extension
|
229
|
+
# permalink_style - permalink style, either built-in or custom
|
230
|
+
#
|
231
|
+
# The returned permalink template will use the same ending style as
|
232
|
+
# specified in permalink_style. For example, if permalink_style contains a
|
233
|
+
# trailing slash (or is :pretty, which indirectly has a trailing slash),
|
234
|
+
# then so will the returned template. If permalink_style has a trailing
|
235
|
+
# ":output_ext" (or is :none, :date, or :ordinal) then so will the returned
|
236
|
+
# template. Otherwise, template will be returned without modification.
|
237
|
+
#
|
238
|
+
# Examples:
|
239
|
+
# add_permalink_suffix("/:basename", :pretty)
|
240
|
+
# # => "/:basename/"
|
241
|
+
#
|
242
|
+
# add_permalink_suffix("/:basename", :date)
|
243
|
+
# # => "/:basename:output_ext"
|
244
|
+
#
|
245
|
+
# add_permalink_suffix("/:basename", "/:year/:month/:title/")
|
246
|
+
# # => "/:basename/"
|
247
|
+
#
|
248
|
+
# add_permalink_suffix("/:basename", "/:year/:month/:title")
|
249
|
+
# # => "/:basename"
|
250
|
+
#
|
251
|
+
# Returns the updated permalink template
|
252
|
+
def add_permalink_suffix(template, permalink_style)
|
253
|
+
template = template.dup
|
254
|
+
|
255
|
+
case permalink_style
|
256
|
+
when :pretty
|
257
|
+
template << "/"
|
258
|
+
when :date, :ordinal, :none
|
259
|
+
template << ":output_ext"
|
260
|
+
else
|
261
|
+
template << "/" if permalink_style.to_s.end_with?("/")
|
262
|
+
template << ":output_ext" if permalink_style.to_s.end_with?(":output_ext")
|
263
|
+
end
|
264
|
+
|
265
|
+
template
|
266
|
+
end
|
267
|
+
|
268
|
+
# Work the same way as Dir.glob but seperating the input into two parts
|
269
|
+
# ('dir' + '/' + 'pattern') to make sure the first part('dir') does not act
|
270
|
+
# as a pattern.
|
271
|
+
#
|
272
|
+
# For example, Dir.glob("path[/*") always returns an empty array,
|
273
|
+
# because the method fails to find the closing pattern to '[' which is ']'
|
274
|
+
#
|
275
|
+
# Examples:
|
276
|
+
# safe_glob("path[", "*")
|
277
|
+
# # => ["path[/file1", "path[/file2"]
|
278
|
+
#
|
279
|
+
# safe_glob("path", "*", File::FNM_DOTMATCH)
|
280
|
+
# # => ["path/.", "path/..", "path/file1"]
|
281
|
+
#
|
282
|
+
# safe_glob("path", ["**", "*"])
|
283
|
+
# # => ["path[/file1", "path[/folder/file2"]
|
284
|
+
#
|
285
|
+
# dir - the dir where glob will be executed under
|
286
|
+
# (the dir will be included to each result)
|
287
|
+
# patterns - the patterns (or the pattern) which will be applied under the dir
|
288
|
+
# flags - the flags which will be applied to the pattern
|
289
|
+
#
|
290
|
+
# Returns matched pathes
|
291
|
+
def safe_glob(dir, patterns, flags = 0)
|
292
|
+
return [] unless Dir.exist?(dir)
|
293
|
+
pattern = File.join(Array(patterns))
|
294
|
+
return [dir] if pattern.empty?
|
295
|
+
Dir.chdir(dir) do
|
296
|
+
Dir.glob(pattern, flags).map { |f| File.join(dir, f) }
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
# Returns merged option hash for File.read of self.site (if exists)
|
301
|
+
# and a given param
|
302
|
+
def merged_file_read_opts(site, opts)
|
303
|
+
merged = (site ? site.file_read_opts : {}).merge(opts)
|
304
|
+
if merged["encoding"] && !merged["encoding"].start_with?("bom|")
|
305
|
+
merged["encoding"] = "bom|#{merged["encoding"]}"
|
306
|
+
end
|
307
|
+
merged
|
308
|
+
end
|
309
|
+
|
310
|
+
private
|
311
|
+
def merge_values(target, overwrite)
|
312
|
+
target.merge!(overwrite) do |_key, old_val, new_val|
|
313
|
+
if new_val.nil?
|
314
|
+
old_val
|
315
|
+
elsif mergable?(old_val) && mergable?(new_val)
|
316
|
+
deep_merge_hashes(old_val, new_val)
|
317
|
+
else
|
318
|
+
new_val
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
private
|
324
|
+
def merge_default_proc(target, overwrite)
|
325
|
+
if target.is_a?(Hash) && overwrite.is_a?(Hash) && target.default_proc.nil?
|
326
|
+
target.default_proc = overwrite.default_proc
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
private
|
331
|
+
def duplicate_frozen_values(target)
|
332
|
+
target.each do |key, val|
|
333
|
+
target[key] = val.dup if val.frozen? && duplicable?(val)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Jekyll - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Utils
|
7
|
+
module Ansi
|
8
|
+
extend self
|
9
|
+
|
10
|
+
ESCAPE = format("%c", 27)
|
11
|
+
MATCH = %r!#{ESCAPE}\[(?:\d+)(?:;\d+)*(j|k|m|s|u|A|B|G)|\e\(B\e\[m!ix
|
12
|
+
COLORS = {
|
13
|
+
:red => 31,
|
14
|
+
:green => 32,
|
15
|
+
:black => 30,
|
16
|
+
:magenta => 35,
|
17
|
+
:yellow => 33,
|
18
|
+
:white => 37,
|
19
|
+
:blue => 34,
|
20
|
+
:cyan => 36,
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
# Strip ANSI from the current string. It also strips cursor stuff,
|
24
|
+
# well some of it, and it also strips some other stuff that a lot of
|
25
|
+
# the other ANSI strippers don't.
|
26
|
+
|
27
|
+
def strip(str)
|
28
|
+
str.gsub MATCH, ""
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
|
33
|
+
def has?(str)
|
34
|
+
!!(str =~ MATCH)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Reset the color back to the default color so that you do not leak any
|
38
|
+
# colors when you move onto the next line. This is probably normally
|
39
|
+
# used as part of a wrapper so that we don't leak colors.
|
40
|
+
|
41
|
+
def reset(str = "")
|
42
|
+
@ansi_reset ||= format("%c[0m", 27)
|
43
|
+
"#{@ansi_reset}#{str}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# SEE: `self::COLORS` for a list of methods. They are mostly
|
47
|
+
# standard base colors supported by pretty much any xterm-color, we do
|
48
|
+
# not need more than the base colors so we do not include them.
|
49
|
+
# Actually... if I'm honest we don't even need most of the
|
50
|
+
# base colors.
|
51
|
+
|
52
|
+
COLORS.each do |color, num|
|
53
|
+
define_method color do |str|
|
54
|
+
"#{format("%c", 27)}[#{num}m#{str}#{reset}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Utils
|
7
|
+
module Exec
|
8
|
+
extend self
|
9
|
+
|
10
|
+
# Runs a program in a sub-shell.
|
11
|
+
#
|
12
|
+
# *args - a list of strings containing the program name and arguments
|
13
|
+
#
|
14
|
+
# Returns a Process::Status and a String of output in an array in
|
15
|
+
# that order.
|
16
|
+
def run(*args)
|
17
|
+
stdin, stdout, stderr, process = Open3.popen3(*args)
|
18
|
+
out = stdout.read.strip
|
19
|
+
err = stderr.read.strip
|
20
|
+
|
21
|
+
[stdin, stdout, stderr].each(&:close)
|
22
|
+
[process.value, out + err]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Utils
|
5
|
+
module Platforms
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Provides jruby? and mri? which respectively detect these two types of
|
9
|
+
# tested Engines we support, in the future we might probably support the
|
10
|
+
# other one that everyone used to talk about.
|
11
|
+
|
12
|
+
{ :jruby? => "jruby", :mri? => "ruby" }.each do |k, v|
|
13
|
+
define_method k do
|
14
|
+
::RUBY_ENGINE == v
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# --
|
19
|
+
# Allows you to detect "real" Windows, or what we would consider
|
20
|
+
# "real" Windows. That is, that we can pass the basic test and the
|
21
|
+
# /proc/version returns nothing to us.
|
22
|
+
# --
|
23
|
+
|
24
|
+
def vanilla_windows?
|
25
|
+
RbConfig::CONFIG["host_os"] =~ %r!mswin|mingw|cygwin!i && \
|
26
|
+
!proc_version
|
27
|
+
end
|
28
|
+
|
29
|
+
# --
|
30
|
+
# XXX: Remove in 4.0
|
31
|
+
# --
|
32
|
+
|
33
|
+
alias_method :really_windows?, \
|
34
|
+
:vanilla_windows?
|
35
|
+
|
36
|
+
#
|
37
|
+
|
38
|
+
def bash_on_windows?
|
39
|
+
RbConfig::CONFIG["host_os"] =~ %r!linux! && \
|
40
|
+
proc_version =~ %r!microsoft!i
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
|
45
|
+
def windows?
|
46
|
+
vanilla_windows? || bash_on_windows?
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
|
51
|
+
def linux?
|
52
|
+
RbConfig::CONFIG["host_os"] =~ %r!linux! && \
|
53
|
+
proc_version !~ %r!microsoft!i
|
54
|
+
end
|
55
|
+
|
56
|
+
# Provides windows?, linux?, osx?, unix? so that we can detect
|
57
|
+
# platforms. This is mostly useful for `jekyll doctor` and for testing
|
58
|
+
# where we kick off certain tests based on the platform.
|
59
|
+
|
60
|
+
{ :osx? => %r!darwin|mac os!, :unix? => %r!solaris|bsd! }.each do |k, v|
|
61
|
+
define_method k do
|
62
|
+
!!(
|
63
|
+
RbConfig::CONFIG["host_os"] =~ v
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
|
70
|
+
private
|
71
|
+
def proc_version
|
72
|
+
@cached_proc_version ||= begin
|
73
|
+
Pathutil.new(
|
74
|
+
"/proc/version"
|
75
|
+
).read
|
76
|
+
rescue Errno::ENOENT
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|