mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Compare commits
6 Commits
cache-incl
...
v1.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa5c98d281 | ||
|
|
eb54b7f90d | ||
|
|
e92b67dfb9 | ||
|
|
3a870fd09e | ||
|
|
3607ac5e5f | ||
|
|
ca95e75976 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -13,5 +13,3 @@ site/_site/
|
||||
coverage
|
||||
.ruby-version
|
||||
.sass-cache
|
||||
tmp/stackprof-*
|
||||
.jekyll-metadata
|
||||
|
||||
25
.travis.yml
25
.travis.yml
@@ -1,26 +1,23 @@
|
||||
language: ruby
|
||||
cache: bundler
|
||||
sudo: false
|
||||
before_install:
|
||||
- gem install bundler
|
||||
rvm:
|
||||
- 2.2
|
||||
- 2.1
|
||||
- 2.0
|
||||
env:
|
||||
matrix:
|
||||
- TEST_SUITE=test
|
||||
- TEST_SUITE=cucumber
|
||||
before_script: bundle update
|
||||
script: script/cibuild
|
||||
- 2.0.0
|
||||
- 1.9.3
|
||||
- 1.9.2
|
||||
- 1.8.7
|
||||
script: bundle exec rake
|
||||
notifications:
|
||||
irc:
|
||||
on_success: change
|
||||
on_failure: change
|
||||
channels:
|
||||
- irc.freenode.org#jekyll
|
||||
- "irc.freenode.org#jekyll"
|
||||
#on_success: change
|
||||
#on_failure: change
|
||||
template:
|
||||
- "%{repository}#%{build_number} (%{branch}) %{message} %{build_url}"
|
||||
- "%{repository}#%{build_number} (%{branch}) %{message} %{build_url}"
|
||||
email:
|
||||
on_success: never
|
||||
on_failure: never
|
||||
slack:
|
||||
secure: dNdKk6nahNURIUbO3ULhA09/vTEQjK0fNbgjVjeYPEvROHgQBP1cIP3AJy8aWs8rl5Yyow4YGEilNRzKPz18AsFptVXofpwyqcBxaCfmHP809NX5PHBaadydveLm+TNVao2XeLXSWu+HUNAYO1AanCUbJSEyJTju347xCBGzESU=
|
||||
|
||||
@@ -4,11 +4,11 @@ Contribute
|
||||
So you've got an awesome idea to throw into Jekyll. Great! Please keep the
|
||||
following in mind:
|
||||
|
||||
* **Contributions will not be accepted without tests or necessary documentation updates.**
|
||||
* **Contributions will not be accepted without tests.**
|
||||
* If you're creating a small fix or patch to an existing feature, just a simple
|
||||
test will do. Please stay in the confines of the current test suite and use
|
||||
[Shoulda](https://github.com/thoughtbot/shoulda/tree/master) and
|
||||
[RR](https://github.com/rr/rr).
|
||||
[Shoulda](http://github.com/thoughtbot/shoulda/tree/master) and
|
||||
[RR](http://github.com/btakita/rr/tree/master).
|
||||
* If it's a brand new feature, make sure to create a new
|
||||
[Cucumber](https://github.com/cucumber/cucumber/) feature and reuse steps
|
||||
where appropriate. Also, whipping up some documentation in your fork's `site`
|
||||
@@ -53,7 +53,7 @@ Here's the most direct way to get your work merged into the project:
|
||||
* Make sure everything still passes by running `rake`.
|
||||
* If necessary, rebase your commits into logical chunks, without errors.
|
||||
* Push the branch up ( `git push origin my_awesome_feature` ).
|
||||
* Create a pull request against jekyll/jekyll and describe what your change
|
||||
* Create a pull request against mojombo/jekyll and describe what your change
|
||||
does and the why you think it should be merged.
|
||||
|
||||
Updating Documentation
|
||||
@@ -63,14 +63,14 @@ We want the Jekyll documentation to be the best it can be. We've
|
||||
open-sourced our docs and we welcome any pull requests if you find it
|
||||
lacking.
|
||||
|
||||
You can find the documentation for jekyllrb.com in the
|
||||
[site](https://github.com/jekyll/jekyll/tree/master/site) directory of
|
||||
You can find the documentation for jekyllrb.com in the
|
||||
[site](https://github.com/mojombo/jekyll/tree/master/site) directory of
|
||||
Jekyll's repo on GitHub.com.
|
||||
|
||||
All documentation pull requests should be directed at `master`. Pull
|
||||
requests directed at another branch will not be accepted.
|
||||
requests directed at another branch will not be accepted.
|
||||
|
||||
The [Jekyll wiki](https://github.com/jekyll/jekyll/wiki) on GitHub
|
||||
The [Jekyll wiki](https://github.com/mojombo/jekyll/wiki) on GitHub
|
||||
can be freely updated without a pull request as all GitHub users have access.
|
||||
|
||||
Gotchas
|
||||
@@ -78,7 +78,7 @@ Gotchas
|
||||
|
||||
* If you want to bump the gem version, please put that in a separate commit.
|
||||
This way, the maintainers can control when the gem gets released.
|
||||
* Try to keep your patch(es) based from the latest commit on jekyll/jekyll.
|
||||
* Try to keep your patch(es) based from the latest commit on mojombo/jekyll.
|
||||
The easier it is to apply your work, the less work the maintainers have to do,
|
||||
which is always a good thing.
|
||||
* Please don't tag your GitHub issue with [fix], [feature], etc. The maintainers
|
||||
|
||||
27
Gemfile
27
Gemfile
@@ -1,29 +1,2 @@
|
||||
source 'https://rubygems.org'
|
||||
gemspec
|
||||
|
||||
gem 'rake', '~> 10.1'
|
||||
gem 'rdoc', '~> 3.11'
|
||||
gem 'redgreen', '~> 1.2'
|
||||
gem 'shoulda', '~> 3.5'
|
||||
gem 'rr', '~> 1.1'
|
||||
gem 'cucumber', '1.3.18'
|
||||
gem 'RedCloth', '~> 4.2'
|
||||
gem 'maruku', '~> 0.7.0'
|
||||
gem 'rdiscount', '~> 1.6'
|
||||
gem 'launchy', '~> 2.3'
|
||||
gem 'simplecov', '~> 0.9'
|
||||
gem 'simplecov-gem-adapter', '~> 1.0.1'
|
||||
gem 'mime-types', '~> 1.5'
|
||||
gem 'activesupport', '~> 3.2.13'
|
||||
gem 'jekyll_test_plugin'
|
||||
gem 'jekyll_test_plugin_malicious'
|
||||
gem 'rouge', '~> 1.7'
|
||||
gem 'liquid-c', '~> 0.0.3'
|
||||
gem 'minitest' if RUBY_PLATFORM =~ /cygwin/
|
||||
gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2")
|
||||
|
||||
if ENV['BENCHMARK']
|
||||
gem 'benchmark-ips'
|
||||
gem 'rbtrace'
|
||||
gem 'stackprof'
|
||||
end
|
||||
|
||||
810
History.markdown
810
History.markdown
File diff suppressed because it is too large
Load Diff
10
LICENSE
10
LICENSE
@@ -1,9 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2008-2014 Tom Preston-Werner
|
||||
Copyright (c) 2008 Tom Preston-Werner
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
of this software and associated documentation files (the 'Software'), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
@@ -12,10 +12,10 @@ furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
SOFTWARE.
|
||||
@@ -1,36 +1,56 @@
|
||||
# [Jekyll](http://jekyllrb.com/)
|
||||
# Jekyll
|
||||
|
||||
[](https://rubygems.org/gems/jekyll)
|
||||
[](https://travis-ci.org/jekyll/jekyll)
|
||||
[](https://codeclimate.com/github/jekyll/jekyll)
|
||||
[](https://gemnasium.com/jekyll/jekyll)
|
||||
[](https://hakiri.io/github/jekyll/jekyll/master)
|
||||
[](http://badge.fury.io/rb/jekyll)
|
||||
|
||||
By Tom Preston-Werner, Nick Quaranto, Parker Moore, and many [awesome contributors](https://github.com/jekyll/jekyll/graphs/contributors)!
|
||||
[](https://travis-ci.org/mojombo/jekyll)
|
||||
[](https://codeclimate.com/github/mojombo/jekyll)
|
||||
[](https://gemnasium.com/mojombo/jekyll)
|
||||
[](https://coveralls.io/r/mojombo/jekyll)
|
||||
|
||||
Jekyll is a simple, blog-aware, static site generator perfect for personal, project, or organization sites. Think of it like a file-based CMS, without all the complexity. Jekyll takes your content, renders Markdown and Liquid templates, and spits out a complete, static website ready to be served by Apache, Nginx or another web server. Jekyll is the engine behind [GitHub Pages](http://pages.github.com), which you can use to host sites right from your GitHub repositories.
|
||||
By Tom Preston-Werner, Nick Quaranto, and many awesome contributors!
|
||||
|
||||
## Philosophy
|
||||
|
||||
Jekyll does what you tell it to do — no more, no less. It doesn't try to outsmart users by making bold assumptions, nor does it burden them with needless complexity and configuration. Put simply, Jekyll gets out of your way and allows you to concentrate on what truly matters: your content.
|
||||
Jekyll is a simple, blog aware, static site generator. It takes a template directory (representing the raw form of a website), runs it through Textile or Markdown and Liquid converters, and spits out a complete, static website suitable for serving with Apache or your favorite web server. This is also the engine behind [GitHub Pages](http://pages.github.com), which you can use to host your project's page or blog right here from GitHub.
|
||||
|
||||
## Getting Started
|
||||
|
||||
* [Install](http://jekyllrb.com/docs/installation/) the gem
|
||||
* Read up about its [Usage](http://jekyllrb.com/docs/usage/) and [Configuration](http://jekyllrb.com/docs/configuration/)
|
||||
* Take a gander at some existing [Sites](https://wiki.github.com/jekyll/jekyll/sites)
|
||||
* Take a gander at some existing [Sites](http://wiki.github.com/mojombo/jekyll/sites)
|
||||
* Fork and [Contribute](http://jekyllrb.com/docs/contributing/) your own modifications
|
||||
* Have questions? Check out [`#jekyll` on irc.freenode.net](https://botbot.me/freenode/jekyll/).
|
||||
* Have questions? Check out `#jekyll` on irc.freenode.net.
|
||||
|
||||
## Diving In
|
||||
|
||||
* [Migrate](http://import.jekyllrb.com/docs/home/) from your previous system
|
||||
* [Migrate](http://jekyllrb.com/docs/migrations/) from your previous system
|
||||
* Learn how the [YAML Front Matter](http://jekyllrb.com/docs/frontmatter/) works
|
||||
* Put information on your site with [Variables](http://jekyllrb.com/docs/variables/)
|
||||
* Customize the [Permalinks](http://jekyllrb.com/docs/permalinks/) your posts are generated with
|
||||
* Use the built-in [Liquid Extensions](http://jekyllrb.com/docs/templates/) to make your life easier
|
||||
* Use custom [Plugins](http://jekyllrb.com/docs/plugins/) to generate content specific to your site
|
||||
|
||||
## Runtime Dependencies
|
||||
|
||||
* Commander: Command-line interface constructor (Ruby)
|
||||
* Colorator: Colorizes command line output (Ruby)
|
||||
* Classifier: Generating related posts (Ruby)
|
||||
* Directory Watcher: Auto-regeneration of sites (Ruby)
|
||||
* Liquid: Templating system (Ruby)
|
||||
* Maruku: Default markdown engine (Ruby)
|
||||
* Pygments.rb: Syntax highlighting (Ruby/Python)
|
||||
* RedCarpet: Markdown engine (Ruby)
|
||||
* Safe YAML: YAML Parser built for security (Ruby)
|
||||
|
||||
## Developer Dependencies
|
||||
|
||||
* Kramdown: Markdown-superset converter (Ruby)
|
||||
* Launchy: Cross-platform file launcher (Ruby)
|
||||
* RDiscount: Discount Markdown Processor (Ruby)
|
||||
* RedCloth: Textile support (Ruby)
|
||||
* RedGreen: Nicer test output (Ruby)
|
||||
* RR: Mocking (Ruby)
|
||||
* Shoulda: Test framework (Ruby)
|
||||
* SimpleCov: Coverage framework (Ruby)
|
||||
|
||||
## License
|
||||
|
||||
See [LICENSE](https://github.com/jekyll/jekyll/blob/master/LICENSE).
|
||||
See [LICENSE](https://github.com/mojombo/jekyll/blob/master/LICENSE).
|
||||
|
||||
171
Rakefile
171
Rakefile
@@ -5,7 +5,6 @@ require 'date'
|
||||
require 'yaml'
|
||||
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
|
||||
require 'jekyll/version'
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
@@ -14,11 +13,24 @@ require 'jekyll/version'
|
||||
#############################################################################
|
||||
|
||||
def name
|
||||
@name ||= File.basename(Dir['*.gemspec'].first, ".*")
|
||||
@name ||= Dir['*.gemspec'].first.split('.').first
|
||||
end
|
||||
|
||||
def version
|
||||
Jekyll::VERSION
|
||||
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
||||
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
||||
end
|
||||
|
||||
def date
|
||||
Date.today.to_s
|
||||
end
|
||||
|
||||
def file_date
|
||||
Date.today.strftime("%F")
|
||||
end
|
||||
|
||||
def rubyforge_project
|
||||
name
|
||||
end
|
||||
|
||||
def gemspec_file
|
||||
@@ -29,8 +41,12 @@ def gem_file
|
||||
"#{name}-#{version}.gem"
|
||||
end
|
||||
|
||||
def replace_header(head, header_name)
|
||||
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
||||
end
|
||||
|
||||
def normalize_bullets(markdown)
|
||||
markdown.gsub(/\n\s{2}\*{1}/, "\n-")
|
||||
markdown.gsub(/\s{2}\*{1}/, "-")
|
||||
end
|
||||
|
||||
def linkify_prs(markdown)
|
||||
@@ -53,32 +69,13 @@ def liquid_escape(markdown)
|
||||
markdown.gsub(/(`{[{%].+[}%]}`)/, "{% raw %}\\1{% endraw %}")
|
||||
end
|
||||
|
||||
def custom_release_header_anchors(markdown)
|
||||
header_regexp = /^(\d{1,2})\.(\d{1,2})\.(\d{1,2}) \/ \d{4}-\d{2}-\d{2}/
|
||||
section_regexp = /^### \w+ \w+$/
|
||||
markdown.split(/^##\s/).map do |release_notes|
|
||||
_, major, minor, patch = *release_notes.match(header_regexp)
|
||||
release_notes
|
||||
.gsub(header_regexp, "\\0\n{: #v\\1-\\2-\\3}")
|
||||
.gsub(section_regexp) { |section| "#{section}\n{: ##{sluffigy(section)}-v#{major}-#{minor}-#{patch}}" }
|
||||
end.join("\n## ")
|
||||
end
|
||||
|
||||
def sluffigy(header)
|
||||
header.gsub(/#/, '').strip.downcase.gsub(/\s+/, '-')
|
||||
end
|
||||
|
||||
def remove_head_from_history(markdown)
|
||||
index = markdown =~ /^##\s+\d+\.\d+\.\d+/
|
||||
markdown[index..-1]
|
||||
end
|
||||
|
||||
def converted_history(markdown)
|
||||
remove_head_from_history(
|
||||
custom_release_header_anchors(
|
||||
liquid_escape(
|
||||
linkify(
|
||||
normalize_bullets(markdown)))))
|
||||
remove_head_from_history(liquid_escape(linkify(normalize_bullets(markdown))))
|
||||
end
|
||||
|
||||
#############################################################################
|
||||
@@ -87,7 +84,14 @@ end
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
multitask :default => [:test, :features]
|
||||
if RUBY_VERSION > '1.9' && ENV["TRAVIS"] == "true"
|
||||
require 'coveralls/rake/task'
|
||||
Coveralls::RakeTask.new
|
||||
|
||||
task :default => [:test, :features, 'coveralls:push']
|
||||
else
|
||||
task :default => [:test, :features]
|
||||
end
|
||||
|
||||
require 'rake/testtask'
|
||||
Rake::TestTask.new(:test) do |test|
|
||||
@@ -134,7 +138,6 @@ namespace :site do
|
||||
desc "Generate and view the site locally"
|
||||
task :preview do
|
||||
require "launchy"
|
||||
require "jekyll"
|
||||
|
||||
# Yep, it's a hack! Wait a few seconds for the Jekyll site to generate and
|
||||
# then open it in a browser. Someday we can do better than this, I hope.
|
||||
@@ -146,83 +149,50 @@ namespace :site do
|
||||
|
||||
# Generate the site in server mode.
|
||||
puts "Running Jekyll..."
|
||||
options = {
|
||||
"source" => File.expand_path("site"),
|
||||
"destination" => File.expand_path("site/_site"),
|
||||
"watch" => true,
|
||||
"serving" => true
|
||||
}
|
||||
Jekyll::Commands::Build.process(options)
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
||||
|
||||
desc "Generate the site"
|
||||
task :generate => [:history, :version_file] do
|
||||
require "jekyll"
|
||||
Jekyll::Commands::Build.process({
|
||||
"source" => File.expand_path("site"),
|
||||
"destination" => File.expand_path("site/_site")
|
||||
})
|
||||
Dir.chdir("site") do
|
||||
sh "#{File.expand_path('bin/jekyll', File.dirname(__FILE__))} serve --watch"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Update normalize.css library to the latest version and minify"
|
||||
task :update_normalize_css do
|
||||
Dir.chdir("site/_sass") do
|
||||
Dir.chdir("site/css") do
|
||||
sh 'curl "http://necolas.github.io/normalize.css/latest/normalize.css" -o "normalize.scss"'
|
||||
sh 'sass "normalize.scss":"_normalize.scss" --style compressed'
|
||||
rm ['normalize.scss', Dir.glob('*.map')].flatten
|
||||
sh 'sass "normalize.scss":"normalize.css" --style compressed'
|
||||
sh 'rm "normalize.scss"'
|
||||
end
|
||||
end
|
||||
|
||||
desc "Commit the local site to the gh-pages branch and publish to GitHub Pages"
|
||||
task :publish => [:history, :version_file] do
|
||||
task :publish => [:history] do
|
||||
# Ensure the gh-pages dir exists so we can generate into it.
|
||||
puts "Checking for gh-pages dir..."
|
||||
unless File.exist?("./gh-pages")
|
||||
puts "Creating gh-pages dir..."
|
||||
sh "git clone git@github.com:jekyll/jekyll gh-pages"
|
||||
puts "No gh-pages directory found. Run the following commands first:"
|
||||
puts " `git clone git@github.com:mojombo/jekyll gh-pages"
|
||||
puts " `cd gh-pages"
|
||||
puts " `git checkout gh-pages`"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# Ensure latest gh-pages branch history.
|
||||
# Ensure gh-pages branch is up to date.
|
||||
Dir.chdir('gh-pages') do
|
||||
sh "git checkout gh-pages"
|
||||
sh "git pull origin gh-pages"
|
||||
end
|
||||
|
||||
# Proceed to purge all files in case we removed a file in this release.
|
||||
puts "Cleaning gh-pages directory..."
|
||||
purge_exclude = %w[
|
||||
gh-pages/.
|
||||
gh-pages/..
|
||||
gh-pages/.git
|
||||
]
|
||||
FileList["gh-pages/{*,.*}"].exclude(*purge_exclude).each do |path|
|
||||
sh "rm -rf #{path}"
|
||||
end
|
||||
|
||||
# Copy site to gh-pages dir.
|
||||
# Copy to gh-pages dir.
|
||||
puts "Copying site to gh-pages branch..."
|
||||
copy_exclude = %w[
|
||||
site/.
|
||||
site/..
|
||||
site/.jekyll-metadata
|
||||
site/_site
|
||||
]
|
||||
FileList["site/{*,.*}"].exclude(*copy_exclude).each do |path|
|
||||
Dir.glob("site/*") do |path|
|
||||
next if path.include? "_site"
|
||||
sh "cp -R #{path} gh-pages/"
|
||||
end
|
||||
|
||||
# Change any configuration settings for production.
|
||||
config = YAML.load_file("gh-pages/_config.yml")
|
||||
config.merge!({'sass' => {'style' => 'compressed'}})
|
||||
File.write('gh-pages/_config.yml', YAML.dump(config))
|
||||
|
||||
# Commit and push.
|
||||
puts "Committing and pushing to GitHub Pages..."
|
||||
sha = `git log`.match(/[a-z0-9]{40}/)[0]
|
||||
Dir.chdir('gh-pages') do
|
||||
sh "git add ."
|
||||
sh "git commit --allow-empty -m 'Updating to #{sha}.'"
|
||||
sh "git commit -m 'Updating to #{sha}.'"
|
||||
sh "git push origin gh-pages"
|
||||
end
|
||||
puts 'Done.'
|
||||
@@ -238,7 +208,7 @@ namespace :site do
|
||||
"permalink" => "/docs/history/",
|
||||
"prev_section" => "contributing"
|
||||
}
|
||||
Dir.chdir('site/_docs/') do
|
||||
Dir.chdir('site/docs/') do
|
||||
File.open("history.md", "w") do |file|
|
||||
file.write("#{front_matter.to_yaml}---\n\n")
|
||||
file.write(converted_history(history_file))
|
||||
@@ -249,11 +219,6 @@ namespace :site do
|
||||
end
|
||||
end
|
||||
|
||||
desc "Write the site latest_version.txt file"
|
||||
task :version_file do
|
||||
File.open('site/latest_version.txt', 'wb') { |f| f.write(version) }
|
||||
end
|
||||
|
||||
namespace :releases do
|
||||
desc "Create new release post"
|
||||
task :new, :version do |t, args|
|
||||
@@ -268,7 +233,7 @@ namespace :site do
|
||||
post.puts("title: 'Jekyll #{release} Released'")
|
||||
post.puts("date: #{Time.new.strftime('%Y-%m-%d %H:%M:%S %z')}")
|
||||
post.puts("author: ")
|
||||
post.puts("version: #{release}")
|
||||
post.puts("version: #{version}")
|
||||
post.puts("categories: [release]")
|
||||
post.puts("---")
|
||||
post.puts
|
||||
@@ -286,22 +251,48 @@ end
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
desc "Release #{name} v#{version}"
|
||||
task :release => :build do
|
||||
unless `git branch` =~ /^\* master$/
|
||||
puts "You must be on the master branch to release!"
|
||||
unless `git branch` =~ /^(\* master|\* v1-stable)$/
|
||||
puts "You must be on the master branch or the v1-stable branch to release!"
|
||||
exit!
|
||||
end
|
||||
sh "git commit --allow-empty -m 'Release :gem: #{version}'"
|
||||
sh "git commit --allow-empty -m 'Release #{version}'"
|
||||
sh "git tag v#{version}"
|
||||
sh "git push origin master"
|
||||
sh "git push origin v#{version}"
|
||||
sh "gem push pkg/#{name}-#{version}.gem"
|
||||
end
|
||||
|
||||
desc "Build #{name} v#{version} into pkg/"
|
||||
task :build do
|
||||
mkdir_p "pkg"
|
||||
task :build => :gemspec do
|
||||
sh "mkdir -p pkg"
|
||||
sh "gem build #{gemspec_file}"
|
||||
sh "mv #{gem_file} pkg"
|
||||
end
|
||||
|
||||
task :gemspec do
|
||||
# read spec file and split out manifest section
|
||||
spec = File.read(gemspec_file)
|
||||
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
||||
|
||||
# replace name version and date
|
||||
replace_header(head, :name)
|
||||
replace_header(head, :version)
|
||||
replace_header(head, :date)
|
||||
#comment this out if your rubyforge_project has a different name
|
||||
replace_header(head, :rubyforge_project)
|
||||
|
||||
# determine file list from git ls-files
|
||||
files = `git ls-files`.
|
||||
split("\n").
|
||||
sort.
|
||||
reject { |file| file =~ /^\./ }.
|
||||
reject { |file| file =~ /^(rdoc|pkg|coverage)/ }.
|
||||
map { |file| " #{file}" }.
|
||||
join("\n")
|
||||
|
||||
# piece file back together and write
|
||||
manifest = " s.files = %w[\n#{files}\n ]\n"
|
||||
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
||||
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
||||
puts "Updated #{gemspec_file}"
|
||||
end
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
require 'jekyll'
|
||||
|
||||
site = Jekyll::Site.new(Jekyll.configuration({
|
||||
'source' => File.expand_path('../site', __dir__),
|
||||
'destination' => File.expand_path('../site/_site', __dir__)
|
||||
}))
|
||||
payload = Jekyll::Utils.deep_merge_hashes(
|
||||
site.site_payload,
|
||||
{ 'site' => {'page' => site.pages.first.to_liquid } }
|
||||
)
|
||||
info = {
|
||||
filters: [Jekyll::Filters],
|
||||
registers: { :site => site, :page => payload['page'] }
|
||||
}
|
||||
|
||||
class WithoutCacheInclude < Jekyll::Tags::IncludeTag
|
||||
def source(file, context)
|
||||
File.read(file, file_read_opts(context))
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('include_woc', WithoutCacheInclude)
|
||||
|
||||
def parse(tag, payload, info)
|
||||
Liquid::Template.parse("{% #{tag} footer.html %}").render!(payload, info)
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('cached') { parse 'include', payload, info }
|
||||
x.report('uncached') { parse 'include_woc', payload, info }
|
||||
end
|
||||
@@ -1,17 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
enum = (0..50).to_a
|
||||
nested = enum.map { |i| [i] }
|
||||
|
||||
def do_thing(blah)
|
||||
blah * 1
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('.map.flatten with nested arrays') { nested.map { |i| do_thing(i) }.flatten(1) }
|
||||
x.report('.flat_map with nested arrays') { nested.flat_map { |i| do_thing(i) } }
|
||||
|
||||
x.report('.map.flatten with no nested arrays') { enum.map { |i| do_thing(i) }.flatten(1) }
|
||||
x.report('.flat_map with no nested arrays') { enum.flat_map { |i| do_thing(i) } }
|
||||
end
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
h = {:bar => 'uco'}
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('fetch with no block') { h.fetch(:bar, (0..9).to_a) }
|
||||
x.report('fetch with a block') { h.fetch(:bar) { (0..9).to_a } }
|
||||
x.report('brackets with an ||') { h[:bar] || (0..9).to_a }
|
||||
end
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative '../lib/jekyll'
|
||||
require 'benchmark/ips'
|
||||
|
||||
base_directory = Dir.pwd
|
||||
|
||||
Benchmark.ips do |x|
|
||||
#
|
||||
# Does not include the base_directory
|
||||
#
|
||||
x.report('with no questionable path') do
|
||||
Jekyll.sanitized_path(base_directory, '')
|
||||
end
|
||||
x.report('with a single-part questionable path') do
|
||||
Jekyll.sanitized_path(base_directory, 'thingy')
|
||||
end
|
||||
x.report('with a multi-part questionable path') do
|
||||
Jekyll.sanitized_path(base_directory, 'thingy/in/my/soup')
|
||||
end
|
||||
x.report('with a single-part traversal path') do
|
||||
Jekyll.sanitized_path(base_directory, '../thingy')
|
||||
end
|
||||
x.report('with a multi-part traversal path') do
|
||||
Jekyll.sanitized_path(base_directory, '../thingy/in/my/../../soup')
|
||||
end
|
||||
|
||||
#
|
||||
# Including the base_directory
|
||||
#
|
||||
x.report('with the exact same paths') do
|
||||
Jekyll.sanitized_path(base_directory, base_directory)
|
||||
end
|
||||
x.report('with a single-part absolute path including the base_directory') do
|
||||
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy'))
|
||||
end
|
||||
x.report('with a multi-part absolute path including the base_directory') do
|
||||
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/in/my/soup'))
|
||||
end
|
||||
x.report('with a single-part traversal path including the base_directory') do
|
||||
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/..'))
|
||||
end
|
||||
x.report('with a multi-part traversal path including the base_directory') do
|
||||
Jekyll.sanitized_path(base_directory, File.join('thingy/in/my/../../soup'))
|
||||
end
|
||||
end
|
||||
@@ -1,14 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
def fast
|
||||
yield
|
||||
end
|
||||
|
||||
def slow(&block)
|
||||
block.call
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('yield') { fast { (0..9).to_a } }
|
||||
x.report('block.call') { slow { (0..9).to_a } }
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('parallel assignment') do
|
||||
a, b = 1, 2
|
||||
end
|
||||
x.report('multi-line assignment') do
|
||||
a = 1
|
||||
b = 2
|
||||
end
|
||||
end
|
||||
@@ -1,8 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
url = "http://jekyllrb.com"
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('+=') { url += '/' }
|
||||
x.report('<<') { url << '/' }
|
||||
end
|
||||
@@ -1,13 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
def str
|
||||
'http://baruco.org/2014/some-talk-with-some-amount-of-value'
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('#tr') { str.tr('some', 'a') }
|
||||
x.report('#gsub') { str.gsub('some', 'a') }
|
||||
x.report('#gsub!') { str.gsub!('some', 'a') }
|
||||
x.report('#sub') { str.sub('some', 'a') }
|
||||
x.report('#sub!') { str.sub!('some', 'a') }
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
require 'benchmark/ips'
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('block') { (1..100).map { |i| i.to_s } }
|
||||
x.report('&:to_s') { (1..100).map(&:to_s) }
|
||||
end
|
||||
164
bin/jekyll
164
bin/jekyll
@@ -3,38 +3,156 @@ STDOUT.sync = true
|
||||
|
||||
$:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
|
||||
|
||||
require 'commander/import'
|
||||
require 'jekyll'
|
||||
require 'mercenary'
|
||||
|
||||
Jekyll::External.require_if_present(
|
||||
Jekyll::External.blessed_gems
|
||||
)
|
||||
|
||||
Jekyll::PluginManager.require_from_bundler
|
||||
|
||||
Jekyll::Deprecator.process(ARGV)
|
||||
|
||||
Mercenary.program(:jekyll) do |p|
|
||||
p.version Jekyll::VERSION
|
||||
p.description 'Jekyll is a blog-aware, static site generator in Ruby'
|
||||
p.syntax 'jekyll <subcommand> [options]'
|
||||
program :name, 'jekyll'
|
||||
program :version, Jekyll::VERSION
|
||||
program :description, 'Jekyll is a blog-aware, static site generator in Ruby'
|
||||
|
||||
p.option 'source', '-s', '--source [DIR]', 'Source directory (defaults to ./)'
|
||||
p.option 'destination', '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)'
|
||||
p.option 'safe', '--safe', 'Safe mode (defaults to false)'
|
||||
p.option 'plugins', '-p', '--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]', Array, 'Plugins directory (defaults to ./_plugins)'
|
||||
p.option 'layouts', '--layouts DIR', String, 'Layouts directory (defaults to ./_layouts)'
|
||||
default_command :default
|
||||
|
||||
Jekyll::Command.subclasses.each { |c| c.init_with_program(p) }
|
||||
global_option '-s', '--source [DIR]', 'Source directory (defaults to ./)'
|
||||
global_option '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)'
|
||||
global_option '--safe', 'Safe mode (defaults to false)'
|
||||
global_option '-p', '--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]', Array, 'Plugins directory (defaults to ./_plugins)'
|
||||
global_option '--layouts DIR', String, 'Layouts directory (defaults to ./_layouts)'
|
||||
|
||||
p.action do |args, options|
|
||||
# Option names don't always directly match the configuration value we'd like.
|
||||
# This method will rename options to match what Jekyll configuration expects.
|
||||
#
|
||||
# options - The Hash of options from Commander.
|
||||
#
|
||||
# Returns the normalized Hash.
|
||||
def normalize_options(options)
|
||||
if drafts_state = options.delete(:drafts)
|
||||
options[:show_drafts] = drafts_state
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
def add_build_options(c)
|
||||
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||
c.option '--future', 'Publishes posts with a future date'
|
||||
c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
|
||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||
c.option '--lsi', 'Use LSI for improved related posts'
|
||||
c.option '-D', '--drafts', 'Render posts in the _drafts folder'
|
||||
c.option '-V', '--verbose', 'Print verbose output.'
|
||||
end
|
||||
|
||||
command :default do |c|
|
||||
c.action do |args, options|
|
||||
if args.empty?
|
||||
Jekyll.logger.error "A subcommand is required."
|
||||
puts p
|
||||
command(:help).run
|
||||
else
|
||||
unless p.has_command?(args.first)
|
||||
Jekyll.logger.abort_with "Invalid command. Use --help for more information"
|
||||
end
|
||||
Jekyll.logger.abort_with "Invalid command. Use --help for more information"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
command :new do |c|
|
||||
c.syntax = 'jekyll new PATH'
|
||||
c.description = 'Creates a new Jekyll site scaffold in PATH'
|
||||
|
||||
c.option '--force', 'Force creation even if PATH already exists'
|
||||
c.option '--blank', 'Creates scaffolding but with empty files'
|
||||
|
||||
c.action do |args, options|
|
||||
Jekyll::Commands::New.process(args, options.__hash__)
|
||||
end
|
||||
end
|
||||
|
||||
command :build do |c|
|
||||
c.syntax = 'jekyll build [options]'
|
||||
c.description = 'Build your site'
|
||||
|
||||
add_build_options(c)
|
||||
|
||||
c.action do |args, options|
|
||||
options = normalize_options(options.__hash__)
|
||||
options = Jekyll.configuration(options)
|
||||
Jekyll::Commands::Build.process(options)
|
||||
end
|
||||
end
|
||||
|
||||
command :serve do |c|
|
||||
c.syntax = 'jekyll serve [options]'
|
||||
c.description = 'Serve your site locally'
|
||||
|
||||
add_build_options(c)
|
||||
|
||||
c.option '-B', '--detach', 'Run the server in the background (detach)'
|
||||
c.option '-P', '--port [PORT]', 'Port to listen on'
|
||||
c.option '-H', '--host [HOST]', 'Host to bind to'
|
||||
c.option '-b', '--baseurl [URL]', 'Base URL'
|
||||
|
||||
c.action do |args, options|
|
||||
options.default :serving => true
|
||||
|
||||
options = normalize_options(options.__hash__)
|
||||
options = Jekyll.configuration(options)
|
||||
Jekyll::Commands::Build.process(options)
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
||||
end
|
||||
alias_command :server, :serve
|
||||
|
||||
command :doctor do |c|
|
||||
c.syntax = 'jekyll doctor'
|
||||
c.description = 'Search site and print specific deprecation warnings'
|
||||
|
||||
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||
|
||||
c.action do |args, options|
|
||||
options = normalize_options(options.__hash__)
|
||||
options = Jekyll.configuration(options)
|
||||
Jekyll::Commands::Doctor.process(options)
|
||||
end
|
||||
end
|
||||
alias_command :hyde, :doctor
|
||||
|
||||
command :docs do |c|
|
||||
c.syntax = 'jekyll docs'
|
||||
c.description = "Launch local server with docs for Jekyll v#{Jekyll::VERSION}"
|
||||
|
||||
c.option '-p', '--port [PORT]', 'Port to listen on'
|
||||
c.option '-u', '--host [HOST]', 'Host to bind to'
|
||||
|
||||
c.action do |args, options|
|
||||
options = normalize_options(options.__hash__)
|
||||
options = Jekyll.configuration(options.merge!({
|
||||
'source' => File.expand_path("../site", File.dirname(__FILE__)),
|
||||
'destination' => File.expand_path("../site/_site", File.dirname(__FILE__))
|
||||
}))
|
||||
puts options
|
||||
Jekyll::Commands::Build.process(options)
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
||||
end
|
||||
|
||||
command :import do |c|
|
||||
c.syntax = 'jekyll import <platform> [options]'
|
||||
c.description = 'Import your old blog to Jekyll'
|
||||
|
||||
c.option '--source STRING', 'Source file or URL to migrate from'
|
||||
c.option '--file STRING', 'File to migrate from'
|
||||
c.option '--dbname STRING', 'Database name to migrate from'
|
||||
c.option '--user STRING', 'Username to use when migrating'
|
||||
c.option '--pass STRING', 'Password to use when migrating'
|
||||
c.option '--host STRING', 'Host address to use when migrating'
|
||||
c.option '--prefix STRING', 'Database table prefix to use when migrating'
|
||||
|
||||
c.action do |args, options|
|
||||
begin
|
||||
require 'jekyll-import'
|
||||
rescue LoadError
|
||||
msg = "You must install the 'jekyll-import' gem before continuing.\n"
|
||||
msg += "* Please see the documentation at http://jekyllrb.com/docs/migrations/ for instructions.\n"
|
||||
abort msg
|
||||
end
|
||||
Jekyll::Commands::Import.process(args.first, options)
|
||||
end
|
||||
end
|
||||
|
||||
3
cucumber.yml
Normal file
3
cucumber.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
default: --format pretty
|
||||
travis: --format progress
|
||||
html_report: --format progress --format html --out=features_report.html
|
||||
@@ -1,145 +0,0 @@
|
||||
Feature: Collections
|
||||
As a hacker who likes to structure content
|
||||
I want to be able to create collections of similar information
|
||||
And render them
|
||||
|
||||
Scenario: Unrendered collection
|
||||
Given I have an "index.html" page that contains "Collections: {{ site.methods }}"
|
||||
And I have fixture collections
|
||||
And I have a configuration file with "collections" set to "['methods']"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: <p>Use <code>Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>\n<p>Signs are nice</p>\n<p><code>Jekyll.sanitized_path</code> is used to make sure your path is in your source.</p>\n<p>Run your generators! default</p>\n<p>Page without title.</p>\n<p>Run your generators! default</p>" in "_site/index.html"
|
||||
And the "_site/methods/configuration.html" file should not exist
|
||||
|
||||
Scenario: Rendered collection
|
||||
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
|
||||
And I have an "collection_metadata.html" page that contains "Methods metadata: {{ site.collections.methods.foo }} {{ site.collections.methods }}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
methods:
|
||||
output: true
|
||||
foo: bar
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: {\"methods" in "_site/index.html"
|
||||
And I should see "Methods metadata: bar" in "_site/collection_metadata.html"
|
||||
And I should see "<p>Whatever: foo.bar</p>" in "_site/methods/configuration.html"
|
||||
|
||||
Scenario: Rendered collection at a custom URL
|
||||
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
methods:
|
||||
output: true
|
||||
permalink: /:collection/:path/
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "<p>Whatever: foo.bar</p>" in "_site/methods/configuration/index.html"
|
||||
|
||||
Scenario: Rendered document in a layout
|
||||
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
|
||||
And I have a default layout that contains "<div class='title'>Tom Preston-Werner</div> {{content}}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
methods:
|
||||
output: true
|
||||
foo: bar
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: {\"methods" in "_site/index.html"
|
||||
And I should see "<p>Run your generators! default</p>" in "_site/methods/site/generate.html"
|
||||
And I should see "<div class='title'>Tom Preston-Werner</div>" in "_site/methods/site/generate.html"
|
||||
|
||||
Scenario: Collections specified as an array
|
||||
Given I have an "index.html" page that contains "Collections: {% for method in site.methods %}{{ method.relative_path }} {% endfor %}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
||||
|
||||
Scenario: Collections specified as an hash
|
||||
Given I have an "index.html" page that contains "Collections: {% for method in site.methods %}{{ method.relative_path }} {% endfor %}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
||||
|
||||
Scenario: All the documents
|
||||
Given I have an "index.html" page that contains "All documents: {% for doc in site.documents %}{{ doc.relative_path }} {% endfor %}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "All documents: _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/um_hi.md" in "_site/index.html"
|
||||
|
||||
Scenario: Documents have an output attribute, which is the converted HTML
|
||||
Given I have an "index.html" page that contains "First document's output: {{ site.documents.first.output }}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "First document's output: <p>Use <code>Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>" in "_site/index.html"
|
||||
|
||||
Scenario: Filter documents by where
|
||||
Given I have an "index.html" page that contains "{% assign items = site.methods | where: 'whatever','foo.bar' %}Item count: {{ items.size }}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Item count: 1" in "_site/index.html"
|
||||
|
||||
Scenario: Sort by title
|
||||
Given I have an "index.html" page that contains "{% assign items = site.methods | sort: 'title' %}1. of {{ items.size }}: {{ items.first.output }}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "1. of 6: <p>Page without title.</p>" in "_site/index.html"
|
||||
|
||||
Scenario: Sort by relative_path
|
||||
Given I have an "index.html" page that contains "Collections: {% assign methods = site.methods | sort: 'relative_path' %}{% for method in methods %}{{ method.title }}, {% endfor %}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
- methods
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: Jekyll.configuration, Jekyll.escape, Jekyll.sanitized_path, Site#generate, , Site#generate," in "_site/index.html"
|
||||
@@ -5,23 +5,23 @@ Feature: Create sites
|
||||
|
||||
Scenario: Blank site
|
||||
Given I do not have a "test_blank" directory
|
||||
When I run jekyll new test_blank --blank
|
||||
When I call jekyll new with test_blank --blank
|
||||
Then the test_blank/_layouts directory should exist
|
||||
And the test_blank/_posts directory should exist
|
||||
And the "test_blank/index.html" file should exist
|
||||
|
||||
Scenario: Basic site
|
||||
Given I have an "index.html" file that contains "Basic Site"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site" in "_site/index.html"
|
||||
|
||||
Scenario: Basic site with a post
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| title | date | content |
|
||||
| Hackers | 2009-03-27 | My First Exploit |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "My First Exploit" in "_site/2009/03/27/hackers.html"
|
||||
|
||||
@@ -29,7 +29,7 @@ Feature: Create sites
|
||||
Given I have a _layouts directory
|
||||
And I have an "index.html" page with layout "default" that contains "Basic Site with Layout"
|
||||
And I have a default layout that contains "Page Layout: {{ content }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: Basic Site with Layout" in "_site/index.html"
|
||||
|
||||
@@ -37,10 +37,10 @@ Feature: Create sites
|
||||
Given I have a _layouts directory
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Wargames | 2009-03-27 | default | The only winning move is not to play. |
|
||||
And I have a default layout that contains "Post Layout: {{ content }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post Layout: <p>The only winning move is not to play.</p>" in "_site/2009/03/27/wargames.html"
|
||||
|
||||
@@ -48,10 +48,10 @@ Feature: Create sites
|
||||
Given I have a _layouts directory
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Wargames | 2009-03-27 | post/simple | The only winning move is not to play. |
|
||||
And I have a post/simple layout that contains "Post Layout: {{ content }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post Layout: <p>The only winning move is not to play.</p>" in "_site/2009/03/27/wargames.html"
|
||||
|
||||
@@ -66,15 +66,15 @@ Feature: Create sites
|
||||
And I have an "another_file" file that contains ""
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2009-03-27 | post | content for entry1. |
|
||||
| entry2 | 2009-04-27 | post | content for entry2. |
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2009-03-27 | post | content for entry1. |
|
||||
| entry2 | 2009-04-27 | post | content for entry2. |
|
||||
And I have a category/_posts directory
|
||||
And I have the following posts in "category":
|
||||
| title | date | layout | content |
|
||||
| entry3 | 2009-05-27 | post | content for entry3. |
|
||||
| entry4 | 2009-06-27 | post | content for entry4. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry3 | 2009-05-27 | post | content for entry3. |
|
||||
| entry4 | 2009-06-27 | post | content for entry4. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page : Site contains 2 pages and 4 posts" in "_site/index.html"
|
||||
And I should see "No replacement \{\{ site.posts.size \}\}" in "_site/about.html"
|
||||
@@ -89,7 +89,7 @@ Feature: Create sites
|
||||
Given I have a _includes directory
|
||||
And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
|
||||
And I have an "_includes/about.textile" file that contains "Generated by Jekyll"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
|
||||
|
||||
@@ -98,7 +98,7 @@ Feature: Create sites
|
||||
And I have an "_includes/about.textile" file that contains "Generated by Jekyll"
|
||||
And I have an info directory
|
||||
And I have an "info/index.html" page that contains "Basic Site with subdir include tag: {% include about.textile %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site with subdir include tag: Generated by Jekyll" in "_site/info/index.html"
|
||||
|
||||
@@ -107,7 +107,7 @@ Feature: Create sites
|
||||
And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}"
|
||||
And I have an "_includes/jekyll.textile" file that contains "Jekyll"
|
||||
And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
|
||||
|
||||
@@ -116,43 +116,26 @@ Feature: Create sites
|
||||
And I have a configuration file with "permalink" set to "pretty"
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "URL: /2020/01/31/entry2/" in "_site/index.html"
|
||||
|
||||
Scenario: Basic site with whitelisted dotfile
|
||||
Given I have an ".htaccess" file that contains "SomeDirective"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "SomeDirective" in "_site/.htaccess"
|
||||
|
||||
Scenario: File was replaced by a directory
|
||||
Given I have a "test" file that contains "some stuff"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
When I delete the file "test"
|
||||
Given I have a test directory
|
||||
And I have a "test/index.html" file that contains "some other stuff"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site/test directory should exist
|
||||
And I should see "some other stuff" in "_site/test/index.html"
|
||||
|
||||
Scenario: Basic site with unpublished page
|
||||
Given I have an "index.html" page with title "index" that contains "Published page"
|
||||
And I have a "public.html" page with published "true" that contains "Explicitly published page"
|
||||
And I have a "secret.html" page with published "false" that contains "Unpublished page"
|
||||
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And the "_site/index.html" file should exist
|
||||
And the "_site/public.html" file should exist
|
||||
But the "_site/secret.html" file should not exist
|
||||
|
||||
When I run jekyll build --unpublished
|
||||
Then the _site directory should exist
|
||||
And the "_site/index.html" file should exist
|
||||
And the "_site/public.html" file should exist
|
||||
And the "_site/secret.html" file should exist
|
||||
|
||||
@@ -13,7 +13,7 @@ Feature: Data
|
||||
price: 2.5
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for product in site.data.products %}{{product.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "sugar" in "_site/index.html"
|
||||
And I should see "salt" in "_site/index.html"
|
||||
@@ -28,33 +28,7 @@ Feature: Data
|
||||
age: 34
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
Scenario: autoload *.json files in _data directory
|
||||
Given I have a _data directory
|
||||
And I have a "_data/members.json" file with content:
|
||||
"""
|
||||
[{"name": "Jack", "age": 28},{"name": "Leon", "age": 34}]
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
Scenario: autoload *.csv files in _data directory
|
||||
Given I have a _data directory
|
||||
And I have a "_data/members.csv" file with content:
|
||||
"""
|
||||
name,age
|
||||
Jack,28
|
||||
Leon,34
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
@@ -69,40 +43,11 @@ Feature: Data
|
||||
age: 34
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data.team_members %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
Scenario: autoload *.yaml files in subdirectories in _data directory
|
||||
Given I have a _data directory
|
||||
And I have a _data/categories directory
|
||||
And I have a "_data/categories/dairy.yaml" file with content:
|
||||
"""
|
||||
name: Dairy Products
|
||||
"""
|
||||
And I have an "index.html" page that contains "{{ site.data.categories.dairy.name }}"
|
||||
When I run jekyll build
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Dairy Products" in "_site/index.html"
|
||||
|
||||
Scenario: folders should have precedence over files with the same name
|
||||
Given I have a _data directory
|
||||
And I have a _data/categories directory
|
||||
And I have a "_data/categories/dairy.yaml" file with content:
|
||||
"""
|
||||
name: Dairy Products
|
||||
"""
|
||||
And I have a "_data/categories.yaml" file with content:
|
||||
"""
|
||||
dairy:
|
||||
name: Should not display this
|
||||
"""
|
||||
And I have an "index.html" page that contains "{{ site.data.categories.dairy.name }}"
|
||||
When I run jekyll build
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Dairy Products" in "_site/index.html"
|
||||
|
||||
Scenario: should be backward compatible with site.data in _config.yml
|
||||
Given I have a "_config.yml" file with content:
|
||||
"""
|
||||
@@ -113,7 +58,8 @@ Feature: Data
|
||||
age: 34
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ Feature: Draft Posts
|
||||
Given I have a configuration file with "permalink" set to "none"
|
||||
And I have a _drafts directory
|
||||
And I have the following draft:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Recipe | 2009-03-27 | default | Not baked yet. |
|
||||
When I run jekyll build --drafts
|
||||
When I run jekyll with drafts
|
||||
Then the _site directory should exist
|
||||
And I should see "Not baked yet." in "_site/recipe.html"
|
||||
|
||||
@@ -18,29 +18,8 @@ Feature: Draft Posts
|
||||
And I have an "index.html" page that contains "Totally index"
|
||||
And I have a _drafts directory
|
||||
And I have the following draft:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Recipe | 2009-03-27 | default | Not baked yet. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the "_site/recipe.html" file should not exist
|
||||
|
||||
Scenario: Don't preview a draft that is not published
|
||||
Given I have a configuration file with "permalink" set to "none"
|
||||
And I have an "index.html" page that contains "Totally index"
|
||||
And I have a _drafts directory
|
||||
And I have the following draft:
|
||||
| title | date | layout | published | content |
|
||||
| Recipe | 2009-03-27 | default | false | Not baked yet. |
|
||||
When I run jekyll build --drafts
|
||||
Then the _site directory should exist
|
||||
And the "_site/recipe.html" file should not exist
|
||||
|
||||
Scenario: Use page.path variable
|
||||
Given I have a configuration file with "permalink" set to "none"
|
||||
And I have a _drafts directory
|
||||
And I have the following draft:
|
||||
| title | date | layout | content |
|
||||
| Recipe | 2009-03-27 | simple | Post path: {{ page.path }} |
|
||||
When I run jekyll build --drafts
|
||||
Then the _site directory should exist
|
||||
And I should see "Post path: _drafts/recipe.textile" in "_site/recipe.html"
|
||||
|
||||
@@ -7,10 +7,10 @@ Feature: Embed filters
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | default | These aren't the droids you're looking for. |
|
||||
And I have a default layout that contains "{{ site.time | date_to_xmlschema }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see today's date in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -18,12 +18,10 @@ Feature: Embed filters
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star & Wars | 2009-03-27 | default | These aren't the droids you're looking for. |
|
||||
|
||||
|
||||
And I have a default layout that contains "{{ page.title | xml_escape }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Star & Wars" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -31,10 +29,10 @@ Feature: Embed filters
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | default | These aren't the droids you're looking for. |
|
||||
And I have a default layout that contains "{{ content | xml_escape }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "7" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -42,10 +40,10 @@ Feature: Embed filters
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | tags | content |
|
||||
| title | date | layout | tags | content |
|
||||
| Star Wars | 2009-03-27 | default | [scifi, movies, force] | These aren't the droids you're looking for. |
|
||||
And I have a default layout that contains "{{ page.tags | array_to_sentence_string }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "scifi, movies, and force" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -53,55 +51,10 @@ Feature: Embed filters
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | default | These aren't the droids you're looking for. |
|
||||
And I have a default layout that contains "By {{ '_Obi-wan_' | textilize }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "By <p><em>Obi-wan</em></p>" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Sort by an arbitrary variable
|
||||
Given I have a _layouts directory
|
||||
And I have the following page:
|
||||
| title | layout | value | content |
|
||||
| Page-1 | default | 8 | Something |
|
||||
And I have the following page:
|
||||
| title | layout | value | content |
|
||||
| Page-2 | default | 6 | Something |
|
||||
And I have a default layout that contains "{{ site.pages | sort:'value' | map:'title' | join:', ' }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see exactly "Page-2, Page-1" in "_site/page-1.html"
|
||||
And I should see exactly "Page-2, Page-1" in "_site/page-2.html"
|
||||
|
||||
Scenario: Sort pages by the title
|
||||
Given I have a _layouts directory
|
||||
And I have the following page:
|
||||
| title | layout | content |
|
||||
| Dog | default | Run |
|
||||
And I have the following page:
|
||||
| title | layout | content |
|
||||
| Bird | default | Fly |
|
||||
And I have the following page:
|
||||
| layout | content |
|
||||
| default | Jump |
|
||||
And I have a default layout that contains "{% assign sorted_pages = site.pages | sort: 'title' %}The rule of {{ sorted_pages.size }}: {% for p in sorted_pages %}{{ p.content | strip_html | strip_newlines }}, {% endfor %}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see exactly "The rule of 3: Jump, Fly, Run," in "_site/bird.html"
|
||||
|
||||
Scenario: Sort pages by the title ordering pages without title last
|
||||
Given I have a _layouts directory
|
||||
And I have the following page:
|
||||
| title | layout | content |
|
||||
| Dog | default | Run |
|
||||
And I have the following page:
|
||||
| title | layout | content |
|
||||
| Bird | default | Fly |
|
||||
And I have the following page:
|
||||
| layout | content |
|
||||
| default | Jump |
|
||||
And I have a default layout that contains "{% assign sorted_pages = site.pages | sort: 'title', 'last' %}The rule of {{ sorted_pages.size }}: {% for p in sorted_pages %}{{ p.content | strip_html | strip_newlines }}, {% endfor %}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see exactly "The rule of 3: Fly, Run, Jump," in "_site/bird.html"
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
Feature: frontmatter defaults
|
||||
Scenario: Use default for frontmatter variables internally
|
||||
Given I have a _layouts directory
|
||||
And I have a pretty layout that contains "THIS IS THE LAYOUT: {{content}}"
|
||||
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| default layout | 2013-09-11 | just some post |
|
||||
And I have an "index.html" page with title "some title" that contains "just some page"
|
||||
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: ""}, values: {layout: "pretty"}}]"
|
||||
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "THIS IS THE LAYOUT: <p>just some post</p>" in "_site/2013/09/11/default-layout.html"
|
||||
And I should see "THIS IS THE LAYOUT: just some page" in "_site/index.html"
|
||||
|
||||
Scenario: Use default for frontmatter variables in Liquid
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| default data | 2013-09-11 | <p>{{page.custom}}</p><div>{{page.author}}</div> |
|
||||
And I have an "index.html" page that contains "just {{page.custom}} by {{page.author}}"
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: ""}, values: {custom: "some special data", author: "Ben"}}]"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "<p>some special data</p><div>Ben</div>" in "_site/2013/09/11/default-data.html"
|
||||
And I should see "just some special data by Ben" in "_site/index.html"
|
||||
|
||||
Scenario: Override frontmatter defaults by path
|
||||
Given I have a _layouts directory
|
||||
And I have a root layout that contains "root: {{ content }}"
|
||||
And I have a subfolder layout that contains "subfolder: {{ content }}"
|
||||
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| about | 2013-10-14 | info on {{page.description}} |
|
||||
And I have a special/_posts directory
|
||||
And I have the following post in "special":
|
||||
| title | date | path | content |
|
||||
| about | 2013-10-14 | local | info on {{page.description}} |
|
||||
|
||||
And I have an "index.html" page with title "overview" that contains "Overview for {{page.description}}"
|
||||
And I have an "special/index.html" page with title "section overview" that contains "Overview for {{page.description}}"
|
||||
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: "special"}, values: {layout: "subfolder", description: "the special section"}}, {scope: {path: ""}, values: {layout: "root", description: "the webpage"}}]"
|
||||
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "root: <p>info on the webpage</p>" in "_site/2013/10/14/about.html"
|
||||
And I should see "subfolder: <p>info on the special section</p>" in "_site/special/2013/10/14/about.html"
|
||||
And I should see "root: Overview for the webpage" in "_site/index.html"
|
||||
And I should see "subfolder: Overview for the special section" in "_site/special/index.html"
|
||||
|
||||
Scenario: Override frontmatter defaults by type
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| this is a post | 2013-10-14 | blabla |
|
||||
And I have an "index.html" page that contains "interesting stuff"
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: "", type: "post"}, values: {permalink: "/post.html"}}, {scope: {path: "", type: "page"}, values: {permalink: "/page.html"}}, {scope: {path: ""}, values: {permalink: "/perma.html"}}]"
|
||||
When I run jekyll build
|
||||
Then I should see "blabla" in "_site/post.html"
|
||||
And I should see "interesting stuff" in "_site/page.html"
|
||||
But the "_site/perma.html" file should not exist
|
||||
|
||||
Scenario: Actual frontmatter overrides defaults
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | permalink | author | content |
|
||||
| override | 2013-10-14 | /frontmatter.html | some guy | a blog by {{page.author}} |
|
||||
And I have an "index.html" page with permalink "override.html" that contains "nothing"
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: ""}, values: {permalink: "/perma.html", author: "Chris"}}]"
|
||||
When I run jekyll build
|
||||
Then I should see "a blog by some guy" in "_site/frontmatter.html"
|
||||
And I should see "nothing" in "_site/override.html"
|
||||
But the "_site/perma.html" file should not exist
|
||||
|
||||
Scenario: Use frontmatter defaults in collections
|
||||
Given I have a _slides directory
|
||||
And I have a "index.html" file that contains "nothing"
|
||||
And I have a "_slides/slide1.html" file with content:
|
||||
"""
|
||||
---
|
||||
---
|
||||
Value: {{ page.myval }}
|
||||
"""
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
slides:
|
||||
output: true
|
||||
defaults:
|
||||
-
|
||||
scope:
|
||||
path: ""
|
||||
type: slides
|
||||
values:
|
||||
myval: "Test"
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Value: Test" in "_site/slides/slide1.html"
|
||||
|
||||
Scenario: Override frontmatter defaults inside a collection
|
||||
Given I have a _slides directory
|
||||
And I have a "index.html" file that contains "nothing"
|
||||
And I have a "_slides/slide2.html" file with content:
|
||||
"""
|
||||
---
|
||||
myval: Override
|
||||
---
|
||||
Value: {{ page.myval }}
|
||||
"""
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
slides:
|
||||
output: true
|
||||
defaults:
|
||||
-
|
||||
scope:
|
||||
path: ""
|
||||
type: slides
|
||||
values:
|
||||
myval: "Test"
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Value: Override" in "_site/slides/slide2.html"
|
||||
|
||||
Scenario: Deep merge frontmatter defaults
|
||||
Given I have an "index.html" page with fruit "{orange: 1}" that contains "Fruits: {{ page.fruit.orange | plus: page.fruit.apple }}"
|
||||
And I have a configuration file with "defaults" set to "[{scope: {path: ""}, values: {fruit: {apple: 2}}}]"
|
||||
When I run jekyll build
|
||||
Then I should see "Fruits: 3" in "_site/index.html"
|
||||
@@ -10,15 +10,15 @@ Feature: Include tags
|
||||
And I have an "_includes/ignore.html" file that contains "<footer>My blog footer</footer>"
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| Include Files | 2013-03-21 | default | {% include header.html param="myparam" %} |
|
||||
| Ignore params if unused | 2013-03-21 | default | {% include ignore.html date="today" %} |
|
||||
| List multiple parameters | 2013-03-21 | default | {% include params.html date="today" start="tomorrow" %} |
|
||||
| Dont keep parameters | 2013-03-21 | default | {% include ignore.html param="test" %}\n{% include header.html %} |
|
||||
| title | date | layout | content |
|
||||
| Include Files | 2013-03-21 | default | {% include header.html param="myparam" %} |
|
||||
| Ignore params if unused | 2013-03-21 | default | {% include ignore.html date="today" %} |
|
||||
| List multiple parameters | 2013-03-21 | default | {% include params.html date="today" start="tomorrow" %} |
|
||||
| Dont keep parameters | 2013-03-21 | default | {% include ignore.html param="test" %}\n{% include header.html %} |
|
||||
| Allow params with spaces and quotes | 2013-04-07 | default | {% include params.html cool="param with spaces" super="\"quoted\"" single='has "quotes"' escaped='\'single\' quotes' %} |
|
||||
| Parameter syntax | 2013-04-12 | default | {% include params.html param1_or_2="value" %} |
|
||||
| Pass a variable | 2013-06-22 | default | {% assign var = 'some text' %}{% include params.html local=var layout=page.layout %} |
|
||||
When I run jekyll build
|
||||
| Parameter syntax | 2013-04-12 | default | {% include params.html param1_or_2="value" %} |
|
||||
| Pass a variable | 2013-06-22 | default | {% assign var = 'some text' %}{% include params.html local=var layout=page.layout %} |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "<header>My awesome blog header: myparam</header>" in "_site/2013/03/21/include-files.html"
|
||||
And I should not see "myparam" in "_site/2013/03/21/ignore-params-if-unused.html"
|
||||
@@ -43,7 +43,7 @@ Feature: Include tags
|
||||
| include_file1 | snippet.html |
|
||||
| include_file2 | parametrized.html |
|
||||
And I have an "index.html" page that contains "{% include {{site.include_file1}} %} that {% include {{site.include_file2}} what='parameters' %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "a snippet that works with parameters" in "_site/index.html"
|
||||
|
||||
@@ -52,28 +52,6 @@ Feature: Include tags
|
||||
And I have an "_includes/one.html" file that contains "one"
|
||||
And I have an "_includes/two.html" file that contains "two"
|
||||
And I have an "index.html" page with files "[one.html, two.html]" that contains "{% for file in page.files %}{% include {{file}} %} {% endfor %}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "one two" in "_site/index.html"
|
||||
|
||||
Scenario: Include a file with variables and filters
|
||||
Given I have an _includes directory
|
||||
And I have an "_includes/one.html" file that contains "one included"
|
||||
And I have a configuration file with:
|
||||
| key | value |
|
||||
| include_file | one |
|
||||
And I have an "index.html" page that contains "{% include {{ site.include_file | append: '.html' }} %}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "one included" in "_site/index.html"
|
||||
|
||||
Scenario: Include a file with partial variables
|
||||
Given I have an _includes directory
|
||||
And I have an "_includes/one.html" file that contains "one included"
|
||||
And I have a configuration file with:
|
||||
| key | value |
|
||||
| include_file | one |
|
||||
And I have an "index.html" page that contains "{% include {{ site.include_file }}.html %}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "one included" in "_site/index.html"
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
Feature: Incremental rebuild
|
||||
As an impatient hacker who likes to blog
|
||||
I want to be able to make a static site
|
||||
Without waiting too long for it to build
|
||||
|
||||
Scenario: Produce correct output site
|
||||
Given I have a _layouts directory
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| Wargames | 2009-03-27 | default | The only winning move is not to play. |
|
||||
And I have a default layout that contains "Post Layout: {{ content }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post Layout: <p>The only winning move is not to play.</p>" in "_site/2009/03/27/wargames.html"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post Layout: <p>The only winning move is not to play.</p>" in "_site/2009/03/27/wargames.html"
|
||||
|
||||
Scenario: Generate a metadata file
|
||||
Given I have an "index.html" file that contains "Basic Site"
|
||||
When I run jekyll build
|
||||
Then the ".jekyll-metadata" file should exist
|
||||
|
||||
Scenario: Rebuild when content is changed
|
||||
Given I have an "index.html" file that contains "Basic Site"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site" in "_site/index.html"
|
||||
When I wait 1 second
|
||||
Then I have an "index.html" file that contains "Bacon Site"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Bacon Site" in "_site/index.html"
|
||||
|
||||
Scenario: Rebuild when layout is changed
|
||||
Given I have a _layouts directory
|
||||
And I have an "index.html" page with layout "default" that contains "Basic Site with Layout"
|
||||
And I have a default layout that contains "Page Layout: {{ content }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: Basic Site with Layout" in "_site/index.html"
|
||||
When I wait 1 second
|
||||
Then I have a default layout that contains "Page Layout Changed: {{ content }}"
|
||||
When I run jekyll build --full-rebuild
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout Changed: Basic Site with Layout" in "_site/index.html"
|
||||
|
||||
Scenario: Rebuild when an include is changed
|
||||
Given I have a _includes directory
|
||||
And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
|
||||
And I have an "_includes/about.textile" file that contains "Generated by Jekyll"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
|
||||
When I wait 1 second
|
||||
Then I have an "_includes/about.textile" file that contains "Regenerated by Jekyll"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Basic Site with include tag: Regenerated by Jekyll" in "_site/index.html"
|
||||
@@ -8,60 +8,23 @@ Feature: Markdown
|
||||
And I have an "index.html" page that contains "Index - {% for post in site.posts %} {{ post.content }} {% endfor %}"
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content | type |
|
||||
| title | date | content | type |
|
||||
| Hackers | 2009-03-27 | # My Title | markdown |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Index" in "_site/index.html"
|
||||
And I should see "<h1 id=\"my-title\">My Title</h1>" in "_site/2009/03/27/hackers.html"
|
||||
And I should see "<h1 id=\"my-title\">My Title</h1>" in "_site/index.html"
|
||||
And I should see "<h1 id=\"my_title\">My Title</h1>" in "_site/2009/03/27/hackers.html"
|
||||
And I should see "<h1 id=\"my_title\">My Title</h1>" in "_site/index.html"
|
||||
|
||||
Scenario: Markdown in pagination on index
|
||||
Given I have a configuration file with "paginate" set to "5"
|
||||
And I have an "index.html" page that contains "Index - {% for post in paginator.posts %} {{ post.content }} {% endfor %}"
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content | type |
|
||||
| title | date | content | type |
|
||||
| Hackers | 2009-03-27 | # My Title | markdown |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Index" in "_site/index.html"
|
||||
And I should see "<h1 id=\"my-title\">My Title</h1>" in "_site/index.html"
|
||||
|
||||
Scenario: Maruku fenced codeblocks
|
||||
Given I have a configuration file with "markdown" set to "maruku"
|
||||
And I have an "index.markdown" file with content:
|
||||
"""
|
||||
---
|
||||
title: My title
|
||||
---
|
||||
|
||||
# My title
|
||||
|
||||
```
|
||||
My awesome code
|
||||
```
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "My awesome code" in "_site/index.html"
|
||||
And I should see "<pre><code>My awesome code</code></pre>" in "_site/index.html"
|
||||
|
||||
Scenario: Maruku fenced codeblocks with syntax highlighting
|
||||
Given I have a configuration file with "markdown" set to "maruku"
|
||||
And I have an "index.markdown" file with content:
|
||||
"""
|
||||
---
|
||||
title: My title
|
||||
---
|
||||
|
||||
# My title
|
||||
|
||||
```ruby
|
||||
puts "My awesome string"
|
||||
```
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "My awesome string" in "_site/index.html"
|
||||
And I should see "<pre class="ruby"><code class="ruby">puts "My awesome string"</code></pre>" in "_site/index.html"
|
||||
And I should see "<h1 id=\"my_title\">My Title</h1>" in "_site/index.html"
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ Feature: Site pagination
|
||||
And I have an "index.html" page that contains "{{ paginator.posts.size }}"
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Wargames | 2009-03-27 | default | The only winning move is not to play. |
|
||||
| Wargames2 | 2009-04-27 | default | The only winning move is not to play2. |
|
||||
| Wargames3 | 2009-05-27 | default | The only winning move is not to play3. |
|
||||
| Wargames4 | 2009-06-27 | default | The only winning move is not to play4. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site/page<exist> directory should exist
|
||||
And the "_site/page<exist>/index.html" file should exist
|
||||
And I should see "<posts>" in "_site/page<exist>/index.html"
|
||||
@@ -36,12 +36,12 @@ Feature: Site pagination
|
||||
And I have an "blog/index.html" page that contains "{{ paginator.posts.size }}"
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Wargames | 2009-03-27 | default | The only winning move is not to play. |
|
||||
| Wargames2 | 2009-04-27 | default | The only winning move is not to play2. |
|
||||
| Wargames3 | 2009-05-27 | default | The only winning move is not to play3. |
|
||||
| Wargames4 | 2009-06-27 | default | The only winning move is not to play4. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site/blog/page-<exist> directory should exist
|
||||
And the "_site/blog/page-<exist>/index.html" file should exist
|
||||
And I should see "<posts>" in "_site/blog/page-<exist>/index.html"
|
||||
@@ -69,7 +69,7 @@ Feature: Site pagination
|
||||
| Wargames2 | 2009-04-27 | default | The only winning move is not to play2. |
|
||||
| Wargames3 | 2009-05-27 | default | The only winning move is not to play3. |
|
||||
| Wargames4 | 2009-06-27 | default | The only winning move is not to play4. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site/blog/page/<exist> directory should exist
|
||||
And the "_site/blog/page/<exist>/index.html" file should exist
|
||||
And I should see "<posts>" in "_site/blog/page/<exist>/index.html"
|
||||
|
||||
@@ -6,20 +6,20 @@ Feature: Fancy permalinks
|
||||
Scenario: Use none permalink schema
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| title | date | content |
|
||||
| None Permalink Schema | 2009-03-27 | Totally nothing. |
|
||||
And I have a configuration file with "permalink" set to "none"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally nothing." in "_site/none-permalink-schema.html"
|
||||
|
||||
Scenario: Use pretty permalink schema
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | content |
|
||||
| title | date | content |
|
||||
| Pretty Permalink Schema | 2009-03-27 | Totally wordpress. |
|
||||
And I have a configuration file with "permalink" set to "pretty"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally wordpress." in "_site/2009/03/27/pretty-permalink-schema/index.html"
|
||||
|
||||
@@ -28,7 +28,7 @@ Feature: Fancy permalinks
|
||||
And I have an "awesome.html" page that contains "Totally awesome"
|
||||
And I have an "sitemap.xml" page that contains "Totally uhm, sitemap"
|
||||
And I have a configuration file with "permalink" set to "pretty"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally index" in "_site/index.html"
|
||||
And I should see "Totally awesome" in "_site/awesome/index.html"
|
||||
@@ -37,39 +37,39 @@ Feature: Fancy permalinks
|
||||
Scenario: Use custom permalink schema with prefix
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | category | date | content |
|
||||
| title | category | date | content |
|
||||
| Custom Permalink Schema | stuff | 2009-03-27 | Totally custom. |
|
||||
And I have a configuration file with "permalink" set to "/blog/:year/:month/:day/:title"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally custom." in "_site/blog/2009/03/27/custom-permalink-schema/index.html"
|
||||
|
||||
Scenario: Use custom permalink schema with category
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | category | date | content |
|
||||
| title | category | date | content |
|
||||
| Custom Permalink Schema | stuff | 2009-03-27 | Totally custom. |
|
||||
And I have a configuration file with "permalink" set to "/:categories/:title.html"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally custom." in "_site/stuff/custom-permalink-schema.html"
|
||||
|
||||
Scenario: Use custom permalink schema with squished date
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | category | date | content |
|
||||
| title | category | date | content |
|
||||
| Custom Permalink Schema | stuff | 2009-03-27 | Totally custom. |
|
||||
And I have a configuration file with "permalink" set to "/:month-:day-:year/:title.html"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Totally custom." in "_site/03-27-2009/custom-permalink-schema.html"
|
||||
|
||||
Scenario: Use per-post permalink
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | permalink | content |
|
||||
| title | date | permalink | content |
|
||||
| Some post | 2013-04-14 | /custom/posts/1 | bla bla |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the _site/custom/posts/1 directory should exist
|
||||
And I should see "bla bla" in "_site/custom/posts/1/index.html"
|
||||
@@ -77,19 +77,9 @@ Feature: Fancy permalinks
|
||||
Scenario: Use per-post ending in .html
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | permalink | content |
|
||||
| title | date | permalink | content |
|
||||
| Some post | 2013-04-14 | /custom/posts/some.html | bla bla |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the _site/custom/posts directory should exist
|
||||
And I should see "bla bla" in "_site/custom/posts/some.html"
|
||||
|
||||
Scenario: Use per-post ending in .htm
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | permalink | content |
|
||||
| Some post | 2013-04-14 | /custom/posts/some.htm | bla bla |
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And the _site/custom/posts directory should exist
|
||||
And I should see "bla bla" in "_site/custom/posts/some.htm"
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
Feature: Configuring and using plugins
|
||||
As a hacker
|
||||
I want to specify my own plugins that can modify Jekyll's behaviour
|
||||
|
||||
Scenario: Add a gem-based plugin
|
||||
Given I have an "index.html" file that contains "Whatever"
|
||||
And I have a configuration file with "gems" set to "[jekyll_test_plugin]"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Whatever" in "_site/index.html"
|
||||
And I should see "this is a test" in "_site/test.txt"
|
||||
|
||||
Scenario: Add an empty whitelist to restrict all gems
|
||||
Given I have an "index.html" file that contains "Whatever"
|
||||
And I have a configuration file with:
|
||||
| key | value |
|
||||
| gems | [jekyll_test_plugin] |
|
||||
| whitelist | [] |
|
||||
When I run jekyll build --safe
|
||||
Then the _site directory should exist
|
||||
And I should see "Whatever" in "_site/index.html"
|
||||
And the "_site/test.txt" file should not exist
|
||||
|
||||
Scenario: Add a whitelist to restrict some gems but allow others
|
||||
Given I have an "index.html" file that contains "Whatever"
|
||||
And I have a configuration file with:
|
||||
| key | value |
|
||||
| gems | [jekyll_test_plugin, jekyll_test_plugin_malicious] |
|
||||
| whitelist | [jekyll_test_plugin] |
|
||||
When I run jekyll build --safe
|
||||
Then the _site directory should exist
|
||||
And I should see "Whatever" in "_site/index.html"
|
||||
And the "_site/test.txt" file should exist
|
||||
And I should see "this is a test" in "_site/test.txt"
|
||||
@@ -7,10 +7,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post title: {{ page.title }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post title: Star Wars" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -18,10 +18,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post url: {{ page.url }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post url: /2009/03/27/star-wars.html" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -29,10 +29,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post date: {{ page.date | date_to_string }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post date: 27 Mar 2009" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -40,10 +40,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post id: {{ page.id }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post id: /2009/03/27/star-wars" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -51,10 +51,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post content: {{ content }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post content: <p>Luke, I am your father.</p>" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -63,46 +63,10 @@ Feature: Post data
|
||||
And I have a movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "movies":
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Use post.categories variable when category is in a folder and has category in YAML
|
||||
Given I have a movies directory
|
||||
And I have a movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "movies":
|
||||
| title | date | layout | category | content |
|
||||
| Star Wars | 2009-03-27 | simple | film | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/film/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Use post.categories variable when category is in a folder and has categories in YAML
|
||||
Given I have a movies directory
|
||||
And I have a movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "movies":
|
||||
| title | date | layout | categories | content |
|
||||
| Star Wars | 2009-03-27 | simple | [film, scifi] | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/film/scifi/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Use post.categories variable when category is in a folder and duplicated category is in YAML
|
||||
Given I have a movies directory
|
||||
And I have a movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "movies":
|
||||
| title | date | layout | category | content |
|
||||
| Star Wars | 2009-03-27 | simple | movies | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -110,10 +74,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | tag | content |
|
||||
| title | date | layout | tag | content |
|
||||
| Star Wars | 2009-05-18 | simple | twist | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post tags: {{ page.tags }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post tags: twist" in "_site/2009/05/18/star-wars.html"
|
||||
|
||||
@@ -123,10 +87,10 @@ Feature: Post data
|
||||
And I have a scifi/movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "scifi/movies":
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -136,10 +100,10 @@ Feature: Post data
|
||||
And I have a scifi/Movies/_posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post in "scifi/Movies":
|
||||
| title | date | layout | content |
|
||||
| title | date | layout | content |
|
||||
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -147,10 +111,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | category | content |
|
||||
| title | date | layout | category | content |
|
||||
| Star Wars | 2009-03-27 | simple | movies | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -158,32 +122,21 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | category | content |
|
||||
| title | date | layout | category | content |
|
||||
| Star Wars | 2009-03-27 | simple | Movies | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Use post.categories variable when categories are in YAML
|
||||
Scenario: Use post.categories variable when category is in YAML
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | categories | content |
|
||||
| Star Wars | 2009-03-27 | simple | ['scifi', 'movies'] | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||
|
||||
Scenario: Use post.categories variable when categories are in YAML and are duplicated
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | categories | content |
|
||||
| Star Wars | 2009-03-27 | simple | ['movies', 'movies'] | Luke, I am your father. |
|
||||
| title | date | layout | category | content |
|
||||
| Star Wars | 2009-03-27 | simple | movies | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -191,11 +144,11 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | categories | content |
|
||||
| title | date | layout | categories | content |
|
||||
| Star Wars | 2009-03-27 | simple | ['scifi', 'Movies'] | Luke, I am your father. |
|
||||
| Star Trek | 2013-03-17 | simple | ['SciFi', 'movies'] | Jean Luc, I am your father. |
|
||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html"
|
||||
@@ -203,24 +156,24 @@ Feature: Post data
|
||||
Scenario Outline: Use page.path variable
|
||||
Given I have a <dir>/_posts directory
|
||||
And I have the following post in "<dir>":
|
||||
| title | type | date | content |
|
||||
| title | type | date | content |
|
||||
| my-post | html | 2013-04-12 | Source path: {{ page.path }} |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Source path: <path_prefix>_posts/2013-04-12-my-post.html" in "_site/<dir>/2013/04/12/my-post.html"
|
||||
|
||||
Examples:
|
||||
| dir | path_prefix |
|
||||
| . | |
|
||||
| dir | dir/ |
|
||||
| dir | path_prefix |
|
||||
| . | |
|
||||
| dir | dir/ |
|
||||
| dir/nested | dir/nested/ |
|
||||
|
||||
Scenario: Override page.path variable
|
||||
Given I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | path | content |
|
||||
| title | date | path | content |
|
||||
| override | 2013-04-12 | override-path.html | Custom path: {{ page.path }} |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Custom path: override-path.html" in "_site/2013/04/12/override.html"
|
||||
|
||||
@@ -228,9 +181,9 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" file that contains "Published!"
|
||||
And I have the following post:
|
||||
| title | date | layout | published | content |
|
||||
| title | date | layout | published | content |
|
||||
| Star Wars | 2009-03-27 | simple | false | Luke, I am your father. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the "_site/2009/03/27/star-wars.html" file should not exist
|
||||
And I should see "Published!" in "_site/index.html"
|
||||
@@ -239,10 +192,10 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | author | content |
|
||||
| title | date | layout | author | content |
|
||||
| Star Wars | 2009-03-27 | simple | Darth Vader | Luke, I am your father. |
|
||||
And I have a simple layout that contains "Post author: {{ page.author }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Post author: Darth Vader" in "_site/2009/03/27/star-wars.html"
|
||||
|
||||
@@ -250,12 +203,12 @@ Feature: Post data
|
||||
Given I have a _posts directory
|
||||
And I have a _layouts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | author | content |
|
||||
| title | date | layout | author | content |
|
||||
| Star Wars | 2009-03-27 | ordered | Darth Vader | Luke, I am your father. |
|
||||
| Some like it hot | 2009-04-27 | ordered | Osgood | Nobody is perfect. |
|
||||
| Terminator | 2009-05-27 | ordered | Arnold | Sayonara, baby |
|
||||
And I have a ordered layout that contains "Previous post: {{ page.previous.title }} and next post: {{ page.next.title }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "next post: Some like it hot" in "_site/2009/03/27/star-wars.html"
|
||||
And I should see "Previous post: Some like it hot" in "_site/2009/05/27/terminator.html"
|
||||
|
||||
@@ -9,9 +9,9 @@ Feature: Post excerpts
|
||||
Given I have an "index.html" page that contains "{% for post in site.posts %}{{ post.excerpt }}{% endfor %}"
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see exactly "<p>content for entry1.</p>" in "_site/index.html"
|
||||
|
||||
@@ -21,9 +21,9 @@ Feature: Post excerpts
|
||||
And I have a _layouts directory
|
||||
And I have a post layout that contains "{{ page.excerpt }}"
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the _site/2007 directory should exist
|
||||
And the _site/2007/12 directory should exist
|
||||
@@ -38,9 +38,9 @@ Feature: Post excerpts
|
||||
And I have a _layouts directory
|
||||
And I have a post layout that contains "<html><head></head><body>{{ page.excerpt }}</body></html>"
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the _site/2007 directory should exist
|
||||
And the _site/2007/12 directory should exist
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
Feature: Rendering
|
||||
As a hacker who likes to blog
|
||||
I want to be able to make a static site
|
||||
In order to share my awesome ideas with the interwebs
|
||||
But I want to make it as simply as possible
|
||||
So render with Liquid and place in Layouts
|
||||
|
||||
Scenario: Render Liquid and place in layout
|
||||
Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!"
|
||||
And I have a simple layout that contains "{{ content }}Ahoy, indeed!"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Hi there, Jekyll development!\nAhoy, indeed" in "_site/index.html"
|
||||
|
||||
Scenario: Don't place asset files in layout
|
||||
Given I have an "index.scss" page with layout "simple" that contains ".foo-bar { color:black; }"
|
||||
And I have an "index.coffee" page with layout "simple" that contains "whatever()"
|
||||
And I have a simple layout that contains "{{ content }}Ahoy, indeed!"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should not see "Ahoy, indeed!" in "_site/index.css"
|
||||
And I should not see "Ahoy, indeed!" in "_site/index.js"
|
||||
|
||||
Scenario: Render liquid in Sass
|
||||
Given I have an "index.scss" page that contains ".foo-bar { color:{{site.color}}; }"
|
||||
And I have a configuration file with "color" set to "red"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see ".foo-bar {\n color: red; }" in "_site/index.css"
|
||||
|
||||
Scenario: Render liquid in CoffeeScript
|
||||
Given I have an "index.coffee" page with animal "cicada" that contains "hey='for {{page.animal}}'"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "hey = 'for cicada';" in "_site/index.js"
|
||||
@@ -7,14 +7,14 @@ Feature: Site configuration
|
||||
Given I have a blank site in "_sourcedir"
|
||||
And I have an "_sourcedir/index.html" file that contains "Changing source directory"
|
||||
And I have a configuration file with "source" set to "_sourcedir"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Changing source directory" in "_site/index.html"
|
||||
|
||||
Scenario: Change destination directory
|
||||
Given I have an "index.html" file that contains "Changing destination directory"
|
||||
And I have a configuration file with "destination" set to "_mysite"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _mysite directory should exist
|
||||
And I should see "Changing destination directory" in "_mysite/index.html"
|
||||
|
||||
@@ -25,7 +25,7 @@ Feature: Site configuration
|
||||
| key | value |
|
||||
| source | <source> |
|
||||
| destination | <dest> |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the <source> directory should exist
|
||||
And the "<dest>/index.html" file should <file_exist> exist
|
||||
And I should see "markdown" in "<source>/index.md"
|
||||
@@ -44,7 +44,7 @@ Feature: Site configuration
|
||||
And I have an "README" file that contains "I want to be excluded"
|
||||
And I have an "index.html" file that contains "I want to be included"
|
||||
And I have a configuration file with "exclude" set to "['Rakefile', 'README']"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then I should see "I want to be included" in "_site/index.html"
|
||||
And the "_site/Rakefile" file should not exist
|
||||
And the "_site/README" file should not exist
|
||||
@@ -57,7 +57,7 @@ Feature: Site configuration
|
||||
| value |
|
||||
| README |
|
||||
| Rakefile |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then I should see "I want to be included" in "_site/index.html"
|
||||
And the "_site/Rakefile" file should not exist
|
||||
And the "_site/README" file should not exist
|
||||
@@ -65,54 +65,37 @@ Feature: Site configuration
|
||||
Scenario: Use RDiscount for markup
|
||||
Given I have an "index.markdown" page that contains "[Google](http://google.com)"
|
||||
And I have a configuration file with "markdown" set to "rdiscount"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "<a href=\"http://google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Use Kramdown for markup
|
||||
Given I have an "index.markdown" page that contains "[Google](http://google.com)"
|
||||
And I have a configuration file with "markdown" set to "kramdown"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "<a href=\"http://google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Use Redcarpet for markup
|
||||
Given I have an "index.markdown" page that contains "[Google](http://google.com)"
|
||||
And I have a configuration file with "markdown" set to "redcarpet"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "<a href=\"http://google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Use Maruku for markup
|
||||
Given I have an "index.markdown" page that contains "[Google](http://google.com)"
|
||||
And I have a configuration file with "markdown" set to "maruku"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "<a href=\"http://google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Highlight code with pygments
|
||||
Given I have an "index.html" page that contains "{% highlight ruby %} puts 'Hello world!' {% endhighlight %}"
|
||||
When I run jekyll build
|
||||
Given I have an "index.html" file that contains "{% highlight ruby %} puts 'Hello world!' {% endhighlight %}"
|
||||
And I have a configuration file with "pygments" set to "true"
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Hello world!" in "_site/index.html"
|
||||
And I should see "class=\"highlight\"" in "_site/index.html"
|
||||
|
||||
Scenario: Highlight code with rouge
|
||||
Given I have an "index.html" page that contains "{% highlight ruby %} puts 'Hello world!' {% endhighlight %}"
|
||||
And I have a configuration file with "highlighter" set to "rouge"
|
||||
When I run jekyll build
|
||||
Then the _site directory should exist
|
||||
And I should see "Hello world!" in "_site/index.html"
|
||||
And I should see "class=\"highlight\"" in "_site/index.html"
|
||||
|
||||
Scenario: Rouge renders code block once
|
||||
Given I have a configuration file with "highlighter" set to "rouge"
|
||||
And I have a _posts directory
|
||||
And I have the following post:
|
||||
| title | date | layout | content |
|
||||
| foo | 2014-04-27 11:34 | default | {% highlight text %} test {% endhighlight %} |
|
||||
When I run jekyll build
|
||||
Then I should not see "highlight(.*)highlight" in "_site/2014/04/27/foo.html"
|
||||
And I should see "puts 'Hello world!'" in "_site/index.html"
|
||||
|
||||
Scenario: Set time and no future dated posts
|
||||
Given I have a _layouts directory
|
||||
@@ -125,10 +108,10 @@ Feature: Site configuration
|
||||
| future | false |
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: 1 on 2010-01-01" in "_site/index.html"
|
||||
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
|
||||
@@ -145,10 +128,10 @@ Feature: Site configuration
|
||||
| future | true |
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html"
|
||||
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
|
||||
@@ -167,7 +150,7 @@ Feature: Site configuration
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. |
|
||||
| entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: 2" in "_site/index.html"
|
||||
And I should see "Post Layout: <p>content for entry1.</p> built at 2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html"
|
||||
@@ -186,7 +169,7 @@ Feature: Site configuration
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. |
|
||||
| entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: 2" in "_site/index.html"
|
||||
And the "_site/2013/04/10/entry1.html" file should exist
|
||||
@@ -200,11 +183,11 @@ Feature: Site configuration
|
||||
| key | value |
|
||||
| limit_posts | 2 |
|
||||
And I have the following posts:
|
||||
| title | date | content |
|
||||
| Apples | 2009-03-27 | An article about apples |
|
||||
| Oranges | 2009-04-01 | An article about oranges |
|
||||
| Bananas | 2009-04-05 | An article about bananas |
|
||||
When I run jekyll build
|
||||
| title | date | content |
|
||||
| Apples | 2009-03-27 | An article about apples |
|
||||
| Oranges | 2009-04-01 | An article about oranges |
|
||||
| Bananas | 2009-04-05 | An article about bananas |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And the "_site/2009/04/05/bananas.html" file should exist
|
||||
And the "_site/2009/04/01/oranges.html" file should exist
|
||||
@@ -217,7 +200,7 @@ Feature: Site configuration
|
||||
| value |
|
||||
| .gitignore |
|
||||
| .foo |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see ".DS_Store" in "_site/.gitignore"
|
||||
And the "_site/.htaccess" file should not exist
|
||||
@@ -234,19 +217,19 @@ Feature: Site configuration
|
||||
| layouts | _theme |
|
||||
And I have a _posts directory
|
||||
And I have the following posts:
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll build
|
||||
| title | date | layout | content |
|
||||
| entry1 | 2007-12-31 | post | content for entry1. |
|
||||
| entry2 | 2020-01-31 | post | content for entry2. |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html"
|
||||
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
|
||||
And I should see "Post Layout: <p>content for entry2.</p>" in "_site/2020/01/31/entry2.html"
|
||||
|
||||
Scenario: arbitrary file reads via layouts
|
||||
Given I have an "index.html" page with layout "page" that contains "FOO"
|
||||
And I have a "_config.yml" file that contains "layouts: '../../../../../../../../../../../../../../usr/include'"
|
||||
When I run jekyll build
|
||||
Scenario: Add a gem-based plugin
|
||||
Given I have an "index.html" file that contains "Whatever"
|
||||
And I have a configuration file with "gems" set to "[jekyll_test_plugin]"
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "FOO" in "_site/index.html"
|
||||
And I should not see " " in "_site/index.html"
|
||||
And I should see "Whatever" in "_site/index.html"
|
||||
And I should see "this is a test" in "_site/test.txt"
|
||||
|
||||
@@ -5,32 +5,32 @@ Feature: Site data
|
||||
|
||||
Scenario: Use page variable in a page
|
||||
Given I have an "contact.html" page with title "Contact" that contains "{{ page.title }}: email@example.com"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Contact: email@example.com" in "_site/contact.html"
|
||||
|
||||
Scenario Outline: Use page.path variable in a page
|
||||
Given I have a <dir> directory
|
||||
And I have a "<path>" page that contains "Source path: {{ page.path }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Source path: <path>" in "_site/<path>"
|
||||
|
||||
Examples:
|
||||
| dir | path |
|
||||
| . | index.html |
|
||||
| dir | dir/about.html |
|
||||
| dir | path |
|
||||
| . | index.html |
|
||||
| dir | dir/about.html |
|
||||
| dir/nested | dir/nested/page.html |
|
||||
|
||||
Scenario: Override page.path
|
||||
Given I have an "override.html" page with path "custom-override.html" that contains "Custom path: {{ page.path }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Custom path: custom-override.html" in "_site/override.html"
|
||||
|
||||
Scenario: Use site.time variable
|
||||
Given I have an "index.html" page that contains "{{ site.time }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see today's time in "_site/index.html"
|
||||
|
||||
@@ -38,11 +38,11 @@ Feature: Site data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" page that contains "{{ site.posts.first.title }}: {{ site.posts.first.url }}"
|
||||
And I have the following posts:
|
||||
| title | date | content |
|
||||
| First Post | 2009-03-25 | My First Post |
|
||||
| Second Post | 2009-03-26 | My Second Post |
|
||||
| Third Post | 2009-03-27 | My Third Post |
|
||||
When I run jekyll build
|
||||
| title | date | content |
|
||||
| First Post | 2009-03-25 | My First Post |
|
||||
| Second Post | 2009-03-26 | My Second Post |
|
||||
| Third Post | 2009-03-27 | My Third Post |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Third Post: /2009/03/27/third-post.html" in "_site/index.html"
|
||||
|
||||
@@ -50,11 +50,11 @@ Feature: Site data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" page that contains "{% for post in site.posts %} {{ post.title }} {% endfor %}"
|
||||
And I have the following posts:
|
||||
| title | date | content |
|
||||
| First Post | 2009-03-25 | My First Post |
|
||||
| Second Post | 2009-03-26 | My Second Post |
|
||||
| Third Post | 2009-03-27 | My Third Post |
|
||||
When I run jekyll build
|
||||
| title | date | content |
|
||||
| First Post | 2009-03-25 | My First Post |
|
||||
| Second Post | 2009-03-26 | My Second Post |
|
||||
| Third Post | 2009-03-27 | My Third Post |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Third Post Second Post First Post" in "_site/index.html"
|
||||
|
||||
@@ -62,10 +62,10 @@ Feature: Site data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" page that contains "{% for post in site.categories.code %} {{ post.title }} {% endfor %}"
|
||||
And I have the following posts:
|
||||
| title | date | category | content |
|
||||
| title | date | category | content |
|
||||
| Awesome Hack | 2009-03-26 | code | puts 'Hello World' |
|
||||
| Delicious Beer | 2009-03-26 | food | 1) Yuengling |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Awesome Hack" in "_site/index.html"
|
||||
|
||||
@@ -73,9 +73,9 @@ Feature: Site data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" page that contains "{% for post in site.tags.beer %} {{ post.content }} {% endfor %}"
|
||||
And I have the following posts:
|
||||
| title | date | tag | content |
|
||||
| Delicious Beer | 2009-03-26 | beer | 1) Yuengling |
|
||||
When I run jekyll build
|
||||
| title | date | tag | content |
|
||||
| Delicious Beer | 2009-03-26 | beer | 1) Yuengling |
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "Yuengling" in "_site/index.html"
|
||||
|
||||
@@ -83,25 +83,25 @@ Feature: Site data
|
||||
Given I have a _posts directory
|
||||
And I have an "index.html" page that contains "{% for post in site.posts %}{{ post.title }}:{{ post.previous.title}},{{ post.next.title}} {% endfor %}"
|
||||
And I have the following posts:
|
||||
| title | date | content |
|
||||
| title | date | content |
|
||||
| first | 2009-02-26 | first |
|
||||
| A | 2009-03-26 | A |
|
||||
| B | 2009-03-26 | B |
|
||||
| C | 2009-03-26 | C |
|
||||
| last | 2009-04-26 | last |
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "last:C, C:B,last B:A,C A:first,B first:,A" in "_site/index.html"
|
||||
|
||||
Scenario: Use configuration date in site payload
|
||||
Given I have an "index.html" page that contains "{{ site.url }}"
|
||||
And I have a configuration file with "url" set to "http://example.com"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "http://example.com" in "_site/index.html"
|
||||
|
||||
Scenario: Access Jekyll version via jekyll.version
|
||||
Given I have an "index.html" page that contains "{{ jekyll.version }}"
|
||||
When I run jekyll build
|
||||
When I run jekyll
|
||||
Then the _site directory should exist
|
||||
And I should see "\d+\.\d+\.\d+" in "_site/index.html"
|
||||
|
||||
@@ -1,36 +1,13 @@
|
||||
def file_content_from_hash(input_hash)
|
||||
matter_hash = input_hash.reject { |k, v| k == "content" }
|
||||
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
||||
|
||||
content = if input_hash['input'] && input_hash['filter']
|
||||
"{{ #{input_hash['input']} | #{input_hash['filter']} }}"
|
||||
else
|
||||
input_hash['content']
|
||||
end
|
||||
|
||||
<<EOF
|
||||
---
|
||||
#{matter}
|
||||
---
|
||||
#{content}
|
||||
EOF
|
||||
end
|
||||
|
||||
Before do
|
||||
FileUtils.mkdir_p(TEST_DIR) unless File.exist?(TEST_DIR)
|
||||
FileUtils.rm_rf(TEST_DIR)
|
||||
FileUtils.mkdir(TEST_DIR)
|
||||
Dir.chdir(TEST_DIR)
|
||||
end
|
||||
|
||||
After do
|
||||
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
||||
FileUtils.rm(JEKYLL_COMMAND_OUTPUT_FILE) if File.exist?(JEKYLL_COMMAND_OUTPUT_FILE)
|
||||
Dir.chdir(File.dirname(TEST_DIR))
|
||||
end
|
||||
|
||||
World(Test::Unit::Assertions)
|
||||
|
||||
Given /^I have a blank site in "(.*)"$/ do |path|
|
||||
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||
FileUtils.mkdir_p(path)
|
||||
end
|
||||
|
||||
Given /^I do not have a "(.*)" directory$/ do |path|
|
||||
@@ -81,28 +58,42 @@ Given /^I have an? (.*) directory$/ do |dir|
|
||||
FileUtils.mkdir_p(dir)
|
||||
end
|
||||
|
||||
Given /^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table|
|
||||
table.hashes.each do |input_hash|
|
||||
title = slug(input_hash['title'])
|
||||
ext = input_hash['type'] || 'textile'
|
||||
Given /^I have the following (draft|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table|
|
||||
table.hashes.each do |post|
|
||||
title = slug(post['title'])
|
||||
ext = post['type'] || 'textile'
|
||||
before, after = location(folder, direction)
|
||||
|
||||
case status
|
||||
when "draft"
|
||||
dest_folder = '_drafts'
|
||||
if "draft" == status
|
||||
folder_post = '_drafts'
|
||||
filename = "#{title}.#{ext}"
|
||||
when "page"
|
||||
dest_folder = ''
|
||||
filename = "#{title}.#{ext}"
|
||||
when "post"
|
||||
parsed_date = Time.xmlschema(input_hash['date']) rescue Time.parse(input_hash['date'])
|
||||
dest_folder = '_posts'
|
||||
elsif "post" == status
|
||||
parsed_date = Time.xmlschema(post['date']) rescue Time.parse(post['date'])
|
||||
folder_post = '_posts'
|
||||
filename = "#{parsed_date.strftime('%Y-%m-%d')}-#{title}.#{ext}"
|
||||
end
|
||||
|
||||
path = File.join(before, dest_folder, after, filename)
|
||||
path = File.join(before, folder_post, after, filename)
|
||||
|
||||
matter_hash = {}
|
||||
%w(title layout tag tags category categories published author path date permalink).each do |key|
|
||||
matter_hash[key] = post[key] if post[key]
|
||||
end
|
||||
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
||||
|
||||
content = if post['input'] && post['filter']
|
||||
"{{ #{post['input']} | #{post['filter']} }}"
|
||||
else
|
||||
post['content']
|
||||
end
|
||||
|
||||
File.open(path, 'w') do |f|
|
||||
f.write file_content_from_hash(input_hash)
|
||||
f.write <<EOF
|
||||
---
|
||||
#{matter}
|
||||
---
|
||||
#{content}
|
||||
EOF
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -130,32 +121,21 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
|
||||
end
|
||||
end
|
||||
|
||||
Given /^I have fixture collections$/ do
|
||||
FileUtils.cp_r File.join(JEKYLL_SOURCE_DIR, "test", "source", "_methods"), source_dir
|
||||
|
||||
When /^I run jekyll$/ do
|
||||
run_jekyll
|
||||
end
|
||||
|
||||
Given /^I wait (\d+) second(s?)$/ do |time, plural|
|
||||
sleep(time.to_f)
|
||||
When /^I run jekyll with drafts$/ do
|
||||
run_jekyll(:drafts => true)
|
||||
end
|
||||
|
||||
##################
|
||||
#
|
||||
# Changing stuff
|
||||
#
|
||||
##################
|
||||
|
||||
When /^I run jekyll(.*)$/ do |args|
|
||||
status = run_jekyll(args)
|
||||
if args.include?("--verbose") || ENV['DEBUG']
|
||||
puts jekyll_run_output
|
||||
end
|
||||
When /^I call jekyll new with test_blank --blank$/ do
|
||||
call_jekyll_new(:path => "test_blank", :blank => true)
|
||||
end
|
||||
|
||||
When /^I run bundle(.*)$/ do |args|
|
||||
status = run_bundle(args)
|
||||
if args.include?("--verbose") || ENV['DEBUG']
|
||||
puts jekyll_run_output
|
||||
end
|
||||
When /^I debug jekyll$/ do
|
||||
run_jekyll(:debug => true)
|
||||
end
|
||||
|
||||
When /^I change "(.*)" to contain "(.*)"$/ do |file, text|
|
||||
@@ -177,7 +157,7 @@ Then /^the (.*) directory should not exist$/ do |dir|
|
||||
end
|
||||
|
||||
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
|
||||
assert_match Regexp.new(text, Regexp::MULTILINE), file_contents(file)
|
||||
assert_match Regexp.new(text), file_contents(file)
|
||||
end
|
||||
|
||||
Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file|
|
||||
@@ -185,7 +165,7 @@ Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file|
|
||||
end
|
||||
|
||||
Then /^I should not see "(.*)" in "(.*)"$/ do |text, file|
|
||||
assert_no_match Regexp.new(text, Regexp::MULTILINE), file_contents(file)
|
||||
assert_no_match Regexp.new(text), file_contents(file)
|
||||
end
|
||||
|
||||
Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file|
|
||||
@@ -193,19 +173,11 @@ Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file|
|
||||
end
|
||||
|
||||
Then /^the "(.*)" file should +exist$/ do |file|
|
||||
file_does_exist = File.file?(file)
|
||||
unless file_does_exist
|
||||
all_steps_to_path(file).each do |dir|
|
||||
STDERR.puts ""
|
||||
STDERR.puts "Dir #{dir}:"
|
||||
STDERR.puts Dir["#{dir}/**/*"]
|
||||
end
|
||||
end
|
||||
assert file_does_exist, "The file \"#{file}\" does not exist.\n"
|
||||
assert File.file?(file), "The file \"#{file}\" does not exist"
|
||||
end
|
||||
|
||||
Then /^the "(.*)" file should not exist$/ do |file|
|
||||
assert !File.exist?(file), "The file \"#{file}\" exists"
|
||||
assert !File.exists?(file), "The file \"#{file}\" exists"
|
||||
end
|
||||
|
||||
Then /^I should see today's time in "(.*)"$/ do |file|
|
||||
@@ -215,7 +187,3 @@ end
|
||||
Then /^I should see today's date in "(.*)"$/ do |file|
|
||||
assert_match Regexp.new(Date.today.to_s), file_contents(file)
|
||||
end
|
||||
|
||||
Then /^I should see "(.*)" in the build output$/ do |text|
|
||||
assert_match Regexp.new(text), jekyll_run_output
|
||||
end
|
||||
|
||||
@@ -1,56 +1,35 @@
|
||||
if RUBY_VERSION > '1.9'
|
||||
require 'coveralls'
|
||||
Coveralls.wear_merged!
|
||||
end
|
||||
|
||||
require 'fileutils'
|
||||
require 'posix-spawn'
|
||||
require 'rr'
|
||||
require 'test/unit'
|
||||
require 'time'
|
||||
|
||||
JEKYLL_SOURCE_DIR = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||
TEST_DIR = File.expand_path(File.join('..', '..', 'tmp', 'jekyll'), File.dirname(__FILE__))
|
||||
JEKYLL_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll'))
|
||||
JEKYLL_COMMAND_OUTPUT_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_output.txt')
|
||||
TEST_DIR = File.join('/', 'tmp', 'jekyll')
|
||||
JEKYLL_PATH = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll')
|
||||
|
||||
def source_dir(*files)
|
||||
File.join(TEST_DIR, *files)
|
||||
def run_jekyll(opts = {})
|
||||
command = JEKYLL_PATH.clone
|
||||
command << " build"
|
||||
command << " --drafts" if opts[:drafts]
|
||||
command << " >> /dev/null 2>&1" if opts[:debug].nil?
|
||||
system command
|
||||
end
|
||||
|
||||
def all_steps_to_path(path)
|
||||
source = Pathname.new(source_dir('_site')).expand_path
|
||||
dest = Pathname.new(path).expand_path
|
||||
paths = []
|
||||
dest.ascend do |f|
|
||||
break if f.eql? source
|
||||
paths.unshift f.to_s
|
||||
end
|
||||
paths
|
||||
end
|
||||
|
||||
def jekyll_output_file
|
||||
JEKYLL_COMMAND_OUTPUT_FILE
|
||||
end
|
||||
|
||||
def jekyll_run_output
|
||||
File.read(jekyll_output_file) if File.file?(jekyll_output_file)
|
||||
end
|
||||
|
||||
def run_bundle(args)
|
||||
child = run_in_shell('bundle', *args.strip.split(' '))
|
||||
end
|
||||
|
||||
def run_jekyll(args)
|
||||
child = run_in_shell(JEKYLL_PATH, *args.strip.split(' '), "--trace")
|
||||
child.status.exitstatus == 0
|
||||
end
|
||||
|
||||
def run_in_shell(*args)
|
||||
POSIX::Spawn::Child.new *args, :out => [JEKYLL_COMMAND_OUTPUT_FILE, "w"]
|
||||
def call_jekyll_new(opts = {})
|
||||
command = JEKYLL_PATH.clone
|
||||
command << " new"
|
||||
command << " #{opts[:path]}" if opts[:path]
|
||||
command << " --blank" if opts[:blank]
|
||||
command << " >> /dev/null 2>&1" if opts[:debug].nil?
|
||||
system command
|
||||
end
|
||||
|
||||
def slug(title)
|
||||
if title
|
||||
title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
||||
else
|
||||
Time.now.strftime("%s%9N") # nanoseconds since the Epoch
|
||||
end
|
||||
title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
||||
end
|
||||
|
||||
def location(folder, direction)
|
||||
@@ -68,8 +47,15 @@ def file_contents(path)
|
||||
end
|
||||
|
||||
def seconds_agnostic_datetime(datetime = Time.now)
|
||||
date, time, zone = datetime.to_s.split(" ")
|
||||
time = seconds_agnostic_time(time)
|
||||
pieces = datetime.to_s.split(" ")
|
||||
if pieces.size == 6 # Ruby 1.8.7
|
||||
date = pieces[0..2].join(" ")
|
||||
time = seconds_agnostic_time(pieces[3])
|
||||
zone = pieces[4..5].join(" ")
|
||||
else # Ruby 1.9.1 or greater
|
||||
date, time, zone = pieces
|
||||
time = seconds_agnostic_time(time)
|
||||
end
|
||||
[
|
||||
Regexp.escape(date),
|
||||
"#{time}:\\d{2}",
|
||||
@@ -84,3 +70,6 @@ def seconds_agnostic_time(time)
|
||||
hour, minutes, _ = time.split(":")
|
||||
"#{hour}:#{minutes}"
|
||||
end
|
||||
|
||||
# work around "invalid option: --format" cucumber bug (see #296)
|
||||
Test::Unit.run = true if RUBY_VERSION < '1.9'
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
require 'fileutils'
|
||||
require 'colorator'
|
||||
require 'cucumber/formatter/console'
|
||||
require 'cucumber/formatter/io'
|
||||
require 'gherkin/formatter/escaping'
|
||||
|
||||
module Features
|
||||
module Support
|
||||
# The formatter used for <tt>--format pretty</tt> (the default formatter).
|
||||
#
|
||||
# This formatter prints features to plain text - exactly how they were parsed,
|
||||
# just prettier. That means with proper indentation and alignment of table columns.
|
||||
#
|
||||
# If the output is STDOUT (and not a file), there are bright colours to watch too.
|
||||
#
|
||||
class Overview
|
||||
include FileUtils
|
||||
include Cucumber::Formatter::Console
|
||||
include Cucumber::Formatter::Io
|
||||
include Gherkin::Formatter::Escaping
|
||||
attr_writer :indent
|
||||
attr_reader :runtime
|
||||
|
||||
def initialize(runtime, path_or_io, options)
|
||||
@runtime, @io, @options = runtime, ensure_io(path_or_io, "pretty"), options
|
||||
@exceptions = []
|
||||
@indent = 0
|
||||
@prefixes = options[:prefixes] || {}
|
||||
@delayed_messages = []
|
||||
end
|
||||
|
||||
def before_features(features)
|
||||
print_profile_information
|
||||
end
|
||||
|
||||
def after_features(features)
|
||||
@io.puts
|
||||
print_summary(features)
|
||||
end
|
||||
|
||||
def before_feature(feature)
|
||||
@exceptions = []
|
||||
@indent = 0
|
||||
end
|
||||
|
||||
def comment_line(comment_line)
|
||||
end
|
||||
|
||||
def after_tags(tags)
|
||||
end
|
||||
|
||||
def tag_name(tag_name)
|
||||
end
|
||||
|
||||
def before_feature_element(feature_element)
|
||||
@indent = 2
|
||||
@scenario_indent = 2
|
||||
end
|
||||
|
||||
def after_feature_element(feature_element)
|
||||
end
|
||||
|
||||
def before_background(background)
|
||||
@indent = 2
|
||||
@scenario_indent = 2
|
||||
@in_background = true
|
||||
end
|
||||
|
||||
def after_background(background)
|
||||
@in_background = nil
|
||||
end
|
||||
|
||||
def background_name(keyword, name, file_colon_line, source_indent)
|
||||
print_feature_element_name(keyword, name, file_colon_line, source_indent)
|
||||
end
|
||||
|
||||
def scenario_name(keyword, name, file_colon_line, source_indent)
|
||||
print_feature_element_name(keyword, name, file_colon_line, source_indent)
|
||||
end
|
||||
|
||||
def before_step(step)
|
||||
@current_step = step
|
||||
end
|
||||
|
||||
def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
|
||||
@hide_this_step = false
|
||||
if exception
|
||||
if @exceptions.include?(exception)
|
||||
@hide_this_step = true
|
||||
return
|
||||
end
|
||||
@exceptions << exception
|
||||
end
|
||||
if status != :failed && @in_background ^ background
|
||||
@hide_this_step = true
|
||||
return
|
||||
end
|
||||
@status = status
|
||||
end
|
||||
|
||||
CHARS = {
|
||||
:failed => "x".red,
|
||||
:pending => "?".yellow,
|
||||
:undefined => "x".red,
|
||||
:passed => ".".green,
|
||||
:skipped => "-".blue
|
||||
}
|
||||
|
||||
def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
|
||||
@io.print CHARS[status]
|
||||
end
|
||||
|
||||
def exception(exception, status)
|
||||
return if @hide_this_step
|
||||
@io.puts
|
||||
print_exception(exception, status, @indent)
|
||||
@io.flush
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def print_feature_element_name(keyword, name, file_colon_line, source_indent)
|
||||
@io.puts
|
||||
names = name.empty? ? [name] : name.split("\n")
|
||||
line = " #{keyword}: #{names[0]}"
|
||||
if @options[:source]
|
||||
line_comment = "#{file_colon_line}"
|
||||
@io.print(line_comment)
|
||||
end
|
||||
@io.print(line)
|
||||
@io.print " "
|
||||
@io.flush
|
||||
end
|
||||
|
||||
def cell_prefix(status)
|
||||
@prefixes[status]
|
||||
end
|
||||
|
||||
def print_summary(features)
|
||||
@io.puts
|
||||
print_stats(features, @options)
|
||||
print_snippets(@options)
|
||||
print_passing_wip(@options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
327
jekyll.gemspec
327
jekyll.gemspec
@@ -1,48 +1,301 @@
|
||||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'jekyll/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.specification_version = 2 if s.respond_to? :specification_version=
|
||||
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
||||
s.rubygems_version = '2.2.2'
|
||||
s.required_ruby_version = '>= 2.0.0'
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.rubygems_version = '1.3.5'
|
||||
|
||||
s.name = 'jekyll'
|
||||
s.version = Jekyll::VERSION
|
||||
s.license = 'MIT'
|
||||
s.name = 'jekyll'
|
||||
s.version = '1.4.1'
|
||||
s.license = 'MIT'
|
||||
s.date = '2013-12-09'
|
||||
s.rubyforge_project = 'jekyll'
|
||||
|
||||
s.summary = 'A simple, blog aware, static site generator.'
|
||||
s.description = 'Jekyll is a simple, blog aware, static site generator.'
|
||||
s.summary = "A simple, blog aware, static site generator."
|
||||
s.description = "Jekyll is a simple, blog aware, static site generator."
|
||||
|
||||
s.authors = ['Tom Preston-Werner']
|
||||
s.email = 'tom@mojombo.com'
|
||||
s.homepage = 'https://github.com/jekyll/jekyll'
|
||||
s.authors = ["Tom Preston-Werner"]
|
||||
s.email = 'tom@mojombo.com'
|
||||
s.homepage = 'http://github.com/mojombo/jekyll'
|
||||
|
||||
all_files = `git ls-files -z`.split("\x0")
|
||||
s.files = all_files.grep(%r{^(bin|lib)/})
|
||||
s.executables = all_files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
s.require_paths = ['lib']
|
||||
s.require_paths = %w[lib]
|
||||
|
||||
s.rdoc_options = ['--charset=UTF-8']
|
||||
s.executables = ["jekyll"]
|
||||
|
||||
s.rdoc_options = ["--charset=UTF-8"]
|
||||
s.extra_rdoc_files = %w[README.markdown LICENSE]
|
||||
|
||||
s.add_runtime_dependency('liquid', '~> 3.0')
|
||||
s.add_runtime_dependency('kramdown', '~> 1.3')
|
||||
s.add_runtime_dependency('mercenary', '~> 0.3.3')
|
||||
s.add_runtime_dependency('safe_yaml', '~> 1.0')
|
||||
s.add_runtime_dependency('colorator', '~> 0.1')
|
||||
|
||||
# Before 3.0 drops, phase the following gems out as dev dependencies
|
||||
# and gracefully handle their absence.
|
||||
s.add_runtime_dependency('pygments.rb', '~> 0.6.0')
|
||||
s.add_runtime_dependency('redcarpet', '~> 3.1')
|
||||
s.add_runtime_dependency('liquid', "~> 2.5.2")
|
||||
s.add_runtime_dependency('classifier', "~> 1.3")
|
||||
s.add_runtime_dependency('listen', "~> 1.3")
|
||||
s.add_runtime_dependency('maruku', "~> 0.7.0")
|
||||
s.add_runtime_dependency('pygments.rb', "~> 0.5.0")
|
||||
s.add_runtime_dependency('commander', "~> 4.1.3")
|
||||
s.add_runtime_dependency('safe_yaml', "~> 0.9.7")
|
||||
s.add_runtime_dependency('colorator', "~> 0.1")
|
||||
s.add_runtime_dependency('redcarpet', "~> 2.3.0")
|
||||
s.add_runtime_dependency('toml', '~> 0.1.0')
|
||||
s.add_runtime_dependency('jekyll-paginate', '~> 1.0')
|
||||
s.add_runtime_dependency('jekyll-gist', '~> 1.0')
|
||||
s.add_runtime_dependency('jekyll-coffeescript', '~> 1.0')
|
||||
s.add_runtime_dependency('jekyll-sass-converter', '~> 1.0')
|
||||
s.add_runtime_dependency('jekyll-watch', '~> 1.1')
|
||||
s.add_runtime_dependency('classifier-reborn', '~> 2.0')
|
||||
|
||||
s.add_development_dependency('rake', "~> 10.1")
|
||||
s.add_development_dependency('rdoc', "~> 3.11")
|
||||
s.add_development_dependency('redgreen', "~> 1.2")
|
||||
s.add_development_dependency('shoulda', "~> 3.3.2")
|
||||
s.add_development_dependency('rr', "~> 1.1")
|
||||
s.add_development_dependency('cucumber', "~> 1.3")
|
||||
s.add_development_dependency('RedCloth', "~> 4.2")
|
||||
s.add_development_dependency('kramdown', "~> 1.2")
|
||||
s.add_development_dependency('rdiscount', "~> 1.6")
|
||||
s.add_development_dependency('launchy', "~> 2.3")
|
||||
s.add_development_dependency('simplecov', "~> 0.7")
|
||||
s.add_development_dependency('simplecov-gem-adapter', "~> 1.0.1")
|
||||
s.add_development_dependency('coveralls', "~> 0.7.0")
|
||||
s.add_development_dependency('mime-types', "~> 1.5")
|
||||
s.add_development_dependency('activesupport', '~> 3.2.13')
|
||||
s.add_development_dependency('jekyll_test_plugin')
|
||||
|
||||
# = MANIFEST =
|
||||
s.files = %w[
|
||||
CONTRIBUTING.markdown
|
||||
Gemfile
|
||||
History.markdown
|
||||
LICENSE
|
||||
README.markdown
|
||||
Rakefile
|
||||
bin/jekyll
|
||||
cucumber.yml
|
||||
features/create_sites.feature
|
||||
features/data.feature
|
||||
features/drafts.feature
|
||||
features/embed_filters.feature
|
||||
features/include_tag.feature
|
||||
features/markdown.feature
|
||||
features/pagination.feature
|
||||
features/permalinks.feature
|
||||
features/post_data.feature
|
||||
features/post_excerpts.feature
|
||||
features/site_configuration.feature
|
||||
features/site_data.feature
|
||||
features/step_definitions/jekyll_steps.rb
|
||||
features/support/env.rb
|
||||
jekyll.gemspec
|
||||
lib/jekyll.rb
|
||||
lib/jekyll/cleaner.rb
|
||||
lib/jekyll/command.rb
|
||||
lib/jekyll/commands/build.rb
|
||||
lib/jekyll/commands/doctor.rb
|
||||
lib/jekyll/commands/new.rb
|
||||
lib/jekyll/commands/serve.rb
|
||||
lib/jekyll/configuration.rb
|
||||
lib/jekyll/converter.rb
|
||||
lib/jekyll/converters/identity.rb
|
||||
lib/jekyll/converters/markdown.rb
|
||||
lib/jekyll/converters/markdown/kramdown_parser.rb
|
||||
lib/jekyll/converters/markdown/maruku_parser.rb
|
||||
lib/jekyll/converters/markdown/rdiscount_parser.rb
|
||||
lib/jekyll/converters/markdown/redcarpet_parser.rb
|
||||
lib/jekyll/converters/textile.rb
|
||||
lib/jekyll/convertible.rb
|
||||
lib/jekyll/core_ext.rb
|
||||
lib/jekyll/deprecator.rb
|
||||
lib/jekyll/draft.rb
|
||||
lib/jekyll/entry_filter.rb
|
||||
lib/jekyll/errors.rb
|
||||
lib/jekyll/excerpt.rb
|
||||
lib/jekyll/filters.rb
|
||||
lib/jekyll/generator.rb
|
||||
lib/jekyll/generators/pagination.rb
|
||||
lib/jekyll/layout.rb
|
||||
lib/jekyll/mime.types
|
||||
lib/jekyll/page.rb
|
||||
lib/jekyll/plugin.rb
|
||||
lib/jekyll/post.rb
|
||||
lib/jekyll/related_posts.rb
|
||||
lib/jekyll/site.rb
|
||||
lib/jekyll/static_file.rb
|
||||
lib/jekyll/stevenson.rb
|
||||
lib/jekyll/tags/gist.rb
|
||||
lib/jekyll/tags/highlight.rb
|
||||
lib/jekyll/tags/include.rb
|
||||
lib/jekyll/tags/post_url.rb
|
||||
lib/jekyll/url.rb
|
||||
lib/site_template/.gitignore
|
||||
lib/site_template/_config.yml
|
||||
lib/site_template/_layouts/default.html
|
||||
lib/site_template/_layouts/post.html
|
||||
lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb
|
||||
lib/site_template/css/main.css
|
||||
lib/site_template/css/syntax.css
|
||||
lib/site_template/index.html
|
||||
script/bootstrap
|
||||
site/.gitignore
|
||||
site/CNAME
|
||||
site/README
|
||||
site/_config.yml
|
||||
site/_includes/analytics.html
|
||||
site/_includes/docs_contents.html
|
||||
site/_includes/docs_contents_mobile.html
|
||||
site/_includes/docs_option.html
|
||||
site/_includes/docs_ul.html
|
||||
site/_includes/footer.html
|
||||
site/_includes/header.html
|
||||
site/_includes/news_contents.html
|
||||
site/_includes/news_contents_mobile.html
|
||||
site/_includes/news_item.html
|
||||
site/_includes/primary-nav-items.html
|
||||
site/_includes/section_nav.html
|
||||
site/_includes/top.html
|
||||
site/_layouts/default.html
|
||||
site/_layouts/docs.html
|
||||
site/_layouts/news.html
|
||||
site/_layouts/news_item.html
|
||||
site/_posts/2013-05-06-jekyll-1-0-0-released.markdown
|
||||
site/_posts/2013-05-08-jekyll-1-0-1-released.markdown
|
||||
site/_posts/2013-05-12-jekyll-1-0-2-released.markdown
|
||||
site/_posts/2013-06-07-jekyll-1-0-3-released.markdown
|
||||
site/_posts/2013-07-14-jekyll-1-1-0-released.markdown
|
||||
site/_posts/2013-07-24-jekyll-1-1-1-released.markdown
|
||||
site/_posts/2013-07-25-jekyll-1-0-4-released.markdown
|
||||
site/_posts/2013-07-25-jekyll-1-1-2-released.markdown
|
||||
site/_posts/2013-09-06-jekyll-1-2-0-released.markdown
|
||||
site/_posts/2013-09-14-jekyll-1-2-1-released.markdown
|
||||
site/_posts/2013-10-28-jekyll-1-3-0-rc1-released.markdown
|
||||
site/_posts/2013-11-04-jekyll-1-3-0-released.markdown
|
||||
site/_posts/2013-11-26-jekyll-1-3-1-released.markdown
|
||||
site/_posts/2013-12-07-jekyll-1-4-0-released.markdown
|
||||
site/css/gridism.css
|
||||
site/css/normalize.css
|
||||
site/css/pygments.css
|
||||
site/css/style.css
|
||||
site/docs/configuration.md
|
||||
site/docs/contributing.md
|
||||
site/docs/datafiles.md
|
||||
site/docs/deployment-methods.md
|
||||
site/docs/drafts.md
|
||||
site/docs/extras.md
|
||||
site/docs/frontmatter.md
|
||||
site/docs/github-pages.md
|
||||
site/docs/heroku.md
|
||||
site/docs/history.md
|
||||
site/docs/index.md
|
||||
site/docs/installation.md
|
||||
site/docs/migrations.md
|
||||
site/docs/pages.md
|
||||
site/docs/pagination.md
|
||||
site/docs/permalinks.md
|
||||
site/docs/plugins.md
|
||||
site/docs/posts.md
|
||||
site/docs/quickstart.md
|
||||
site/docs/resources.md
|
||||
site/docs/sites.md
|
||||
site/docs/structure.md
|
||||
site/docs/templates.md
|
||||
site/docs/troubleshooting.md
|
||||
site/docs/upgrading.md
|
||||
site/docs/usage.md
|
||||
site/docs/variables.md
|
||||
site/favicon.png
|
||||
site/feed.xml
|
||||
site/freenode.txt
|
||||
site/img/article-footer.png
|
||||
site/img/footer-arrow.png
|
||||
site/img/footer-logo.png
|
||||
site/img/logo-2x.png
|
||||
site/img/octojekyll.png
|
||||
site/img/tube.png
|
||||
site/img/tube1x.png
|
||||
site/index.html
|
||||
site/js/modernizr-2.5.3.min.js
|
||||
site/news/index.html
|
||||
site/news/releases/index.html
|
||||
test/fixtures/broken_front_matter1.erb
|
||||
test/fixtures/broken_front_matter2.erb
|
||||
test/fixtures/broken_front_matter3.erb
|
||||
test/fixtures/exploit_front_matter.erb
|
||||
test/fixtures/front_matter.erb
|
||||
test/helper.rb
|
||||
test/source/+/foo.md
|
||||
test/source/.htaccess
|
||||
test/source/_config.dev.toml
|
||||
test/source/_data/languages.yml
|
||||
test/source/_data/members.yaml
|
||||
test/source/_data/products.yml
|
||||
test/source/_includes/params.html
|
||||
test/source/_includes/sig.markdown
|
||||
test/source/_layouts/default.html
|
||||
test/source/_layouts/post/simple.html
|
||||
test/source/_layouts/simple.html
|
||||
test/source/_plugins/dummy.rb
|
||||
test/source/_posts/2008-02-02-not-published.textile
|
||||
test/source/_posts/2008-02-02-published.textile
|
||||
test/source/_posts/2008-10-18-foo-bar.textile
|
||||
test/source/_posts/2008-11-21-complex.textile
|
||||
test/source/_posts/2008-12-03-permalinked-post.textile
|
||||
test/source/_posts/2008-12-13-include.markdown
|
||||
test/source/_posts/2009-01-27-array-categories.textile
|
||||
test/source/_posts/2009-01-27-categories.textile
|
||||
test/source/_posts/2009-01-27-category.textile
|
||||
test/source/_posts/2009-01-27-empty-categories.textile
|
||||
test/source/_posts/2009-01-27-empty-category.textile
|
||||
test/source/_posts/2009-03-12-hash-#1.markdown
|
||||
test/source/_posts/2009-05-18-empty-tag.textile
|
||||
test/source/_posts/2009-05-18-empty-tags.textile
|
||||
test/source/_posts/2009-05-18-tag.textile
|
||||
test/source/_posts/2009-05-18-tags.textile
|
||||
test/source/_posts/2009-06-22-empty-yaml.textile
|
||||
test/source/_posts/2009-06-22-no-yaml.textile
|
||||
test/source/_posts/2010-01-08-triple-dash.markdown
|
||||
test/source/_posts/2010-01-09-date-override.textile
|
||||
test/source/_posts/2010-01-09-time-override.textile
|
||||
test/source/_posts/2010-01-09-timezone-override.textile
|
||||
test/source/_posts/2010-01-16-override-data.textile
|
||||
test/source/_posts/2011-04-12-md-extension.md
|
||||
test/source/_posts/2011-04-12-text-extension.text
|
||||
test/source/_posts/2013-01-02-post-excerpt.markdown
|
||||
test/source/_posts/2013-01-12-nil-layout.textile
|
||||
test/source/_posts/2013-01-12-no-layout.textile
|
||||
test/source/_posts/2013-03-19-not-a-post.markdown/.gitkeep
|
||||
test/source/_posts/2013-04-11-custom-excerpt.markdown
|
||||
test/source/_posts/2013-05-10-number-category.textile
|
||||
test/source/_posts/2013-07-22-post-excerpt-with-layout.markdown
|
||||
test/source/_posts/2013-08-01-mkdn-extension.mkdn
|
||||
test/source/_posts/es/2008-11-21-nested.textile
|
||||
test/source/about.html
|
||||
test/source/category/_posts/2008-9-23-categories.textile
|
||||
test/source/contacts.html
|
||||
test/source/contacts/bar.html
|
||||
test/source/contacts/index.html
|
||||
test/source/css/screen.css
|
||||
test/source/deal.with.dots.html
|
||||
test/source/foo/_posts/bar/2008-12-12-topical-post.textile
|
||||
test/source/index.html
|
||||
test/source/products.yml
|
||||
test/source/sitemap.xml
|
||||
test/source/symlink-test/_data
|
||||
test/source/symlink-test/symlinked-dir
|
||||
test/source/symlink-test/symlinked-file
|
||||
test/source/win/_posts/2009-05-24-yaml-linebreak.markdown
|
||||
test/source/z_category/_posts/2008-9-23-categories.textile
|
||||
test/suite.rb
|
||||
test/test_command.rb
|
||||
test/test_configuration.rb
|
||||
test/test_convertible.rb
|
||||
test/test_core_ext.rb
|
||||
test/test_entry_filter.rb
|
||||
test/test_excerpt.rb
|
||||
test/test_filters.rb
|
||||
test/test_generated_site.rb
|
||||
test/test_kramdown.rb
|
||||
test/test_new_command.rb
|
||||
test/test_page.rb
|
||||
test/test_pager.rb
|
||||
test/test_post.rb
|
||||
test/test_rdiscount.rb
|
||||
test/test_redcarpet.rb
|
||||
test/test_redcloth.rb
|
||||
test/test_related_posts.rb
|
||||
test/test_site.rb
|
||||
test/test_tags.rb
|
||||
test/test_url.rb
|
||||
]
|
||||
# = MANIFEST =
|
||||
|
||||
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
||||
end
|
||||
|
||||
209
lib/jekyll.rb
209
lib/jekyll.rb
@@ -18,150 +18,41 @@ require 'rubygems'
|
||||
# stdlib
|
||||
require 'fileutils'
|
||||
require 'time'
|
||||
require 'safe_yaml'
|
||||
require 'English'
|
||||
require 'pathname'
|
||||
require 'logger'
|
||||
require 'set'
|
||||
|
||||
# 3rd party
|
||||
require 'safe_yaml/load'
|
||||
require 'liquid'
|
||||
require 'kramdown'
|
||||
require 'maruku'
|
||||
require 'colorator'
|
||||
require 'toml'
|
||||
|
||||
SafeYAML::OPTIONS[:suppress_warnings] = true
|
||||
Liquid::Template.error_mode = :strict
|
||||
# internal requires
|
||||
require 'jekyll/core_ext'
|
||||
require 'jekyll/stevenson'
|
||||
require 'jekyll/deprecator'
|
||||
require 'jekyll/configuration'
|
||||
require 'jekyll/site'
|
||||
require 'jekyll/convertible'
|
||||
require 'jekyll/url'
|
||||
require 'jekyll/layout'
|
||||
require 'jekyll/page'
|
||||
require 'jekyll/post'
|
||||
require 'jekyll/excerpt'
|
||||
require 'jekyll/draft'
|
||||
require 'jekyll/filters'
|
||||
require 'jekyll/static_file'
|
||||
require 'jekyll/errors'
|
||||
require 'jekyll/related_posts'
|
||||
require 'jekyll/cleaner'
|
||||
require 'jekyll/entry_filter'
|
||||
|
||||
module Jekyll
|
||||
|
||||
# internal requires
|
||||
autoload :Cleaner, 'jekyll/cleaner'
|
||||
autoload :Collection, 'jekyll/collection'
|
||||
autoload :Configuration, 'jekyll/configuration'
|
||||
autoload :Convertible, 'jekyll/convertible'
|
||||
autoload :Deprecator, 'jekyll/deprecator'
|
||||
autoload :Document, 'jekyll/document'
|
||||
autoload :Draft, 'jekyll/draft'
|
||||
autoload :EntryFilter, 'jekyll/entry_filter'
|
||||
autoload :Errors, 'jekyll/errors'
|
||||
autoload :Excerpt, 'jekyll/excerpt'
|
||||
autoload :External, 'jekyll/external'
|
||||
autoload :Filters, 'jekyll/filters'
|
||||
autoload :FrontmatterDefaults, 'jekyll/frontmatter_defaults'
|
||||
autoload :Layout, 'jekyll/layout'
|
||||
autoload :LayoutReader, 'jekyll/layout_reader'
|
||||
autoload :LogAdapter, 'jekyll/log_adapter'
|
||||
autoload :Metadata, 'jekyll/metadata'
|
||||
autoload :Page, 'jekyll/page'
|
||||
autoload :PluginManager, 'jekyll/plugin_manager'
|
||||
autoload :Post, 'jekyll/post'
|
||||
autoload :Publisher, 'jekyll/publisher'
|
||||
autoload :RelatedPosts, 'jekyll/related_posts'
|
||||
autoload :Renderer, 'jekyll/renderer'
|
||||
autoload :Site, 'jekyll/site'
|
||||
autoload :StaticFile, 'jekyll/static_file'
|
||||
autoload :Stevenson, 'jekyll/stevenson'
|
||||
autoload :URL, 'jekyll/url'
|
||||
autoload :Utils, 'jekyll/utils'
|
||||
autoload :VERSION, 'jekyll/version'
|
||||
|
||||
# extensions
|
||||
require 'jekyll/plugin'
|
||||
require 'jekyll/converter'
|
||||
require 'jekyll/generator'
|
||||
require 'jekyll/command'
|
||||
require 'jekyll/liquid_extensions'
|
||||
|
||||
class << self
|
||||
# Public: Tells you which Jekyll environment you are building in so you can skip tasks
|
||||
# if you need to. This is useful when doing expensive compression tasks on css and
|
||||
# images and allows you to skip that when working in development.
|
||||
|
||||
def env
|
||||
ENV["JEKYLL_ENV"] || "development"
|
||||
end
|
||||
|
||||
# Public: Generate a Jekyll configuration Hash by merging the default
|
||||
# options with anything in _config.yml, and adding the given options on top.
|
||||
#
|
||||
# override - A Hash of config directives that override any options in both
|
||||
# the defaults and the config file. See Jekyll::Configuration::DEFAULTS for a
|
||||
# list of option names and their defaults.
|
||||
#
|
||||
# Returns the final configuration Hash.
|
||||
def configuration(override = Hash.new)
|
||||
config = Configuration[Configuration::DEFAULTS]
|
||||
override = Configuration[override].stringify_keys
|
||||
unless override.delete('skip_config_files')
|
||||
config = config.read_config_files(config.config_files(override))
|
||||
end
|
||||
|
||||
# Merge DEFAULTS < _config.yml < override
|
||||
config = Utils.deep_merge_hashes(config, override).stringify_keys
|
||||
set_timezone(config['timezone']) if config['timezone']
|
||||
|
||||
config
|
||||
end
|
||||
|
||||
# Public: Set the TZ environment variable to use the timezone specified
|
||||
#
|
||||
# timezone - the IANA Time Zone
|
||||
#
|
||||
# Returns nothing
|
||||
def set_timezone(timezone)
|
||||
ENV['TZ'] = timezone
|
||||
end
|
||||
|
||||
# Public: Fetch the logger instance for this Jekyll process.
|
||||
#
|
||||
# Returns the LogAdapter instance.
|
||||
def logger
|
||||
@logger ||= LogAdapter.new(Stevenson.new, (ENV["JEKYLL_LOG_LEVEL"] || :info).to_sym)
|
||||
end
|
||||
|
||||
# Public: Set the log writer.
|
||||
# New log writer must respond to the same methods
|
||||
# as Ruby's interal Logger.
|
||||
#
|
||||
# writer - the new Logger-compatible log transport
|
||||
#
|
||||
# Returns the new logger.
|
||||
def logger=(writer)
|
||||
@logger = LogAdapter.new(writer)
|
||||
end
|
||||
|
||||
# Public: An array of sites
|
||||
#
|
||||
# Returns the Jekyll sites created.
|
||||
def sites
|
||||
@sites ||= []
|
||||
end
|
||||
|
||||
# Public: Ensures the questionable path is prefixed with the base directory
|
||||
# and prepends the questionable path with the base directory if false.
|
||||
#
|
||||
# base_directory - the directory with which to prefix the questionable path
|
||||
# questionable_path - the path we're unsure about, and want prefixed
|
||||
#
|
||||
# Returns the sanitized path.
|
||||
def sanitized_path(base_directory, questionable_path)
|
||||
return base_directory if base_directory.eql?(questionable_path)
|
||||
|
||||
clean_path = File.expand_path(questionable_path, "/")
|
||||
clean_path = clean_path.sub(/\A\w\:\//, '/')
|
||||
|
||||
unless clean_path.start_with?(base_directory.sub(/\A\w\:\//, '/'))
|
||||
File.join(base_directory, clean_path)
|
||||
else
|
||||
clean_path
|
||||
end
|
||||
end
|
||||
|
||||
# Conditional optimizations
|
||||
Jekyll::External.require_if_present('liquid-c')
|
||||
|
||||
end
|
||||
end
|
||||
# extensions
|
||||
require 'jekyll/plugin'
|
||||
require 'jekyll/converter'
|
||||
require 'jekyll/generator'
|
||||
require 'jekyll/command'
|
||||
|
||||
require_all 'jekyll/commands'
|
||||
require_all 'jekyll/converters'
|
||||
@@ -169,11 +60,41 @@ require_all 'jekyll/converters/markdown'
|
||||
require_all 'jekyll/generators'
|
||||
require_all 'jekyll/tags'
|
||||
|
||||
# Eventually remove these for 3.0 as non-core
|
||||
Jekyll::External.require_with_graceful_fail(%w[
|
||||
toml
|
||||
jekyll-paginate
|
||||
jekyll-gist
|
||||
jekyll-coffeescript
|
||||
jekyll-sass-converter
|
||||
])
|
||||
SafeYAML::OPTIONS[:suppress_warnings] = true
|
||||
|
||||
module Jekyll
|
||||
VERSION = '1.4.1'
|
||||
|
||||
# Public: Generate a Jekyll configuration Hash by merging the default
|
||||
# options with anything in _config.yml, and adding the given options on top.
|
||||
#
|
||||
# override - A Hash of config directives that override any options in both
|
||||
# the defaults and the config file. See Jekyll::Configuration::DEFAULTS for a
|
||||
# list of option names and their defaults.
|
||||
#
|
||||
# Returns the final configuration Hash.
|
||||
def self.configuration(override)
|
||||
config = Configuration[Configuration::DEFAULTS]
|
||||
override = Configuration[override].stringify_keys
|
||||
config = config.read_config_files(config.config_files(override))
|
||||
|
||||
# Merge DEFAULTS < _config.yml < override
|
||||
config = config.deep_merge(override).stringify_keys
|
||||
set_timezone(config['timezone']) if config['timezone']
|
||||
|
||||
config
|
||||
end
|
||||
|
||||
# Static: Set the TZ environment variable to use the timezone specified
|
||||
#
|
||||
# timezone - the IANA Time Zone
|
||||
#
|
||||
# Returns nothing
|
||||
def self.set_timezone(timezone)
|
||||
ENV['TZ'] = timezone
|
||||
end
|
||||
|
||||
def self.logger
|
||||
@logger ||= Stevenson.new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,8 +4,6 @@ module Jekyll
|
||||
class Site
|
||||
# Handles the cleanup of a site's destination before it is built.
|
||||
class Cleaner
|
||||
attr_reader :site
|
||||
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
@@ -13,7 +11,6 @@ module Jekyll
|
||||
# Cleans up the site's destination directory
|
||||
def cleanup!
|
||||
FileUtils.rm_rf(obsolete_files)
|
||||
FileUtils.rm_rf(metadata_file) if @site.full_rebuild?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -25,20 +22,13 @@ module Jekyll
|
||||
(existing_files - new_files - new_dirs + replaced_files).to_a
|
||||
end
|
||||
|
||||
# Private: The metadata file storing dependency tree and build history
|
||||
#
|
||||
# Returns an Array with the metdata file as the only item
|
||||
def metadata_file
|
||||
[site.metadata.metadata_file]
|
||||
end
|
||||
|
||||
# Private: The list of existing files, apart from those included in keep_files and hidden files.
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def existing_files
|
||||
files = Set.new
|
||||
Dir.glob(site.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex || keep_dirs.include?(file)
|
||||
Dir.glob(File.join(@site.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex
|
||||
end
|
||||
files
|
||||
end
|
||||
@@ -48,7 +38,7 @@ module Jekyll
|
||||
# Returns a Set with the file paths
|
||||
def new_files
|
||||
files = Set.new
|
||||
site.each_site_file { |item| files << item.destination(site.dest) }
|
||||
@site.each_site_file { |item| files << item.destination(@site.dest) }
|
||||
files
|
||||
end
|
||||
|
||||
@@ -57,19 +47,7 @@ module Jekyll
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def new_dirs
|
||||
new_files.map { |file| parent_dirs(file) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: The list of parent directories of a given file
|
||||
#
|
||||
# Returns an Array with the directory paths
|
||||
def parent_dirs(file)
|
||||
parent_dir = File.dirname(file)
|
||||
if parent_dir == site.dest
|
||||
[]
|
||||
else
|
||||
[parent_dir] + parent_dirs(parent_dir)
|
||||
end
|
||||
new_files.map { |file| File.dirname(file) }.to_set
|
||||
end
|
||||
|
||||
# Private: The list of existing files that will be replaced by a directory during build
|
||||
@@ -79,14 +57,6 @@ module Jekyll
|
||||
new_dirs.select { |dir| File.file?(dir) }.to_set
|
||||
end
|
||||
|
||||
# Private: The list of directories that need to be kept because they are parent directories
|
||||
# of files specified in keep_files
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def keep_dirs
|
||||
site.keep_files.map { |file| parent_dirs(site.in_dest_dir(file)) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: Creates a regular expression from the config's keep_files array
|
||||
#
|
||||
# Examples
|
||||
@@ -94,7 +64,7 @@ module Jekyll
|
||||
#
|
||||
# Returns the regular expression
|
||||
def keep_file_regex
|
||||
or_list = site.keep_files.join("|")
|
||||
or_list = @site.keep_files.join("|")
|
||||
pattern = "\/(#{or_list.gsub(".", "\.")})"
|
||||
Regexp.new pattern
|
||||
end
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
module Jekyll
|
||||
class Collection
|
||||
attr_reader :site, :label, :metadata
|
||||
|
||||
# Create a new Collection.
|
||||
#
|
||||
# site - the site to which this collection belongs.
|
||||
# label - the name of the collection
|
||||
#
|
||||
# Returns nothing.
|
||||
def initialize(site, label)
|
||||
@site = site
|
||||
@label = sanitize_label(label)
|
||||
@metadata = extract_metadata
|
||||
end
|
||||
|
||||
# Fetch the Documents in this collection.
|
||||
# Defaults to an empty array if no documents have been read in.
|
||||
#
|
||||
# Returns an array of Jekyll::Document objects.
|
||||
def docs
|
||||
@docs ||= []
|
||||
end
|
||||
|
||||
# Fetch the static files in this collection.
|
||||
# Defaults to an empty array if no static files have been read in.
|
||||
#
|
||||
# Returns an array of Jekyll::StaticFile objects.
|
||||
def files
|
||||
@files ||= []
|
||||
end
|
||||
|
||||
# Read the allowed documents into the collection's array of docs.
|
||||
#
|
||||
# Returns the sorted array of docs.
|
||||
def read
|
||||
filtered_entries.each do |file_path|
|
||||
full_path = collection_dir(file_path)
|
||||
next if File.directory?(full_path)
|
||||
if Utils.has_yaml_header? full_path
|
||||
doc = Jekyll::Document.new(full_path, { site: site, collection: self })
|
||||
doc.read
|
||||
docs << doc if site.publisher.publish?(doc)
|
||||
else
|
||||
relative_dir = Jekyll.sanitized_path(relative_directory, File.dirname(file_path)).chomp("/.")
|
||||
files << StaticFile.new(site, site.source, relative_dir, File.basename(full_path), self)
|
||||
end
|
||||
end
|
||||
docs.sort!
|
||||
end
|
||||
|
||||
# All the entries in this collection.
|
||||
#
|
||||
# Returns an Array of file paths to the documents in this collection
|
||||
# relative to the collection's directory
|
||||
def entries
|
||||
return Array.new unless exists?
|
||||
@entries ||=
|
||||
Dir.glob(collection_dir("**", "*.*")).map do |entry|
|
||||
entry["#{collection_dir}/"] = ''; entry
|
||||
end
|
||||
end
|
||||
|
||||
# Filtered version of the entries in this collection.
|
||||
# See `Jekyll::EntryFilter#filter` for more information.
|
||||
#
|
||||
# Returns a list of filtered entry paths.
|
||||
def filtered_entries
|
||||
return Array.new unless exists?
|
||||
@filtered_entries ||=
|
||||
Dir.chdir(directory) do
|
||||
entry_filter.filter(entries).reject do |f|
|
||||
path = collection_dir(f)
|
||||
File.directory?(path) || (File.symlink?(f) && site.safe)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The directory for this Collection, relative to the site source.
|
||||
#
|
||||
# Returns a String containing the directory name where the collection
|
||||
# is stored on the filesystem.
|
||||
def relative_directory
|
||||
@relative_directory ||= "_#{label}"
|
||||
end
|
||||
|
||||
# The full path to the directory containing the collection.
|
||||
#
|
||||
# Returns a String containing th directory name where the collection
|
||||
# is stored on the filesystem.
|
||||
def directory
|
||||
@directory ||= site.in_source_dir(relative_directory)
|
||||
end
|
||||
|
||||
# The full path to the directory containing the collection, with
|
||||
# optional subpaths.
|
||||
#
|
||||
# *files - (optional) any other path pieces relative to the
|
||||
# directory to append to the path
|
||||
#
|
||||
# Returns a String containing th directory name where the collection
|
||||
# is stored on the filesystem.
|
||||
def collection_dir(*files)
|
||||
return directory if files.empty?
|
||||
site.in_source_dir(relative_directory, *files)
|
||||
end
|
||||
|
||||
# Checks whether the directory "exists" for this collection.
|
||||
# The directory must exist on the filesystem and must not be a symlink
|
||||
# if in safe mode.
|
||||
#
|
||||
# Returns false if the directory doesn't exist or if it's a symlink
|
||||
# and we're in safe mode.
|
||||
def exists?
|
||||
File.directory?(directory) && !(File.symlink?(directory) && site.safe)
|
||||
end
|
||||
|
||||
# The entry filter for this collection.
|
||||
# Creates an instance of Jekyll::EntryFilter.
|
||||
#
|
||||
# Returns the instance of Jekyll::EntryFilter for this collection.
|
||||
def entry_filter
|
||||
@entry_filter ||= Jekyll::EntryFilter.new(site, relative_directory)
|
||||
end
|
||||
|
||||
# An inspect string.
|
||||
#
|
||||
# Returns the inspect string
|
||||
def inspect
|
||||
"#<Jekyll::Collection @label=#{label} docs=#{docs}>"
|
||||
end
|
||||
|
||||
# Produce a sanitized label name
|
||||
# Label names may not contain anything but alphanumeric characters,
|
||||
# underscores, and hyphens.
|
||||
#
|
||||
# label - the possibly-unsafe label
|
||||
#
|
||||
# Returns a sanitized version of the label.
|
||||
def sanitize_label(label)
|
||||
label.gsub(/[^a-z0-9_\-\.]/i, '')
|
||||
end
|
||||
|
||||
# Produce a representation of this Collection for use in Liquid.
|
||||
# Exposes two attributes:
|
||||
# - label
|
||||
# - docs
|
||||
#
|
||||
# Returns a representation of this collection for use in Liquid.
|
||||
def to_liquid
|
||||
metadata.merge({
|
||||
"label" => label,
|
||||
"docs" => docs,
|
||||
"files" => files,
|
||||
"directory" => directory,
|
||||
"output" => write?,
|
||||
"relative_directory" => relative_directory
|
||||
})
|
||||
end
|
||||
|
||||
# Whether the collection's documents ought to be written as individual
|
||||
# files in the output.
|
||||
#
|
||||
# Returns true if the 'write' metadata is true, false otherwise.
|
||||
def write?
|
||||
!!metadata['output']
|
||||
end
|
||||
|
||||
# The URL template to render collection's documents at.
|
||||
#
|
||||
# Returns the URL template to render collection's documents at.
|
||||
def url_template
|
||||
metadata.fetch('permalink', "/:collection/:path:output_ext")
|
||||
end
|
||||
|
||||
# Extract options for this collection from the site configuration.
|
||||
#
|
||||
# Returns the metadata for this collection
|
||||
def extract_metadata
|
||||
if site.config['collections'].is_a?(Hash)
|
||||
site.config['collections'][label] || Hash.new
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,67 +1,27 @@
|
||||
module Jekyll
|
||||
class Command
|
||||
|
||||
class << self
|
||||
|
||||
# A list of subclasses of Jekyll::Command
|
||||
def subclasses
|
||||
@subclasses ||= []
|
||||
def self.globs(source, destination)
|
||||
Dir.chdir(source) do
|
||||
dirs = Dir['*'].select { |x| File.directory?(x) }
|
||||
dirs -= [destination, File.expand_path(destination), File.basename(destination)]
|
||||
dirs = dirs.map { |x| "#{x}/**/*" }
|
||||
dirs += ['*']
|
||||
end
|
||||
|
||||
# Keep a list of subclasses of Jekyll::Command every time it's inherited
|
||||
# Called automatically.
|
||||
#
|
||||
# base - the subclass
|
||||
#
|
||||
# Returns nothing
|
||||
def inherited(base)
|
||||
subclasses << base
|
||||
super(base)
|
||||
end
|
||||
|
||||
# Run Site#process and catch errors
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
#
|
||||
# Returns nothing
|
||||
def process_site(site)
|
||||
site.process
|
||||
rescue Jekyll::Errors::FatalException => e
|
||||
Jekyll.logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
||||
Jekyll.logger.error "", "------------------------------------"
|
||||
Jekyll.logger.error "", e.message
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# Create a full Jekyll configuration with the options passed in as overrides
|
||||
#
|
||||
# options - the configuration overrides
|
||||
#
|
||||
# Returns a full Jekyll configuration
|
||||
def configuration_from_options(options)
|
||||
Jekyll.configuration(options)
|
||||
end
|
||||
|
||||
# Add common options to a command for building configuration
|
||||
#
|
||||
# c - the Jekyll::Command to add these options to
|
||||
#
|
||||
# Returns nothing
|
||||
def add_build_options(c)
|
||||
c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||
c.option 'future', '--future', 'Publishes posts with a future date'
|
||||
c.option 'limit_posts', '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
|
||||
c.option 'watch', '-w', '--[no-]watch', 'Watch for changes and rebuild'
|
||||
c.option 'force_polling', '--force_polling', 'Force watch to use polling'
|
||||
c.option 'lsi', '--lsi', 'Use LSI for improved related posts'
|
||||
c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder'
|
||||
c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished'
|
||||
c.option 'quiet', '-q', '--quiet', 'Silence output.'
|
||||
c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
|
||||
c.option 'full_rebuild', '-f', '--full-rebuild', 'Disable incremental rebuild.'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Static: Run Site#process and catch errors
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
#
|
||||
# Returns nothing
|
||||
def self.process_site(site)
|
||||
site.process
|
||||
rescue Jekyll::FatalException => e
|
||||
puts
|
||||
Jekyll.logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
||||
Jekyll.logger.error "", "------------------------------------"
|
||||
Jekyll.logger.error "", e.message
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,77 +1,70 @@
|
||||
module Jekyll
|
||||
module Commands
|
||||
class Build < Command
|
||||
def self.process(options)
|
||||
site = Jekyll::Site.new(options)
|
||||
|
||||
class << self
|
||||
self.build(site, options)
|
||||
self.watch(site, options) if options['watch']
|
||||
end
|
||||
|
||||
# Create the Mercenary command for the Jekyll CLI for this Command
|
||||
def init_with_program(prog)
|
||||
prog.command(:build) do |c|
|
||||
c.syntax 'build [options]'
|
||||
c.description 'Build your site'
|
||||
c.alias :b
|
||||
# Private: Build the site from source into destination.
|
||||
#
|
||||
# site - A Jekyll::Site instance
|
||||
# options - A Hash of options passed to the command
|
||||
#
|
||||
# Returns nothing.
|
||||
def self.build(site, options)
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
Jekyll.logger.info "Source:", source
|
||||
Jekyll.logger.info "Destination:", destination
|
||||
print Jekyll.logger.formatted_topic "Generating..."
|
||||
self.process_site(site)
|
||||
puts "done."
|
||||
end
|
||||
|
||||
add_build_options(c)
|
||||
# Private: Watch for file changes and rebuild the site.
|
||||
#
|
||||
# site - A Jekyll::Site instance
|
||||
# options - A Hash of options passed to the command
|
||||
#
|
||||
# Returns nothing.
|
||||
def self.watch(site, options)
|
||||
require 'listen'
|
||||
|
||||
c.action do |args, options|
|
||||
options["serving"] = false
|
||||
Jekyll::Commands::Build.process(options)
|
||||
end
|
||||
end
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
|
||||
begin
|
||||
dest = Pathname.new(destination).relative_path_from(Pathname.new(source)).to_s
|
||||
ignored = Regexp.new(Regexp.escape(dest))
|
||||
rescue ArgumentError
|
||||
# Destination is outside the source, no need to ignore it.
|
||||
ignored = nil
|
||||
end
|
||||
|
||||
# Build your jekyll site
|
||||
# Continuously watch if `watch` is set to true in the config.
|
||||
def process(options)
|
||||
Jekyll.logger.log_level = :error if options['quiet']
|
||||
Jekyll.logger.info "Auto-regeneration:", "enabled"
|
||||
|
||||
options = configuration_from_options(options)
|
||||
site = Jekyll::Site.new(options)
|
||||
listener = Listen::Listener.new(source, :ignore => ignored) do |modified, added, removed|
|
||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
n = modified.length + added.length + removed.length
|
||||
print Jekyll.logger.formatted_topic("Regenerating:") + "#{n} files at #{t} "
|
||||
self.process_site(site)
|
||||
puts "...done."
|
||||
end
|
||||
listener.start
|
||||
|
||||
if options.fetch('skip_initial_build', false)
|
||||
Jekyll.logger.warn "Build Warning:", "Skipping the initial build. This may result in an out-of-date site."
|
||||
else
|
||||
build(site, options)
|
||||
unless options['serving']
|
||||
trap("INT") do
|
||||
listener.stop
|
||||
puts " Halting auto-regeneration."
|
||||
exit 0
|
||||
end
|
||||
|
||||
if options.fetch('watch', false)
|
||||
watch(site, options)
|
||||
else
|
||||
Jekyll.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
|
||||
end
|
||||
loop { sleep 1000 }
|
||||
end
|
||||
|
||||
# Build your Jekyll site.
|
||||
#
|
||||
# site - the Jekyll::Site instance to build
|
||||
# options - A Hash of options passed to the command
|
||||
#
|
||||
# Returns nothing.
|
||||
def build(site, options)
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
full_build = options['full_rebuild']
|
||||
Jekyll.logger.info "Source:", source
|
||||
Jekyll.logger.info "Destination:", destination
|
||||
Jekyll.logger.info "Incremental build:", (full_build ? "disabled" : "enabled")
|
||||
Jekyll.logger.info "Generating..."
|
||||
process_site(site)
|
||||
Jekyll.logger.info "", "done."
|
||||
end
|
||||
|
||||
# Private: Watch for file changes and rebuild the site.
|
||||
#
|
||||
# site - A Jekyll::Site instance
|
||||
# options - A Hash of options passed to the command
|
||||
#
|
||||
# Returns nothing.
|
||||
def watch(site, options)
|
||||
External.require_with_graceful_fail 'jekyll-watch'
|
||||
Jekyll::Watcher.watch(options)
|
||||
end
|
||||
|
||||
end # end of class << self
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
module Jekyll
|
||||
module Commands
|
||||
class Clean < Command
|
||||
class << self
|
||||
|
||||
def init_with_program(prog)
|
||||
prog.command(:clean) do |c|
|
||||
c.syntax 'clean [subcommand]'
|
||||
c.description 'Clean the site (removes site output and metadata file) without building.'
|
||||
|
||||
c.action do |args, _|
|
||||
Jekyll::Commands::Clean.process({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def process(options)
|
||||
options = configuration_from_options(options)
|
||||
destination = options['destination']
|
||||
metadata_file = File.join(options['source'], '.jekyll-metadata')
|
||||
|
||||
if File.directory? destination
|
||||
Jekyll.logger.info "Cleaning #{destination}..."
|
||||
FileUtils.rm_rf(destination)
|
||||
Jekyll.logger.info "", "done."
|
||||
else
|
||||
Jekyll.logger.info "Nothing to do for #{destination}."
|
||||
end
|
||||
|
||||
if File.file? metadata_file
|
||||
Jekyll.logger.info "Removing #{metadata_file}..."
|
||||
FileUtils.rm_rf(metadata_file)
|
||||
Jekyll.logger.info "", "done."
|
||||
else
|
||||
Jekyll.logger.info "Nothing to do for #{metadata_file}."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,23 +2,8 @@ module Jekyll
|
||||
module Commands
|
||||
class Doctor < Command
|
||||
class << self
|
||||
|
||||
def init_with_program(prog)
|
||||
prog.command(:doctor) do |c|
|
||||
c.syntax 'doctor'
|
||||
c.description 'Search site and print specific deprecation warnings'
|
||||
c.alias(:hyde)
|
||||
|
||||
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||
|
||||
c.action do |args, options|
|
||||
Jekyll::Commands::Doctor.process(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def process(options)
|
||||
site = Jekyll::Site.new(configuration_from_options(options))
|
||||
site = Jekyll::Site.new(options)
|
||||
site.read
|
||||
|
||||
if healthy?(site)
|
||||
@@ -41,7 +26,7 @@ module Jekyll
|
||||
if page.uses_relative_permalinks
|
||||
Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" +
|
||||
" permalinks which will be deprecated in" +
|
||||
" Jekyll v2.0.0 and beyond."
|
||||
" Jekyll v1.2 and beyond."
|
||||
contains_deprecated_pages = true
|
||||
end
|
||||
end
|
||||
@@ -76,9 +61,7 @@ module Jekyll
|
||||
end
|
||||
urls
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
module Jekyll
|
||||
module Commands
|
||||
class Help < Command
|
||||
class << self
|
||||
|
||||
def init_with_program(prog)
|
||||
prog.command(:help) do |c|
|
||||
c.syntax 'help [subcommand]'
|
||||
c.description 'Show the help message, optionally for a given subcommand.'
|
||||
|
||||
c.action do |args, _|
|
||||
cmd = (args.first || "").to_sym
|
||||
if args.empty?
|
||||
puts prog
|
||||
elsif prog.has_command? cmd
|
||||
puts prog.commands[cmd]
|
||||
else
|
||||
invalid_command(prog, cmd)
|
||||
abort
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def invalid_command(prog, cmd)
|
||||
Jekyll.logger.error "Error:", "Hmm... we don't know what the '#{cmd}' command is."
|
||||
Jekyll.logger.info "Valid commands:", prog.commands.keys.join(", ")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,80 +3,65 @@ require 'erb'
|
||||
module Jekyll
|
||||
module Commands
|
||||
class New < Command
|
||||
class << self
|
||||
def init_with_program(prog)
|
||||
prog.command(:new) do |c|
|
||||
c.syntax 'new PATH'
|
||||
c.description 'Creates a new Jekyll site scaffold in PATH'
|
||||
def self.process(args, options = {})
|
||||
raise ArgumentError.new('You must specify a path.') if args.empty?
|
||||
|
||||
c.option 'force', '--force', 'Force creation even if PATH already exists'
|
||||
c.option 'blank', '--blank', 'Creates scaffolding but with empty files'
|
||||
|
||||
c.action do |args, options|
|
||||
Jekyll::Commands::New.process(args, options)
|
||||
end
|
||||
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
||||
FileUtils.mkdir_p new_blog_path
|
||||
if preserve_source_location?(new_blog_path, options)
|
||||
Jekyll.logger.error "Conflict:", "#{new_blog_path} exists and is not empty."
|
||||
exit(1)
|
||||
end
|
||||
|
||||
if options[:blank]
|
||||
create_blank_site new_blog_path
|
||||
else
|
||||
create_sample_files new_blog_path
|
||||
|
||||
File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f|
|
||||
f.write(self.scaffold_post_content)
|
||||
end
|
||||
end
|
||||
|
||||
def process(args, options = {})
|
||||
raise ArgumentError.new('You must specify a path.') if args.empty?
|
||||
puts "New jekyll site installed in #{new_blog_path}."
|
||||
end
|
||||
|
||||
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
||||
FileUtils.mkdir_p new_blog_path
|
||||
if preserve_source_location?(new_blog_path, options)
|
||||
Jekyll.logger.abort_with "Conflict:", "#{new_blog_path} exists and is not empty."
|
||||
end
|
||||
|
||||
if options["blank"]
|
||||
create_blank_site new_blog_path
|
||||
else
|
||||
create_sample_files new_blog_path
|
||||
|
||||
File.open(File.expand_path(initialized_post_name, new_blog_path), "w") do |f|
|
||||
f.write(scaffold_post_content)
|
||||
end
|
||||
end
|
||||
|
||||
Jekyll.logger.info "New jekyll site installed in #{new_blog_path}."
|
||||
def self.create_blank_site(path)
|
||||
Dir.chdir(path) do
|
||||
FileUtils.mkdir(%w(_layouts _posts _drafts))
|
||||
FileUtils.touch("index.html")
|
||||
end
|
||||
end
|
||||
|
||||
def create_blank_site(path)
|
||||
Dir.chdir(path) do
|
||||
FileUtils.mkdir(%w(_layouts _posts _drafts))
|
||||
FileUtils.touch("index.html")
|
||||
end
|
||||
end
|
||||
def self.scaffold_post_content
|
||||
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
||||
end
|
||||
|
||||
def scaffold_post_content
|
||||
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
||||
end
|
||||
# Internal: Gets the filename of the sample post to be created
|
||||
#
|
||||
# Returns the filename of the sample post, as a String
|
||||
def self.initialized_post_name
|
||||
"_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown"
|
||||
end
|
||||
|
||||
# Internal: Gets the filename of the sample post to be created
|
||||
#
|
||||
# Returns the filename of the sample post, as a String
|
||||
def initialized_post_name
|
||||
"_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown"
|
||||
end
|
||||
private
|
||||
|
||||
private
|
||||
def self.preserve_source_location?(path, options)
|
||||
!options[:force] && !Dir["#{path}/**/*"].empty?
|
||||
end
|
||||
|
||||
def preserve_source_location?(path, options)
|
||||
!options["force"] && !Dir["#{path}/**/*"].empty?
|
||||
end
|
||||
def self.create_sample_files(path)
|
||||
FileUtils.cp_r site_template + '/.', path
|
||||
FileUtils.rm File.expand_path(scaffold_path, path)
|
||||
end
|
||||
|
||||
def create_sample_files(path)
|
||||
FileUtils.cp_r site_template + '/.', path
|
||||
FileUtils.rm File.expand_path(scaffold_path, path)
|
||||
end
|
||||
def self.site_template
|
||||
File.expand_path("../../site_template", File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
def site_template
|
||||
File.expand_path("../../site_template", File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
def scaffold_path
|
||||
"_posts/0000-00-00-welcome-to-jekyll.markdown.erb"
|
||||
end
|
||||
end
|
||||
def self.scaffold_path
|
||||
"_posts/0000-00-00-welcome-to-jekyll.markdown.erb"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,135 +2,64 @@
|
||||
module Jekyll
|
||||
module Commands
|
||||
class Serve < Command
|
||||
def self.process(options)
|
||||
require 'webrick'
|
||||
include WEBrick
|
||||
|
||||
class << self
|
||||
destination = options['destination']
|
||||
|
||||
def init_with_program(prog)
|
||||
prog.command(:serve) do |c|
|
||||
c.syntax 'serve [options]'
|
||||
c.description 'Serve your site locally'
|
||||
c.alias :server
|
||||
c.alias :s
|
||||
|
||||
add_build_options(c)
|
||||
|
||||
c.option 'detach', '-B', '--detach', 'Run the server in the background (detach)'
|
||||
c.option 'port', '-P', '--port [PORT]', 'Port to listen on'
|
||||
c.option 'host', '-H', '--host [HOST]', 'Host to bind to'
|
||||
c.option 'baseurl', '-b', '--baseurl [URL]', 'Base URL'
|
||||
c.option 'skip_initial_build', '--skip-initial-build', 'Skips the initial site build which occurs before the server is started.'
|
||||
|
||||
c.action do |args, options|
|
||||
options["serving"] = true
|
||||
options["watch"] = true unless options.key?("watch")
|
||||
Jekyll::Commands::Build.process(options)
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Boot up a WEBrick server which points to the compiled site's root.
|
||||
def process(options)
|
||||
options = configuration_from_options(options)
|
||||
destination = options['destination']
|
||||
setup(destination)
|
||||
|
||||
s = WEBrick::HTTPServer.new(webrick_options(options))
|
||||
s.unmount("")
|
||||
|
||||
s.mount(
|
||||
options['baseurl'],
|
||||
WEBrick::HTTPServlet::FileHandler,
|
||||
destination,
|
||||
file_handler_options
|
||||
)
|
||||
|
||||
Jekyll.logger.info "Server address:", server_address(s, options)
|
||||
|
||||
if options['detach'] # detach the server
|
||||
pid = Process.fork { s.start }
|
||||
Process.detach(pid)
|
||||
Jekyll.logger.info "Server detached with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
|
||||
else # create a new server thread, then join it with current terminal
|
||||
t = Thread.new { s.start }
|
||||
trap("INT") { s.shutdown }
|
||||
t.join
|
||||
end
|
||||
end
|
||||
|
||||
def setup(destination)
|
||||
require 'webrick'
|
||||
|
||||
FileUtils.mkdir_p(destination)
|
||||
|
||||
# monkey patch WEBrick using custom 404 page (/404.html)
|
||||
if File.exist?(File.join(destination, '404.html'))
|
||||
WEBrick::HTTPResponse.class_eval do
|
||||
def create_error_page
|
||||
@header['content-type'] = "text/html; charset=UTF-8"
|
||||
@body = IO.read(File.join(@config[:DocumentRoot], '404.html'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def webrick_options(config)
|
||||
opts = {
|
||||
:BindAddress => config['host'],
|
||||
:DirectoryIndex => %w(index.html index.htm index.cgi index.rhtml index.xml),
|
||||
:DocumentRoot => config['destination'],
|
||||
:DoNotReverseLookup => true,
|
||||
:MimeTypes => mime_types,
|
||||
:Port => config['port'],
|
||||
:StartCallback => start_callback(config['detach'])
|
||||
}
|
||||
|
||||
if config['verbose']
|
||||
opts.merge!({
|
||||
:Logger => WEBrick::Log.new($stdout, WEBrick::Log::DEBUG)
|
||||
})
|
||||
else
|
||||
opts.merge!({
|
||||
:AccessLog => [],
|
||||
:Logger => WEBrick::Log.new([], WEBrick::Log::WARN)
|
||||
})
|
||||
end
|
||||
|
||||
opts
|
||||
end
|
||||
|
||||
def start_callback(detached)
|
||||
unless detached
|
||||
Proc.new { Jekyll.logger.info "Server running...", "press ctrl-c to stop." }
|
||||
end
|
||||
end
|
||||
|
||||
def mime_types
|
||||
mime_types_file = File.expand_path('../mime.types', File.dirname(__FILE__))
|
||||
WEBrick::HTTPUtils::load_mime_types(mime_types_file)
|
||||
end
|
||||
|
||||
def server_address(server, options)
|
||||
baseurl = "#{options['baseurl']}/" if options['baseurl']
|
||||
[
|
||||
"http://",
|
||||
server.config[:BindAddress],
|
||||
":",
|
||||
server.config[:Port],
|
||||
baseurl || ""
|
||||
].map(&:to_s).join("")
|
||||
end
|
||||
FileUtils.mkdir_p(destination)
|
||||
|
||||
# recreate NondisclosureName under utf-8 circumstance
|
||||
def file_handler_options
|
||||
WEBrick::Config::FileHandler.merge({
|
||||
:FancyIndexing => true,
|
||||
:NondisclosureName => ['.ht*','~*']
|
||||
fh_option = WEBrick::Config::FileHandler
|
||||
fh_option[:NondisclosureName] = ['.ht*','~*']
|
||||
|
||||
s = HTTPServer.new(webrick_options(options))
|
||||
|
||||
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option)
|
||||
|
||||
Jekyll.logger.info "Server address:", "http://#{s.config[:BindAddress]}:#{s.config[:Port]}"
|
||||
|
||||
if options['detach'] # detach the server
|
||||
pid = Process.fork { s.start }
|
||||
Process.detach(pid)
|
||||
Jekyll.logger.info "Server detatched with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
|
||||
else # create a new server thread, then join it with current terminal
|
||||
t = Thread.new { s.start }
|
||||
trap("INT") { s.shutdown }
|
||||
t.join()
|
||||
end
|
||||
end
|
||||
|
||||
def self.webrick_options(config)
|
||||
opts = {
|
||||
:Port => config['port'],
|
||||
:BindAddress => config['host'],
|
||||
:MimeTypes => self.mime_types,
|
||||
:DoNotReverseLookup => true,
|
||||
:StartCallback => start_callback(config['detach'])
|
||||
}
|
||||
|
||||
if !config['verbose']
|
||||
opts.merge!({
|
||||
:AccessLog => [],
|
||||
:Logger => Log::new([], Log::WARN)
|
||||
})
|
||||
end
|
||||
|
||||
opts
|
||||
end
|
||||
|
||||
def self.start_callback(detached)
|
||||
unless detached
|
||||
Proc.new { Jekyll.logger.info "Server running...", "press ctrl-c to stop." }
|
||||
end
|
||||
end
|
||||
|
||||
def self.mime_types
|
||||
mime_types_file = File.expand_path('../mime.types', File.dirname(__FILE__))
|
||||
WEBrick::HTTPUtils::load_mime_types(mime_types_file)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,64 +6,50 @@ module Jekyll
|
||||
# Default options. Overridden by values in _config.yml.
|
||||
# Strings rather than symbols are used for compatibility with YAML.
|
||||
DEFAULTS = {
|
||||
# Where things are
|
||||
'source' => Dir.pwd,
|
||||
'destination' => File.join(Dir.pwd, '_site'),
|
||||
'plugins' => '_plugins',
|
||||
'layouts' => '_layouts',
|
||||
'data_source' => '_data',
|
||||
'collections' => nil,
|
||||
|
||||
# Handling Reading
|
||||
'safe' => false,
|
||||
'include' => ['.htaccess'],
|
||||
'exclude' => [],
|
||||
'keep_files' => ['.git','.svn'],
|
||||
'encoding' => 'utf-8',
|
||||
'markdown_ext' => 'markdown,mkdown,mkdn,mkd,md',
|
||||
'textile_ext' => 'textile',
|
||||
'full_rebuild' => false,
|
||||
|
||||
# Filtering Content
|
||||
'show_drafts' => nil,
|
||||
'limit_posts' => 0,
|
||||
'future' => true, # remove and make true just default
|
||||
'unpublished' => false,
|
||||
|
||||
# Plugins
|
||||
'whitelist' => [],
|
||||
'gems' => [],
|
||||
|
||||
# Conversion
|
||||
'markdown' => 'kramdown',
|
||||
'highlighter' => 'pygments',
|
||||
'lsi' => false,
|
||||
'excerpt_separator' => "\n\n",
|
||||
|
||||
# Serving
|
||||
'detach' => false, # default to not detaching the server
|
||||
'port' => '4000',
|
||||
'host' => '127.0.0.1',
|
||||
'baseurl' => '',
|
||||
|
||||
# Backwards-compatibility options
|
||||
'relative_permalinks' => false,
|
||||
|
||||
# Output Configuration
|
||||
'permalink' => 'date',
|
||||
'paginate_path' => '/page:num',
|
||||
'timezone' => nil, # use the local timezone
|
||||
|
||||
'quiet' => false,
|
||||
'defaults' => [],
|
||||
'encoding' => nil, # use the system encoding
|
||||
|
||||
'safe' => false,
|
||||
'detach' => false, # default to not detaching the server
|
||||
'show_drafts' => nil,
|
||||
'limit_posts' => 0,
|
||||
'lsi' => false,
|
||||
'future' => true, # remove and make true just default
|
||||
'pygments' => true,
|
||||
|
||||
'relative_permalinks' => true, # backwards-compatibility with < 1.0
|
||||
# will be set to false once 2.0 hits
|
||||
|
||||
'markdown' => 'maruku',
|
||||
'permalink' => 'date',
|
||||
'baseurl' => '/',
|
||||
'include' => ['.htaccess'],
|
||||
'exclude' => [],
|
||||
'paginate_path' => '/page:num',
|
||||
|
||||
'markdown_ext' => 'markdown,mkd,mkdn,md',
|
||||
'textile_ext' => 'textile',
|
||||
|
||||
'port' => '4000',
|
||||
'host' => '0.0.0.0',
|
||||
|
||||
'excerpt_separator' => "\n\n",
|
||||
|
||||
'maruku' => {
|
||||
'use_tex' => false,
|
||||
'use_divs' => false,
|
||||
'png_engine' => 'blahtex',
|
||||
'png_dir' => 'images/latex',
|
||||
'png_url' => '/images/latex',
|
||||
'fenced_code_blocks' => true
|
||||
'png_url' => '/images/latex'
|
||||
},
|
||||
|
||||
'rdiscount' => {
|
||||
@@ -75,12 +61,12 @@ module Jekyll
|
||||
},
|
||||
|
||||
'kramdown' => {
|
||||
'auto_ids' => true,
|
||||
'footnote_nr' => 1,
|
||||
'entity_output' => 'as_char',
|
||||
'toc_levels' => '1..6',
|
||||
'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo',
|
||||
'enable_coderay' => false,
|
||||
'auto_ids' => true,
|
||||
'footnote_nr' => 1,
|
||||
'entity_output' => 'as_char',
|
||||
'toc_levels' => '1..6',
|
||||
'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo',
|
||||
'use_coderay' => false,
|
||||
|
||||
'coderay' => {
|
||||
'coderay_wrap' => 'div',
|
||||
@@ -113,16 +99,12 @@ module Jekyll
|
||||
override['source'] || self['source'] || DEFAULTS['source']
|
||||
end
|
||||
|
||||
def quiet?(override = {})
|
||||
override['quiet'] || self['quiet'] || DEFAULTS['quiet']
|
||||
end
|
||||
|
||||
def safe_load_file(filename)
|
||||
case File.extname(filename)
|
||||
when /\.toml/i
|
||||
when '.toml'
|
||||
TOML.load_file(filename)
|
||||
when /\.ya?ml/i
|
||||
SafeYAML.load_file(filename)
|
||||
when /\.y(a)?ml/
|
||||
YAML.safe_load_file(filename)
|
||||
else
|
||||
raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead."
|
||||
end
|
||||
@@ -134,16 +116,10 @@ module Jekyll
|
||||
#
|
||||
# Returns an Array of config files
|
||||
def config_files(override)
|
||||
# Be quiet quickly.
|
||||
Jekyll.logger.log_level = :error if quiet?(override)
|
||||
|
||||
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
||||
config_files = override.delete('config')
|
||||
if config_files.to_s.empty?
|
||||
default = %w[yml yaml].find(Proc.new { 'yml' }) do |ext|
|
||||
File.exists? Jekyll.sanitized_path(source(override), "_config.#{ext}")
|
||||
end
|
||||
config_files = Jekyll.sanitized_path(source(override), "_config.#{default}")
|
||||
config_files = File.join(source(override), "_config.yml")
|
||||
@default_config_file = true
|
||||
end
|
||||
config_files = [config_files] unless config_files.is_a? Array
|
||||
@@ -182,7 +158,7 @@ module Jekyll
|
||||
begin
|
||||
files.each do |config_file|
|
||||
new_config = read_config_file(config_file)
|
||||
configuration = Utils.deep_merge_hashes(configuration, new_config)
|
||||
configuration = configuration.deep_merge(new_config)
|
||||
end
|
||||
rescue ArgumentError => err
|
||||
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
||||
@@ -209,40 +185,30 @@ module Jekyll
|
||||
def backwards_compatibilize
|
||||
config = clone
|
||||
# Provide backwards-compatibility
|
||||
if config.key?('auto') || config.key?('watch')
|
||||
if config.has_key?('auto') || config.has_key?('watch')
|
||||
Jekyll.logger.warn "Deprecation:", "Auto-regeneration can no longer" +
|
||||
" be set from your configuration file(s). Use the"+
|
||||
" --[no-]watch/-w command-line option instead."
|
||||
" --watch/-w command-line option instead."
|
||||
config.delete('auto')
|
||||
config.delete('watch')
|
||||
end
|
||||
|
||||
if config.key? 'server'
|
||||
if config.has_key? 'server'
|
||||
Jekyll.logger.warn "Deprecation:", "The 'server' configuration option" +
|
||||
" is no longer accepted. Use the 'jekyll serve'" +
|
||||
" subcommand to serve your site with WEBrick."
|
||||
config.delete('server')
|
||||
end
|
||||
|
||||
if config.key? 'server_port'
|
||||
if config.has_key? 'server_port'
|
||||
Jekyll.logger.warn "Deprecation:", "The 'server_port' configuration option" +
|
||||
" has been renamed to 'port'. Please update your config" +
|
||||
" file accordingly."
|
||||
# copy but don't overwrite:
|
||||
config['port'] = config['server_port'] unless config.key?('port')
|
||||
config['port'] = config['server_port'] unless config.has_key?('port')
|
||||
config.delete('server_port')
|
||||
end
|
||||
|
||||
if config.key? 'pygments'
|
||||
Jekyll.logger.warn "Deprecation:", "The 'pygments' configuration option" +
|
||||
" has been renamed to 'highlighter'. Please update your" +
|
||||
" config file accordingly. The allowed values are 'rouge', " +
|
||||
"'pygments' or null."
|
||||
|
||||
config['highlighter'] = 'pygments' if config['pygments']
|
||||
config.delete('pygments')
|
||||
end
|
||||
|
||||
%w[include exclude].each do |option|
|
||||
if config.fetch(option, []).is_a?(String)
|
||||
Jekyll.logger.warn "Deprecation:", "The '#{option}' configuration option" +
|
||||
@@ -251,19 +217,6 @@ module Jekyll
|
||||
" as a list of comma-separated values."
|
||||
config[option] = csv_to_array(config[option])
|
||||
end
|
||||
config[option].map!(&:to_s)
|
||||
end
|
||||
|
||||
if (config['kramdown'] || {}).key?('use_coderay')
|
||||
Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" +
|
||||
" to 'enable_coderay' in your configuration file."
|
||||
config['kramdown']['use_coderay'] = config['kramdown'].delete('enable_coderay')
|
||||
end
|
||||
|
||||
if config.fetch('markdown', 'kramdown').to_s.downcase.eql?("maruku")
|
||||
Jekyll::Deprecator.deprecation_message "You're using the 'maruku' " +
|
||||
"Markdown processor. Maruku support has been deprecated and will " +
|
||||
"be removed in 3.0.0. We recommend you switch to Kramdown."
|
||||
end
|
||||
config
|
||||
end
|
||||
@@ -271,7 +224,7 @@ module Jekyll
|
||||
def fix_common_issues
|
||||
config = clone
|
||||
|
||||
if config.key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 1)
|
||||
if config.has_key?('paginate') && (!config['paginate'].is_a?(Integer) || config['paginate'] < 1)
|
||||
Jekyll.logger.warn "Config Warning:", "The `paginate` key must be a" +
|
||||
" positive integer or nil. It's currently set to '#{config['paginate'].inspect}'."
|
||||
config['paginate'] = nil
|
||||
@@ -279,5 +232,6 @@ module Jekyll
|
||||
|
||||
config
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
module Jekyll
|
||||
class Converter < Plugin
|
||||
# Public: Get or set the highlighter prefix. When an argument is specified,
|
||||
# Public: Get or set the pygments prefix. When an argument is specified,
|
||||
# the prefix will be set. If no argument is specified, the current prefix
|
||||
# will be returned.
|
||||
#
|
||||
# highlighter_prefix - The String prefix (default: nil).
|
||||
# pygments_prefix - The String prefix (default: nil).
|
||||
#
|
||||
# Returns the String prefix.
|
||||
def self.highlighter_prefix(highlighter_prefix = nil)
|
||||
@highlighter_prefix = highlighter_prefix if highlighter_prefix
|
||||
@highlighter_prefix
|
||||
def self.pygments_prefix(pygments_prefix = nil)
|
||||
@pygments_prefix = pygments_prefix if pygments_prefix
|
||||
@pygments_prefix
|
||||
end
|
||||
|
||||
# Public: Get or set the highlighter suffix. When an argument is specified,
|
||||
# Public: Get or set the pygments suffix. When an argument is specified,
|
||||
# the suffix will be set. If no argument is specified, the current suffix
|
||||
# will be returned.
|
||||
#
|
||||
# highlighter_suffix - The String suffix (default: nil).
|
||||
# pygments_suffix - The String suffix (default: nil).
|
||||
#
|
||||
# Returns the String suffix.
|
||||
def self.highlighter_suffix(highlighter_suffix = nil)
|
||||
@highlighter_suffix = highlighter_suffix if highlighter_suffix
|
||||
@highlighter_suffix
|
||||
def self.pygments_suffix(pygments_suffix = nil)
|
||||
@pygments_suffix = pygments_suffix if pygments_suffix
|
||||
@pygments_suffix
|
||||
end
|
||||
|
||||
# Initialize the converter.
|
||||
@@ -31,18 +31,18 @@ module Jekyll
|
||||
@config = config
|
||||
end
|
||||
|
||||
# Get the highlighter prefix.
|
||||
# Get the pygments prefix.
|
||||
#
|
||||
# Returns the String prefix.
|
||||
def highlighter_prefix
|
||||
self.class.highlighter_prefix
|
||||
def pygments_prefix
|
||||
self.class.pygments_prefix
|
||||
end
|
||||
|
||||
# Get the highlighter suffix.
|
||||
# Get the pygments suffix.
|
||||
#
|
||||
# Returns the String suffix.
|
||||
def highlighter_suffix
|
||||
self.class.highlighter_suffix
|
||||
def pygments_suffix
|
||||
self.class.pygments_suffix
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,58 +3,31 @@ module Jekyll
|
||||
class Markdown < Converter
|
||||
safe true
|
||||
|
||||
highlighter_prefix "\n"
|
||||
highlighter_suffix "\n"
|
||||
pygments_prefix "\n"
|
||||
pygments_suffix "\n"
|
||||
|
||||
def setup
|
||||
return if @setup
|
||||
@parser =
|
||||
case @config['markdown'].downcase
|
||||
when 'redcarpet' then RedcarpetParser.new(@config)
|
||||
when 'kramdown' then KramdownParser.new(@config)
|
||||
when 'rdiscount' then RDiscountParser.new(@config)
|
||||
when 'maruku' then MarukuParser.new(@config)
|
||||
@parser = case @config['markdown']
|
||||
when 'redcarpet'
|
||||
RedcarpetParser.new @config
|
||||
when 'kramdown'
|
||||
KramdownParser.new @config
|
||||
when 'rdiscount'
|
||||
RDiscountParser.new @config
|
||||
when 'maruku'
|
||||
MarukuParser.new @config
|
||||
else
|
||||
# So they can't try some tricky bullshit or go down the ancestor chain, I hope.
|
||||
if allowed_custom_class?(@config['markdown'])
|
||||
self.class.const_get(@config['markdown']).new(@config)
|
||||
else
|
||||
Jekyll.logger.error "Invalid Markdown Processor:", "#{@config['markdown']}"
|
||||
Jekyll.logger.error "", "Valid options are [ #{valid_processors.join(" | ")} ]"
|
||||
raise Errors::FatalException, "Invalid Markdown Processor: #{@config['markdown']}"
|
||||
end
|
||||
end
|
||||
STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
|
||||
STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
|
||||
raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
|
||||
end
|
||||
@setup = true
|
||||
end
|
||||
|
||||
def valid_processors
|
||||
%w[
|
||||
maruku
|
||||
rdiscount
|
||||
kramdown
|
||||
redcarpet
|
||||
] + third_party_processors
|
||||
end
|
||||
|
||||
def third_party_processors
|
||||
self.class.constants - %w[
|
||||
KramdownParser
|
||||
MarukuParser
|
||||
RDiscountParser
|
||||
RedcarpetParser
|
||||
PRIORITIES
|
||||
].map(&:to_sym)
|
||||
end
|
||||
|
||||
def extname_matches_regexp
|
||||
@extname_matches_regexp ||= Regexp.new(
|
||||
'^\.(' + @config['markdown_ext'].gsub(',','|') +')$',
|
||||
Regexp::IGNORECASE
|
||||
)
|
||||
end
|
||||
|
||||
def matches(ext)
|
||||
ext =~ extname_matches_regexp
|
||||
rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
|
||||
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
||||
end
|
||||
|
||||
def output_ext(ext)
|
||||
@@ -65,19 +38,6 @@ module Jekyll
|
||||
setup
|
||||
@parser.convert(content)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Private: Determine whether a class name is an allowed custom markdown
|
||||
# class name
|
||||
#
|
||||
# parser_name - the name of the parser class
|
||||
#
|
||||
# Returns true if the parser name contains only alphanumeric characters
|
||||
# and is defined within Jekyll::Converters::Markdown
|
||||
def allowed_custom_class?(parser_name)
|
||||
parser_name !~ /[^A-Za-z0-9]/ && self.class.constants.include?(parser_name.to_sym)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,19 +8,19 @@ module Jekyll
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
||||
STDERR.puts ' $ [sudo] gem install kramdown'
|
||||
raise Errors::FatalException.new("Missing dependency: kramdown")
|
||||
raise FatalException.new("Missing dependency: kramdown")
|
||||
end
|
||||
|
||||
def convert(content)
|
||||
# Check for use of coderay
|
||||
if @config['kramdown']['enable_coderay']
|
||||
if @config['kramdown']['use_coderay']
|
||||
%w[wrap line_numbers line_numbers_start tab_width bold_every css default_lang].each do |opt|
|
||||
key = "coderay_#{opt}"
|
||||
@config['kramdown'][key] = @config['kramdown']['coderay'][key] unless @config['kramdown'].key?(key)
|
||||
@config['kramdown'][key] = @config['kramdown']['coderay'][key] unless @config['kramdown'].has_key?(key)
|
||||
end
|
||||
end
|
||||
|
||||
Kramdown::Document.new(content, Utils.symbolize_hash_keys(@config['kramdown'])).to_html
|
||||
Kramdown::Document.new(content, @config["kramdown"].symbolize_keys).to_html
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,14 +8,10 @@ module Jekyll
|
||||
@errors = []
|
||||
load_divs_library if @config['maruku']['use_divs']
|
||||
load_blahtext_library if @config['maruku']['use_tex']
|
||||
|
||||
# allow fenced code blocks (new in Maruku 0.7.0)
|
||||
MaRuKu::Globals[:fenced_code_blocks] = !!@config['maruku']['fenced_code_blocks']
|
||||
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
||||
STDERR.puts ' $ [sudo] gem install maruku'
|
||||
raise Errors::FatalException.new("Missing dependency: maruku")
|
||||
raise FatalException.new("Missing dependency: maruku")
|
||||
end
|
||||
|
||||
def load_divs_library
|
||||
|
||||
@@ -3,9 +3,13 @@ module Jekyll
|
||||
class Markdown
|
||||
class RDiscountParser
|
||||
def initialize(config)
|
||||
Jekyll::External.require_with_graceful_fail "rdiscount"
|
||||
require 'rdiscount'
|
||||
@config = config
|
||||
@rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
||||
STDERR.puts ' $ [sudo] gem install rdiscount'
|
||||
raise FatalException.new("Missing dependency: rdiscount")
|
||||
end
|
||||
|
||||
def convert(content)
|
||||
|
||||
@@ -5,8 +5,7 @@ module Jekyll
|
||||
|
||||
module CommonMethods
|
||||
def add_code_tags(code, lang)
|
||||
code = code.to_s
|
||||
code = code.sub(/<pre>/, "<pre><code class=\"language-#{lang}\" data-lang=\"#{lang}\">")
|
||||
code = code.sub(/<pre>/, "<pre><code class=\"#{lang} language-#{lang}\" data-lang=\"#{lang}\">")
|
||||
code = code.sub(/<\/pre>/,"</code></pre>")
|
||||
end
|
||||
end
|
||||
@@ -14,16 +13,16 @@ module Jekyll
|
||||
module WithPygments
|
||||
include CommonMethods
|
||||
def block_code(code, lang)
|
||||
Jekyll::External.require_with_graceful_fail("pygments")
|
||||
require 'pygments'
|
||||
lang = lang && lang.split.first || "text"
|
||||
add_code_tags(
|
||||
output = add_code_tags(
|
||||
Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }),
|
||||
lang
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
module WithoutHighlighting
|
||||
module WithoutPygments
|
||||
require 'cgi'
|
||||
|
||||
include CommonMethods
|
||||
@@ -34,61 +33,29 @@ module Jekyll
|
||||
|
||||
def block_code(code, lang)
|
||||
lang = lang && lang.split.first || "text"
|
||||
add_code_tags(code_wrap(code), lang)
|
||||
output = add_code_tags(code_wrap(code), lang)
|
||||
end
|
||||
end
|
||||
|
||||
module WithRouge
|
||||
def block_code(code, lang)
|
||||
code = "<pre>#{super}</pre>"
|
||||
|
||||
output = "<div class=\"highlight\">"
|
||||
output << add_code_tags(code, lang)
|
||||
output << "</div>"
|
||||
end
|
||||
|
||||
protected
|
||||
def rouge_formatter(lexer)
|
||||
Rouge::Formatters::HTML.new(:wrap => false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(config)
|
||||
External.require_with_graceful_fail("redcarpet")
|
||||
require 'redcarpet'
|
||||
@config = config
|
||||
@redcarpet_extensions = {}
|
||||
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
||||
|
||||
@renderer ||= class_with_proper_highlighter(@config['highlighter'])
|
||||
end
|
||||
|
||||
def class_with_proper_highlighter(highlighter)
|
||||
case highlighter
|
||||
when "pygments"
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
include WithPygments
|
||||
end
|
||||
when "rouge"
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
Jekyll::External.require_with_graceful_fail(%w[
|
||||
rouge
|
||||
rouge/plugins/redcarpet
|
||||
])
|
||||
|
||||
if Rouge.version < '1.3.0'
|
||||
abort "Please install Rouge 1.3.0 or greater and try running Jekyll again."
|
||||
end
|
||||
|
||||
include Rouge::Plugins::Redcarpet
|
||||
include CommonMethods
|
||||
include WithRouge
|
||||
end
|
||||
else
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
include WithoutHighlighting
|
||||
end
|
||||
end
|
||||
@renderer ||= if @config['pygments']
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
include WithPygments
|
||||
end
|
||||
else
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
include WithoutPygments
|
||||
end
|
||||
end
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
||||
STDERR.puts ' $ [sudo] gem install redcarpet'
|
||||
raise FatalException.new("Missing dependency: redcarpet")
|
||||
end
|
||||
|
||||
def convert(content)
|
||||
|
||||
@@ -3,8 +3,8 @@ module Jekyll
|
||||
class Textile < Converter
|
||||
safe true
|
||||
|
||||
highlighter_prefix '<notextile>'
|
||||
highlighter_suffix '</notextile>'
|
||||
pygments_prefix '<notextile>'
|
||||
pygments_suffix '</notextile>'
|
||||
|
||||
def setup
|
||||
return if @setup
|
||||
@@ -13,18 +13,12 @@ module Jekyll
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Textile. Please run:'
|
||||
STDERR.puts ' $ [sudo] gem install RedCloth'
|
||||
raise Errors::FatalException.new("Missing dependency: RedCloth")
|
||||
end
|
||||
|
||||
def extname_matches_regexp
|
||||
@extname_matches_regexp ||= Regexp.new(
|
||||
'(' + @config['textile_ext'].gsub(',','|') +')$',
|
||||
Regexp::IGNORECASE
|
||||
)
|
||||
raise FatalException.new("Missing dependency: RedCloth")
|
||||
end
|
||||
|
||||
def matches(ext)
|
||||
ext =~ extname_matches_regexp
|
||||
rgx = '(' + @config['textile_ext'].gsub(',','|') +')'
|
||||
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
|
||||
end
|
||||
|
||||
def output_ext(ext)
|
||||
@@ -38,7 +32,7 @@ module Jekyll
|
||||
return RedCloth.new(content).to_html if @config['redcloth'].nil?
|
||||
|
||||
# List of attributes defined on RedCloth
|
||||
# (from https://github.com/jgarber/redcloth/blob/master/lib/redcloth/textile_doc.rb)
|
||||
# (from http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html)
|
||||
attrs = ['filter_classes', 'filter_html', 'filter_ids', 'filter_styles',
|
||||
'hard_breaks', 'lite_mode', 'no_span_caps', 'sanitize_html']
|
||||
|
||||
|
||||
@@ -13,25 +13,17 @@ require 'set'
|
||||
# self.ext=
|
||||
# self.output=
|
||||
# self.name
|
||||
# self.path
|
||||
# self.type -> :page, :post or :draft
|
||||
|
||||
module Jekyll
|
||||
module Convertible
|
||||
# Returns the contents as a String.
|
||||
def to_s
|
||||
content || ''
|
||||
self.content || ''
|
||||
end
|
||||
|
||||
# Whether the file is published or not, as indicated in YAML front-matter
|
||||
def published?
|
||||
!(data.key?('published') && data['published'] == false)
|
||||
end
|
||||
|
||||
# Returns merged option hash for File.read of self.site (if exists)
|
||||
# Returns merged optin hash for File.read of self.site (if exists)
|
||||
# and a given param
|
||||
def merged_file_read_opts(opts)
|
||||
(site ? site.file_read_opts : {}).merge(opts)
|
||||
(self.site ? self.site.file_read_opts : {}).merge(opts)
|
||||
end
|
||||
|
||||
# Read the YAML frontmatter.
|
||||
@@ -43,16 +35,16 @@ module Jekyll
|
||||
# Returns nothing.
|
||||
def read_yaml(base, name, opts = {})
|
||||
begin
|
||||
self.content = File.read(site.in_source_dir(base, name),
|
||||
merged_file_read_opts(opts))
|
||||
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
||||
self.content = File.read_with_options(File.join(base, name),
|
||||
merged_file_read_opts(opts))
|
||||
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
||||
self.content = $POSTMATCH
|
||||
self.data = SafeYAML.load($1)
|
||||
self.data = YAML.safe_load($1)
|
||||
end
|
||||
rescue SyntaxError => e
|
||||
Jekyll.logger.warn "YAML Exception reading #{File.join(base, name)}: #{e.message}"
|
||||
puts "YAML Exception reading #{File.join(base, name)}: #{e.message}"
|
||||
rescue Exception => e
|
||||
Jekyll.logger.warn "Error reading file #{File.join(base, name)}: #{e.message}"
|
||||
puts "Error reading file #{File.join(base, name)}: #{e.message}"
|
||||
end
|
||||
|
||||
self.data ||= {}
|
||||
@@ -60,17 +52,13 @@ module Jekyll
|
||||
|
||||
# Transform the contents based on the content type.
|
||||
#
|
||||
# Returns the transformed contents.
|
||||
# Returns nothing.
|
||||
def transform
|
||||
converters.reduce(content) do |output, converter|
|
||||
begin
|
||||
converter.convert output
|
||||
rescue => e
|
||||
Jekyll.logger.error "Conversion error:", "#{converter.class} encountered an error while converting '#{path}':"
|
||||
Jekyll.logger.error("", e.to_s)
|
||||
raise e
|
||||
end
|
||||
end
|
||||
self.content = converter.convert(self.content)
|
||||
rescue => e
|
||||
Jekyll.logger.error "Conversion error:", "There was an error converting" +
|
||||
" '#{self.path}'."
|
||||
raise e
|
||||
end
|
||||
|
||||
# Determine the extension depending on content_type.
|
||||
@@ -78,21 +66,15 @@ module Jekyll
|
||||
# Returns the String extension for the output file.
|
||||
# e.g. ".html" for an HTML output file.
|
||||
def output_ext
|
||||
if converters.all? { |c| c.is_a?(Jekyll::Converters::Identity) }
|
||||
ext
|
||||
else
|
||||
converters.map { |c|
|
||||
c.output_ext(ext) unless c.is_a?(Jekyll::Converters::Identity)
|
||||
}.compact.last
|
||||
end
|
||||
converter.output_ext(self.ext)
|
||||
end
|
||||
|
||||
# Determine which converter to use based on this convertible's
|
||||
# extension.
|
||||
#
|
||||
# Returns the Converter instance.
|
||||
def converters
|
||||
@converters ||= site.converters.select { |c| c.matches(ext) }.sort
|
||||
def converter
|
||||
@converter ||= self.site.converters.find { |c| c.matches(self.ext) }
|
||||
end
|
||||
|
||||
# Render Liquid in the content
|
||||
@@ -119,78 +101,7 @@ module Jekyll
|
||||
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
|
||||
[attribute, send(attribute)]
|
||||
}]
|
||||
|
||||
defaults = site.frontmatter_defaults.all(relative_path, type)
|
||||
Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
|
||||
end
|
||||
|
||||
# The type of a document,
|
||||
# i.e., its classname downcase'd and to_sym'd.
|
||||
#
|
||||
# Returns the type of self.
|
||||
def type
|
||||
if is_a?(Draft)
|
||||
:drafts
|
||||
elsif is_a?(Post)
|
||||
:posts
|
||||
elsif is_a?(Page)
|
||||
:pages
|
||||
end
|
||||
end
|
||||
|
||||
# Determine whether the document is an asset file.
|
||||
# Asset files include CoffeeScript files and Sass/SCSS files.
|
||||
#
|
||||
# Returns true if the extname belongs to the set of extensions
|
||||
# that asset files use.
|
||||
def asset_file?
|
||||
sass_file? || coffeescript_file?
|
||||
end
|
||||
|
||||
# Determine whether the document is a Sass file.
|
||||
#
|
||||
# Returns true if extname == .sass or .scss, false otherwise.
|
||||
def sass_file?
|
||||
%w[.sass .scss].include?(ext)
|
||||
end
|
||||
|
||||
# Determine whether the document is a CoffeeScript file.
|
||||
#
|
||||
# Returns true if extname == .coffee, false otherwise.
|
||||
def coffeescript_file?
|
||||
'.coffee'.eql?(ext)
|
||||
end
|
||||
|
||||
# Determine whether the file should be rendered with Liquid.
|
||||
#
|
||||
# Always returns true.
|
||||
def render_with_liquid?
|
||||
true
|
||||
end
|
||||
|
||||
# Determine whether to regenerate the file based on metadata.
|
||||
#
|
||||
# Returns true if file needs to be regenerated
|
||||
def regenerate?
|
||||
asset_file? ||
|
||||
data['regenerate'] ||
|
||||
site.metadata.regenerate?(site.in_source_dir(relative_path))
|
||||
end
|
||||
|
||||
# Determine whether the file should be placed into layouts.
|
||||
#
|
||||
# Returns false if the document is an asset file.
|
||||
def place_in_layout?
|
||||
!asset_file?
|
||||
end
|
||||
|
||||
# Checks if the layout specified in the document actually exists
|
||||
#
|
||||
# layout - the layout to check
|
||||
#
|
||||
# Returns true if the layout is invalid, false if otherwise
|
||||
def invalid_layout?(layout)
|
||||
!data["layout"].nil? && layout.nil? && !(self.is_a? Jekyll::Excerpt)
|
||||
data.deep_merge(further_data)
|
||||
end
|
||||
|
||||
# Recursively render layouts
|
||||
@@ -202,25 +113,16 @@ module Jekyll
|
||||
# Returns nothing
|
||||
def render_all_layouts(layouts, payload, info)
|
||||
# recursively render layouts
|
||||
layout = layouts[data["layout"]]
|
||||
|
||||
Jekyll.logger.warn("Build Warning:", "Layout '#{data["layout"]}' requested in #{path} does not exist.") if invalid_layout? layout
|
||||
|
||||
layout = layouts[self.data["layout"]]
|
||||
used = Set.new([layout])
|
||||
|
||||
while layout
|
||||
payload = Utils.deep_merge_hashes(payload, {"content" => output, "page" => layout.data})
|
||||
payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
|
||||
|
||||
self.output = render_liquid(layout.content,
|
||||
self.output = self.render_liquid(layout.content,
|
||||
payload,
|
||||
info,
|
||||
File.join(site.config['layouts'], layout.name))
|
||||
|
||||
# Add layout to dependency tree
|
||||
site.metadata.add_dependency(
|
||||
site.in_source_dir(path),
|
||||
site.in_source_dir(layout.path)
|
||||
)
|
||||
File.join(self.site.config['layouts'], layout.name))
|
||||
|
||||
if layout = layouts[layout.data["layout"]]
|
||||
if used.include?(layout)
|
||||
@@ -239,19 +141,21 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def do_layout(payload, layouts)
|
||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page => payload['page'] } }
|
||||
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site, :page => payload['page'] } }
|
||||
|
||||
# render and transform content (this becomes the final content of the object)
|
||||
payload["highlighter_prefix"] = converters.first.highlighter_prefix
|
||||
payload["highlighter_suffix"] = converters.first.highlighter_suffix
|
||||
payload["pygments_prefix"] = converter.pygments_prefix
|
||||
payload["pygments_suffix"] = converter.pygments_suffix
|
||||
|
||||
self.content = render_liquid(content, payload, info) if render_with_liquid?
|
||||
self.content = transform
|
||||
self.content = self.render_liquid(self.content,
|
||||
payload,
|
||||
info)
|
||||
self.transform
|
||||
|
||||
# output keeps track of what will finally be written
|
||||
self.output = content
|
||||
self.output = self.content
|
||||
|
||||
render_all_layouts(layouts, payload, info) if place_in_layout?
|
||||
self.render_all_layouts(layouts, payload, info)
|
||||
end
|
||||
|
||||
# Write the generated page file to the destination directory.
|
||||
@@ -263,20 +167,7 @@ module Jekyll
|
||||
path = destination(dest)
|
||||
FileUtils.mkdir_p(File.dirname(path))
|
||||
File.open(path, 'wb') do |f|
|
||||
f.write(output)
|
||||
end
|
||||
end
|
||||
|
||||
# Accessor for data properties by Liquid.
|
||||
#
|
||||
# property - The String name of the property to retrieve.
|
||||
#
|
||||
# Returns the String value or nil if the property isn't included.
|
||||
def [](property)
|
||||
if self.class::ATTRIBUTES_FOR_LIQUID.include?(property)
|
||||
send(property)
|
||||
else
|
||||
data[property]
|
||||
f.write(self.output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
86
lib/jekyll/core_ext.rb
Normal file
86
lib/jekyll/core_ext.rb
Normal file
@@ -0,0 +1,86 @@
|
||||
class Hash
|
||||
# Merges self with another hash, recursively.
|
||||
#
|
||||
# This code was lovingly stolen from some random gem:
|
||||
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
||||
#
|
||||
# Thanks to whoever made it.
|
||||
def deep_merge(hash)
|
||||
target = dup
|
||||
|
||||
hash.keys.each do |key|
|
||||
if hash[key].is_a? Hash and self[key].is_a? Hash
|
||||
target[key] = target[key].deep_merge(hash[key])
|
||||
next
|
||||
end
|
||||
|
||||
target[key] = hash[key]
|
||||
end
|
||||
|
||||
target
|
||||
end
|
||||
|
||||
# Read array from the supplied hash favouring the singular key
|
||||
# and then the plural key, and handling any nil entries.
|
||||
# +hash+ the hash to read from
|
||||
# +singular_key+ the singular key
|
||||
# +plural_key+ the plural key
|
||||
#
|
||||
# Returns an array
|
||||
def pluralized_array(singular_key, plural_key)
|
||||
hash = self
|
||||
if hash.has_key?(singular_key)
|
||||
array = [hash[singular_key]] if hash[singular_key]
|
||||
elsif hash.has_key?(plural_key)
|
||||
case hash[plural_key]
|
||||
when String
|
||||
array = hash[plural_key].split
|
||||
when Array
|
||||
array = hash[plural_key].compact
|
||||
end
|
||||
end
|
||||
array || []
|
||||
end
|
||||
|
||||
def symbolize_keys!
|
||||
keys.each do |key|
|
||||
self[(key.to_sym rescue key) || key] = delete(key)
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def symbolize_keys
|
||||
dup.symbolize_keys!
|
||||
end
|
||||
end
|
||||
|
||||
# Thanks, ActiveSupport!
|
||||
class Date
|
||||
# Converts datetime to an appropriate format for use in XML
|
||||
def xmlschema
|
||||
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
||||
end if RUBY_VERSION < '1.9'
|
||||
end
|
||||
|
||||
module Enumerable
|
||||
# Returns true if path matches against any glob pattern.
|
||||
# Look for more detail about glob pattern in method File::fnmatch.
|
||||
def glob_include?(e)
|
||||
any? { |exp| File.fnmatch?(exp, e) }
|
||||
end
|
||||
end
|
||||
|
||||
# Ruby 1.8's File.read don't support option.
|
||||
# read_with_options ignore optional parameter for 1.8,
|
||||
# and act as alias for 1.9 or later.
|
||||
class File
|
||||
if RUBY_VERSION < '1.9'
|
||||
def self.read_with_options(path, opts = {})
|
||||
self.read(path)
|
||||
end
|
||||
else
|
||||
def self.read_with_options(path, opts = {})
|
||||
self.read(path, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,6 @@
|
||||
module Jekyll
|
||||
module Deprecator
|
||||
extend self
|
||||
|
||||
def process(args)
|
||||
class Deprecator
|
||||
def self.process(args)
|
||||
no_subcommand(args)
|
||||
arg_is_present? args, "--server", "The --server command has been replaced by the \
|
||||
'serve' subcommand."
|
||||
@@ -11,34 +9,28 @@ module Jekyll
|
||||
arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'."
|
||||
arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \
|
||||
the '--watch' switch."
|
||||
arg_is_present? args, "--pygments", "The 'pygments'settings has been removed in \
|
||||
favour of 'highlighter'."
|
||||
arg_is_present? args, "--pygments", "The 'pygments' setting can only be set in \
|
||||
your config files."
|
||||
arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in your \
|
||||
config files."
|
||||
arg_is_present? args, "--url", "The 'url' setting can only be set in your config files."
|
||||
end
|
||||
|
||||
def no_subcommand(args)
|
||||
def self.no_subcommand(args)
|
||||
if args.size > 0 && args.first =~ /^--/ && !%w[--help --version].include?(args.first)
|
||||
deprecation_message "Jekyll now uses subcommands instead of just \
|
||||
switches. Run `jekyll --help' to find out more."
|
||||
Jekyll.logger.error "Deprecation:", "Jekyll now uses subcommands instead of just \
|
||||
switches. Run `jekyll help' to find out more."
|
||||
end
|
||||
end
|
||||
|
||||
def arg_is_present?(args, deprecated_argument, message)
|
||||
def self.arg_is_present?(args, deprecated_argument, message)
|
||||
if args.include?(deprecated_argument)
|
||||
deprecation_message(message)
|
||||
end
|
||||
end
|
||||
|
||||
def deprecation_message(message)
|
||||
def self.deprecation_message(message)
|
||||
Jekyll.logger.error "Deprecation:", message
|
||||
end
|
||||
|
||||
def defaults_deprecate_type(old, current)
|
||||
Jekyll.logger.warn "Defaults:", "The '#{old}' type has become '#{current}'."
|
||||
Jekyll.logger.warn "Defaults:", "Please update your front-matter defaults to use 'type: #{current}'."
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
module Jekyll
|
||||
class Document
|
||||
include Comparable
|
||||
|
||||
attr_reader :path, :site, :extname
|
||||
attr_accessor :content, :collection, :output
|
||||
|
||||
# Create a new Document.
|
||||
#
|
||||
# site - the Jekyll::Site instance to which this Document belongs
|
||||
# path - the path to the file
|
||||
#
|
||||
# Returns nothing.
|
||||
def initialize(path, relations)
|
||||
@site = relations[:site]
|
||||
@path = path
|
||||
@extname = File.extname(path)
|
||||
@collection = relations[:collection]
|
||||
@has_yaml_header = nil
|
||||
end
|
||||
|
||||
# Fetch the Document's data.
|
||||
#
|
||||
# Returns a Hash containing the data. An empty hash is returned if
|
||||
# no data was read.
|
||||
def data
|
||||
@data ||= Hash.new
|
||||
end
|
||||
|
||||
# The path to the document, relative to the site source.
|
||||
#
|
||||
# Returns a String path which represents the relative path
|
||||
# from the site source to this document
|
||||
def relative_path
|
||||
@relative_path ||= Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
|
||||
end
|
||||
|
||||
# The base filename of the document, without the file extname.
|
||||
#
|
||||
# Returns the basename without the file extname.
|
||||
def basename_without_ext
|
||||
@basename_without_ext ||= File.basename(path, '.*')
|
||||
end
|
||||
|
||||
# The base filename of the document.
|
||||
#
|
||||
# Returns the base filename of the document.
|
||||
def basename
|
||||
@basename ||= File.basename(path)
|
||||
end
|
||||
|
||||
# Produces a "cleaned" relative path.
|
||||
# The "cleaned" relative path is the relative path without the extname
|
||||
# and with the collection's directory removed as well.
|
||||
# This method is useful when building the URL of the document.
|
||||
#
|
||||
# Examples:
|
||||
# When relative_path is "_methods/site/generate.md":
|
||||
# cleaned_relative_path
|
||||
# # => "/site/generate"
|
||||
#
|
||||
# Returns the cleaned relative path of the document.
|
||||
def cleaned_relative_path
|
||||
@cleaned_relative_path ||=
|
||||
relative_path[0 .. -extname.length - 1].sub(collection.relative_directory, "")
|
||||
end
|
||||
|
||||
# Determine whether the document is a YAML file.
|
||||
#
|
||||
# Returns true if the extname is either .yml or .yaml, false otherwise.
|
||||
def yaml_file?
|
||||
%w[.yaml .yml].include?(extname)
|
||||
end
|
||||
|
||||
# Determine whether the document is an asset file.
|
||||
# Asset files include CoffeeScript files and Sass/SCSS files.
|
||||
#
|
||||
# Returns true if the extname belongs to the set of extensions
|
||||
# that asset files use.
|
||||
def asset_file?
|
||||
sass_file? || coffeescript_file?
|
||||
end
|
||||
|
||||
# Determine whether the document is a Sass file.
|
||||
#
|
||||
# Returns true if extname == .sass or .scss, false otherwise.
|
||||
def sass_file?
|
||||
%w[.sass .scss].include?(extname)
|
||||
end
|
||||
|
||||
# Determine whether the document is a CoffeeScript file.
|
||||
#
|
||||
# Returns true if extname == .coffee, false otherwise.
|
||||
def coffeescript_file?
|
||||
'.coffee'.eql?(extname)
|
||||
end
|
||||
|
||||
# Determine whether the file should be rendered with Liquid.
|
||||
#
|
||||
# Returns false if the document is either an asset file or a yaml file,
|
||||
# true otherwise.
|
||||
def render_with_liquid?
|
||||
!(coffeescript_file? || yaml_file?)
|
||||
end
|
||||
|
||||
# Determine whether the document should be regenerated based on metadata.
|
||||
#
|
||||
# Returns true if the document needs to be regenerated.
|
||||
def regenerate?
|
||||
data['regenerate'] || site.metadata.regenerate?(path, write?)
|
||||
end
|
||||
|
||||
# Determine whether the file should be placed into layouts.
|
||||
#
|
||||
# Returns false if the document is either an asset file or a yaml file,
|
||||
# true otherwise.
|
||||
def place_in_layout?
|
||||
!(asset_file? || yaml_file?)
|
||||
end
|
||||
|
||||
# The URL template where the document would be accessible.
|
||||
#
|
||||
# Returns the URL template for the document.
|
||||
def url_template
|
||||
collection.url_template
|
||||
end
|
||||
|
||||
# Construct a Hash of key-value pairs which contain a mapping between
|
||||
# a key in the URL template and the corresponding value for this document.
|
||||
#
|
||||
# Returns the Hash of key-value pairs for replacement in the URL.
|
||||
def url_placeholders
|
||||
{
|
||||
collection: collection.label,
|
||||
path: cleaned_relative_path,
|
||||
output_ext: Jekyll::Renderer.new(site, self).output_ext,
|
||||
name: Utils.slugify(basename_without_ext),
|
||||
title: Utils.slugify(data['title']) || Utils.slugify(basename_without_ext)
|
||||
}
|
||||
end
|
||||
|
||||
# The permalink for this Document.
|
||||
# Permalink is set via the data Hash.
|
||||
#
|
||||
# Returns the permalink or nil if no permalink was set in the data.
|
||||
def permalink
|
||||
data && data.is_a?(Hash) && data['permalink']
|
||||
end
|
||||
|
||||
# The computed URL for the document. See `Jekyll::URL#to_s` for more details.
|
||||
#
|
||||
# Returns the computed URL for the document.
|
||||
def url
|
||||
@url = URL.new({
|
||||
template: url_template,
|
||||
placeholders: url_placeholders,
|
||||
permalink: permalink
|
||||
}).to_s
|
||||
end
|
||||
|
||||
# The full path to the output file.
|
||||
#
|
||||
# base_directory - the base path of the output directory
|
||||
#
|
||||
# Returns the full path to the output file of this document.
|
||||
def destination(base_directory)
|
||||
dest = site.in_dest_dir(base_directory)
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if url =~ /\/$/
|
||||
path
|
||||
end
|
||||
|
||||
# Write the generated Document file to the destination directory.
|
||||
#
|
||||
# dest - The String path to the destination dir.
|
||||
#
|
||||
# Returns nothing.
|
||||
def write(dest)
|
||||
path = destination(dest)
|
||||
FileUtils.mkdir_p(File.dirname(path))
|
||||
File.open(path, 'wb') do |f|
|
||||
f.write(output)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns merged option hash for File.read of self.site (if exists)
|
||||
# and a given param
|
||||
#
|
||||
# opts - override options
|
||||
#
|
||||
# Return the file read options hash.
|
||||
def merged_file_read_opts(opts)
|
||||
site ? site.file_read_opts.merge(opts) : opts
|
||||
end
|
||||
|
||||
# Whether the file is published or not, as indicated in YAML front-matter
|
||||
#
|
||||
# Returns true if the 'published' key is specified in the YAML front-matter and not `false`.
|
||||
def published?
|
||||
!(data.key?('published') && data['published'] == false)
|
||||
end
|
||||
|
||||
# Read in the file and assign the content and data based on the file contents.
|
||||
# Merge the frontmatter of the file with the frontmatter default
|
||||
# values
|
||||
#
|
||||
# Returns nothing.
|
||||
def read(opts = {})
|
||||
if yaml_file?
|
||||
@data = SafeYAML.load_file(path)
|
||||
else
|
||||
begin
|
||||
defaults = @site.frontmatter_defaults.all(url, collection.label.to_sym)
|
||||
unless defaults.empty?
|
||||
@data = defaults
|
||||
end
|
||||
@content = File.read(path, merged_file_read_opts(opts))
|
||||
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
||||
@content = $POSTMATCH
|
||||
data_file = SafeYAML.load($1)
|
||||
unless data_file.nil?
|
||||
@data = Utils.deep_merge_hashes(defaults, data_file)
|
||||
end
|
||||
end
|
||||
rescue SyntaxError => e
|
||||
puts "YAML Exception reading #{path}: #{e.message}"
|
||||
rescue Exception => e
|
||||
puts "Error reading file #{path}: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create a Liquid-understandable version of this Document.
|
||||
#
|
||||
# Returns a Hash representing this Document's data.
|
||||
def to_liquid
|
||||
if data.is_a?(Hash)
|
||||
Utils.deep_merge_hashes data, {
|
||||
"output" => output,
|
||||
"content" => content,
|
||||
"relative_path" => relative_path,
|
||||
"path" => relative_path,
|
||||
"url" => url,
|
||||
"collection" => collection.label
|
||||
}
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
# The inspect string for this document.
|
||||
# Includes the relative path and the collection label.
|
||||
#
|
||||
# Returns the inspect string for this document.
|
||||
def inspect
|
||||
"#<Jekyll::Document #{relative_path} collection=#{collection.label}>"
|
||||
end
|
||||
|
||||
# The string representation for this document.
|
||||
#
|
||||
# Returns the content of the document
|
||||
def to_s
|
||||
content || ''
|
||||
end
|
||||
|
||||
# Compare this document against another document.
|
||||
# Comparison is a comparison between the 2 paths of the documents.
|
||||
#
|
||||
# Returns -1, 0, +1 or nil depending on whether this doc's path is less than,
|
||||
# equal or greater than the other doc's path. See String#<=> for more details.
|
||||
def <=>(anotherDocument)
|
||||
path <=> anotherDocument.path
|
||||
end
|
||||
|
||||
# Determine whether this document should be written.
|
||||
# Based on the Collection to which it belongs.
|
||||
#
|
||||
# True if the document has a collection and if that collection's #write?
|
||||
# method returns true, otherwise false.
|
||||
def write?
|
||||
collection && collection.write?
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -14,13 +14,8 @@ module Jekyll
|
||||
end
|
||||
|
||||
# Get the full path to the directory containing the draft files
|
||||
def containing_dir(dir)
|
||||
site.in_source_dir(dir, '_drafts')
|
||||
end
|
||||
|
||||
# The path to the draft source file, relative to the site source
|
||||
def relative_path
|
||||
File.join(@dir, '_drafts', @name)
|
||||
def containing_dir(source, dir)
|
||||
File.join(source, dir, '_drafts')
|
||||
end
|
||||
|
||||
# Extract information from the post filename.
|
||||
|
||||
@@ -1,72 +1,35 @@
|
||||
module Jekyll
|
||||
class EntryFilter
|
||||
SPECIAL_LEADING_CHARACTERS = ['.', '_', '#'].freeze
|
||||
class EntryFilter
|
||||
attr_reader :site
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
|
||||
attr_reader :site
|
||||
|
||||
def initialize(site, base_directory = nil)
|
||||
@site = site
|
||||
@base_directory = derive_base_directory(@site, base_directory.to_s.dup)
|
||||
end
|
||||
|
||||
def base_directory
|
||||
@base_directory.to_s
|
||||
end
|
||||
|
||||
def derive_base_directory(site, base_dir)
|
||||
if base_dir.start_with?(site.source)
|
||||
base_dir[site.source] = ""
|
||||
end
|
||||
base_dir
|
||||
end
|
||||
|
||||
def relative_to_source(entry)
|
||||
File.join(base_directory, entry)
|
||||
end
|
||||
|
||||
def filter(entries)
|
||||
entries.reject do |e|
|
||||
unless included?(e)
|
||||
special?(e) || backup?(e) || excluded?(e) || symlink?(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def included?(entry)
|
||||
glob_include?(site.include, entry)
|
||||
end
|
||||
|
||||
def special?(entry)
|
||||
SPECIAL_LEADING_CHARACTERS.include?(entry[0..0]) ||
|
||||
SPECIAL_LEADING_CHARACTERS.include?(File.basename(entry)[0..0])
|
||||
end
|
||||
|
||||
def backup?(entry)
|
||||
entry[-1..-1] == '~'
|
||||
end
|
||||
|
||||
def excluded?(entry)
|
||||
excluded = glob_include?(site.exclude, relative_to_source(entry))
|
||||
Jekyll.logger.debug "EntryFilter:", "excluded?(#{relative_to_source(entry)}) ==> #{excluded}"
|
||||
excluded
|
||||
end
|
||||
|
||||
def symlink?(entry)
|
||||
File.symlink?(entry) && site.safe
|
||||
end
|
||||
|
||||
def ensure_leading_slash(path)
|
||||
path[0..0] == "/" ? path : "/#{path}"
|
||||
end
|
||||
|
||||
# Returns true if path matches against any glob pattern.
|
||||
# Look for more detail about glob pattern in method File::fnmatch.
|
||||
def glob_include?(enum, e)
|
||||
entry = ensure_leading_slash(e)
|
||||
enum.any? do |exp|
|
||||
item = ensure_leading_slash(exp)
|
||||
File.fnmatch?(item, entry) || entry.start_with?(item)
|
||||
def filter(entries)
|
||||
entries.reject do |e|
|
||||
unless included?(e)
|
||||
special?(e) || backup?(e) || excluded?(e) || symlink?(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def included?(entry)
|
||||
site.include.glob_include?(entry)
|
||||
end
|
||||
|
||||
def special?(entry)
|
||||
['.', '_', '#'].include?(entry[0..0])
|
||||
end
|
||||
|
||||
def backup?(entry)
|
||||
entry[-1..-1] == '~'
|
||||
end
|
||||
|
||||
def excluded?(entry)
|
||||
site.exclude.glob_include?(entry)
|
||||
end
|
||||
|
||||
def symlink?(entry)
|
||||
File.symlink?(entry) && site.safe
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
module Jekyll
|
||||
module Errors
|
||||
class FatalException < RuntimeError
|
||||
end
|
||||
|
||||
class MissingDependencyException < FatalException
|
||||
end
|
||||
class FatalException < StandardError
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
require 'forwardable'
|
||||
|
||||
module Jekyll
|
||||
class Excerpt
|
||||
include Convertible
|
||||
extend Forwardable
|
||||
|
||||
attr_accessor :post
|
||||
attr_accessor :content, :output, :ext
|
||||
|
||||
def_delegator :@post, :site, :site
|
||||
def_delegator :@post, :name, :name
|
||||
def_delegator :@post, :ext, :ext
|
||||
|
||||
# Initialize this Post instance.
|
||||
#
|
||||
# site - The Site.
|
||||
@@ -24,8 +17,14 @@ module Jekyll
|
||||
self.content = extract_excerpt(post.content)
|
||||
end
|
||||
|
||||
%w[site name ext].each do |meth|
|
||||
define_method(meth) do
|
||||
post.send(meth)
|
||||
end
|
||||
end
|
||||
|
||||
def to_liquid
|
||||
post.to_liquid(post.class::EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
||||
post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
||||
end
|
||||
|
||||
# Fetch YAML front-matter data from related post, without layout key
|
||||
@@ -38,7 +37,7 @@ module Jekyll
|
||||
end
|
||||
|
||||
# 'Path' of the excerpt.
|
||||
#
|
||||
#
|
||||
# Returns the path for the post this excerpt belongs to with #excerpt appended
|
||||
def path
|
||||
File.join(post.path, "#excerpt")
|
||||
@@ -46,9 +45,9 @@ module Jekyll
|
||||
|
||||
# Check if excerpt includes a string
|
||||
#
|
||||
# Returns true if the string passed in
|
||||
# Returns true if the string passed in
|
||||
def include?(something)
|
||||
(output && output.include?(something)) || content.include?(something)
|
||||
(self.output && self.output.include?(something)) || self.content.include?(something)
|
||||
end
|
||||
|
||||
# The UID for this post (useful in feeds).
|
||||
@@ -60,7 +59,7 @@ module Jekyll
|
||||
end
|
||||
|
||||
def to_s
|
||||
output || content
|
||||
self.output || self.content
|
||||
end
|
||||
|
||||
# Returns the shorthand String identifier of this Post.
|
||||
@@ -106,7 +105,7 @@ module Jekyll
|
||||
# Returns excerpt String
|
||||
def extract_excerpt(post_content)
|
||||
separator = site.config['excerpt_separator']
|
||||
head, _, tail = post_content.to_s.partition(separator)
|
||||
head, _, tail = post_content.partition(separator)
|
||||
|
||||
"" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
|
||||
end
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
module Jekyll
|
||||
module External
|
||||
class << self
|
||||
|
||||
#
|
||||
# Gems that, if installed, should be loaded.
|
||||
# Usually contain subcommands.
|
||||
#
|
||||
def blessed_gems
|
||||
%w{
|
||||
jekyll-docs
|
||||
jekyll-import
|
||||
}
|
||||
end
|
||||
|
||||
#
|
||||
# Require a gem or file if it's present, otherwise silently fail.
|
||||
#
|
||||
# names - a string gem name or array of gem names
|
||||
#
|
||||
def require_if_present(names)
|
||||
Array(names).each do |name|
|
||||
begin
|
||||
require name
|
||||
rescue LoadError
|
||||
Jekyll.logger.debug "Couldn't load #{name}. Skipping."
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Require a gem or gems. If it's not present, show a very nice error
|
||||
# message that explains everything and is much more helpful than the
|
||||
# normal LoadError.
|
||||
#
|
||||
# names - a string gem name or array of gem names
|
||||
#
|
||||
def require_with_graceful_fail(names)
|
||||
Array(names).each do |name|
|
||||
begin
|
||||
require name
|
||||
rescue LoadError => e
|
||||
Jekyll.logger.error "Dependency Error:", <<-MSG
|
||||
Yikes! It looks like you don't have #{name} or one of its dependencies installed.
|
||||
In order to use Jekyll as currently configured, you'll need to install this gem.
|
||||
|
||||
The full error message from Ruby is: '#{e.message}'
|
||||
|
||||
If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/!
|
||||
MSG
|
||||
raise Jekyll::Errors::MissingDependencyException.new(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@ module Jekyll
|
||||
# Returns the HTML formatted String.
|
||||
def textilize(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Textile)
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Textile)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
@@ -21,43 +21,10 @@ module Jekyll
|
||||
# Returns the HTML formatted String.
|
||||
def markdownify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
# Convert a Sass string into CSS output.
|
||||
#
|
||||
# input - The Sass String to convert.
|
||||
#
|
||||
# Returns the CSS formatted String.
|
||||
def sassify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Sass)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
# Convert a Scss string into CSS output.
|
||||
#
|
||||
# input - The Scss String to convert.
|
||||
#
|
||||
# Returns the CSS formatted String.
|
||||
def scssify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Scss)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
# Slugify a filename or title.
|
||||
#
|
||||
# input - The filename or title to slugify.
|
||||
#
|
||||
# Returns the given filename or title as a lowercase String, with every
|
||||
# sequence of spaces and non-alphanumeric characters replaced with a
|
||||
# hyphen.
|
||||
def slugify(input)
|
||||
Utils.slugify(input)
|
||||
end
|
||||
|
||||
# Format a date in short format e.g. "27 Jan 2011".
|
||||
#
|
||||
# date - the Time to format.
|
||||
@@ -116,7 +83,7 @@ module Jekyll
|
||||
#
|
||||
# Returns the escaped String.
|
||||
def xml_escape(input)
|
||||
CGI.escapeHTML(input.to_s)
|
||||
CGI.escapeHTML(input)
|
||||
end
|
||||
|
||||
# CGI escape a string for use in a URL. Replaces any special characters
|
||||
@@ -133,7 +100,7 @@ module Jekyll
|
||||
def cgi_escape(input)
|
||||
CGI::escape(input)
|
||||
end
|
||||
|
||||
|
||||
# URI escape a string.
|
||||
#
|
||||
# input - The String to escape.
|
||||
@@ -157,7 +124,7 @@ module Jekyll
|
||||
input.split.length
|
||||
end
|
||||
|
||||
# Join an array of things into a string by separating with commas and the
|
||||
# Join an array of things into a string by separating with commes and the
|
||||
# word "and" for the last one.
|
||||
#
|
||||
# array - The Array of Strings to join.
|
||||
@@ -188,113 +155,7 @@ module Jekyll
|
||||
#
|
||||
# Returns the converted json string
|
||||
def jsonify(input)
|
||||
as_liquid(input).to_json
|
||||
end
|
||||
|
||||
# Group an array of items by a property
|
||||
#
|
||||
# input - the inputted Enumerable
|
||||
# property - the property
|
||||
#
|
||||
# Returns an array of Hashes, each looking something like this:
|
||||
# {"name" => "larry"
|
||||
# "items" => [...] } # all the items where `property` == "larry"
|
||||
def group_by(input, property)
|
||||
if groupable?(input)
|
||||
input.group_by do |item|
|
||||
item_property(item, property).to_s
|
||||
end.inject([]) do |memo, i|
|
||||
memo << {"name" => i.first, "items" => i.last}
|
||||
end
|
||||
else
|
||||
input
|
||||
end
|
||||
end
|
||||
|
||||
# Filter an array of objects
|
||||
#
|
||||
# input - the object array
|
||||
# property - property within each object to filter by
|
||||
# value - desired value
|
||||
#
|
||||
# Returns the filtered array of objects
|
||||
def where(input, property, value)
|
||||
return input unless input.is_a?(Enumerable)
|
||||
input = input.values if input.is_a?(Hash)
|
||||
input.select { |object| item_property(object, property) == value }
|
||||
end
|
||||
|
||||
# Sort an array of objects
|
||||
#
|
||||
# input - the object array
|
||||
# property - property within each object to filter by
|
||||
# nils ('first' | 'last') - nils appear before or after non-nil values
|
||||
#
|
||||
# Returns the filtered array of objects
|
||||
def sort(input, property = nil, nils = "first")
|
||||
if property.nil?
|
||||
input.sort
|
||||
else
|
||||
case
|
||||
when nils == "first"
|
||||
order = - 1
|
||||
when nils == "last"
|
||||
order = + 1
|
||||
else
|
||||
raise ArgumentError.new("Invalid nils order: " +
|
||||
"'#{nils}' is not a valid nils order. It must be 'first' or 'last'.")
|
||||
end
|
||||
|
||||
input.sort { |apple, orange|
|
||||
apple_property = item_property(apple, property)
|
||||
orange_property = item_property(orange, property)
|
||||
|
||||
if !apple_property.nil? && orange_property.nil?
|
||||
- order
|
||||
elsif apple_property.nil? && !orange_property.nil?
|
||||
+ order
|
||||
else
|
||||
apple_property <=> orange_property
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def pop(array, input = 1)
|
||||
return array unless array.is_a?(Array)
|
||||
new_ary = array.dup
|
||||
new_ary.pop(input.to_i || 1)
|
||||
new_ary
|
||||
end
|
||||
|
||||
def push(array, input)
|
||||
return array unless array.is_a?(Array)
|
||||
new_ary = array.dup
|
||||
new_ary.push(input)
|
||||
new_ary
|
||||
end
|
||||
|
||||
def shift(array, input = 1)
|
||||
return array unless array.is_a?(Array)
|
||||
new_ary = array.dup
|
||||
new_ary.shift(input.to_i || 1)
|
||||
new_ary
|
||||
end
|
||||
|
||||
def unshift(array, input)
|
||||
return array unless array.is_a?(Array)
|
||||
new_ary = array.dup
|
||||
new_ary.unshift(input)
|
||||
new_ary
|
||||
end
|
||||
|
||||
# Convert an object into its String representation for debugging
|
||||
#
|
||||
# input - The Object to be converted
|
||||
#
|
||||
# Returns a String representation of the object.
|
||||
def inspect(input)
|
||||
CGI.escapeHTML(input.inspect)
|
||||
input.to_json
|
||||
end
|
||||
|
||||
private
|
||||
@@ -303,48 +164,10 @@ module Jekyll
|
||||
when Time
|
||||
input
|
||||
when String
|
||||
Time.parse(input) rescue Time.at(input.to_i)
|
||||
when Numeric
|
||||
Time.at(input)
|
||||
Time.parse(input)
|
||||
else
|
||||
Jekyll.logger.error "Invalid Date:", "'#{input}' is not a valid datetime."
|
||||
exit(1)
|
||||
end.localtime
|
||||
end
|
||||
|
||||
def groupable?(element)
|
||||
element.respond_to?(:group_by)
|
||||
end
|
||||
|
||||
def item_property(item, property)
|
||||
if item.respond_to?(:to_liquid)
|
||||
item.to_liquid[property.to_s]
|
||||
elsif item.respond_to?(:data)
|
||||
item.data[property.to_s]
|
||||
else
|
||||
item[property.to_s]
|
||||
end
|
||||
end
|
||||
|
||||
def as_liquid(item)
|
||||
case item
|
||||
when Hash
|
||||
pairs = item.map { |k, v| as_liquid([k, v]) }
|
||||
Hash[pairs]
|
||||
when Array
|
||||
item.map{ |i| as_liquid(i) }
|
||||
else
|
||||
if item.respond_to?(:to_liquid)
|
||||
liquidated = item.to_liquid
|
||||
# prevent infinite recursion for simple types (which return `self`)
|
||||
if liquidated == item
|
||||
item
|
||||
else
|
||||
as_liquid(liquidated)
|
||||
end
|
||||
else
|
||||
item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
module Jekyll
|
||||
# This class handles custom defaults for YAML frontmatter settings.
|
||||
# These are set in _config.yml and apply both to internal use (e.g. layout)
|
||||
# and the data available to liquid.
|
||||
#
|
||||
# It is exposed via the frontmatter_defaults method on the site class.
|
||||
class FrontmatterDefaults
|
||||
# Initializes a new instance.
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
|
||||
def update_deprecated_types(set)
|
||||
return set unless set.key?('scope') && set['scope'].key?('type')
|
||||
|
||||
set['scope']['type'] = case set['scope']['type']
|
||||
when 'page'
|
||||
Deprecator.defaults_deprecate_type('page', 'pages')
|
||||
'pages'
|
||||
when 'post'
|
||||
Deprecator.defaults_deprecate_type('post', 'posts')
|
||||
'posts'
|
||||
when 'draft'
|
||||
Deprecator.defaults_deprecate_type('draft', 'drafts')
|
||||
'drafts'
|
||||
else
|
||||
set['scope']['type']
|
||||
end
|
||||
|
||||
set
|
||||
end
|
||||
|
||||
# Finds a default value for a given setting, filtered by path and type
|
||||
#
|
||||
# path - the path (relative to the source) of the page, post or :draft the default is used in
|
||||
# type - a symbol indicating whether a :page, a :post or a :draft calls this method
|
||||
#
|
||||
# Returns the default value or nil if none was found
|
||||
def find(path, type, setting)
|
||||
value = nil
|
||||
old_scope = nil
|
||||
|
||||
matching_sets(path, type).each do |set|
|
||||
if set['values'].key?(setting) && has_precedence?(old_scope, set['scope'])
|
||||
value = set['values'][setting]
|
||||
old_scope = set['scope']
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# Collects a hash with all default values for a page or post
|
||||
#
|
||||
# path - the relative path of the page or post
|
||||
# type - a symbol indicating the type (:post, :page or :draft)
|
||||
#
|
||||
# Returns a hash with all default values (an empty hash if there are none)
|
||||
def all(path, type)
|
||||
defaults = {}
|
||||
old_scope = nil
|
||||
matching_sets(path, type).each do |set|
|
||||
if has_precedence?(old_scope, set['scope'])
|
||||
defaults = Utils.deep_merge_hashes(defaults, set['values'])
|
||||
old_scope = set['scope']
|
||||
else
|
||||
defaults = Utils.deep_merge_hashes(set['values'], defaults)
|
||||
end
|
||||
end
|
||||
defaults
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Checks if a given default setting scope matches the given path and type
|
||||
#
|
||||
# scope - the hash indicating the scope, as defined in _config.yml
|
||||
# path - the path to check for
|
||||
# type - the type (:post, :page or :draft) to check for
|
||||
#
|
||||
# Returns true if the scope applies to the given path and type
|
||||
def applies?(scope, path, type)
|
||||
applies_path?(scope, path) && applies_type?(scope, type)
|
||||
end
|
||||
|
||||
def applies_path?(scope, path)
|
||||
return true if !scope.has_key?('path') || scope['path'].empty?
|
||||
|
||||
scope_path = Pathname.new(scope['path'])
|
||||
Pathname.new(sanitize_path(path)).ascend do |path|
|
||||
if path == scope_path
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Determines whether the scope applies to type.
|
||||
# The scope applies to the type if:
|
||||
# 1. no 'type' is specified
|
||||
# 2. the 'type' in the scope is the same as the type asked about
|
||||
#
|
||||
# scope - the Hash defaults set being asked about application
|
||||
# type - the type of the document being processed / asked about
|
||||
# its defaults.
|
||||
#
|
||||
# Returns true if either of the above conditions are satisfied,
|
||||
# otherwise returns false
|
||||
def applies_type?(scope, type)
|
||||
!scope.key?('type') || scope['type'].eql?(type.to_s)
|
||||
end
|
||||
|
||||
# Checks if a given set of default values is valid
|
||||
#
|
||||
# set - the default value hash, as defined in _config.yml
|
||||
#
|
||||
# Returns true if the set is valid and can be used in this class
|
||||
def valid?(set)
|
||||
set.is_a?(Hash) && set['values'].is_a?(Hash)
|
||||
end
|
||||
|
||||
# Determines if a new scope has precedence over an old one
|
||||
#
|
||||
# old_scope - the old scope hash, or nil if there's none
|
||||
# new_scope - the new scope hash
|
||||
#
|
||||
# Returns true if the new scope has precedence over the older
|
||||
def has_precedence?(old_scope, new_scope)
|
||||
return true if old_scope.nil?
|
||||
|
||||
new_path = sanitize_path(new_scope['path'])
|
||||
old_path = sanitize_path(old_scope['path'])
|
||||
|
||||
if new_path.length != old_path.length
|
||||
new_path.length >= old_path.length
|
||||
elsif new_scope.key? 'type'
|
||||
true
|
||||
else
|
||||
!old_scope.key? 'type'
|
||||
end
|
||||
end
|
||||
|
||||
# Collects a list of sets that match the given path and type
|
||||
#
|
||||
# Returns an array of hashes
|
||||
def matching_sets(path, type)
|
||||
valid_sets.select do |set|
|
||||
!set.has_key?('scope') || applies?(set['scope'], path, type)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a list of valid sets
|
||||
#
|
||||
# This is not cached to allow plugins to modify the configuration
|
||||
# and have their changes take effect
|
||||
#
|
||||
# Returns an array of hashes
|
||||
def valid_sets
|
||||
sets = @site.config['defaults']
|
||||
return [] unless sets.is_a?(Array)
|
||||
|
||||
sets.map do |set|
|
||||
if valid?(set)
|
||||
update_deprecated_types(set)
|
||||
else
|
||||
Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
|
||||
Jekyll.logger.warn "#{set}"
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
# Sanitizes the given path by removing a leading and addding a trailing slash
|
||||
def sanitize_path(path)
|
||||
if path.nil? || path.empty?
|
||||
""
|
||||
else
|
||||
path.gsub(/\A\//, '').gsub(/([^\/])\z/, '\1/')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
217
lib/jekyll/generators/pagination.rb
Normal file
217
lib/jekyll/generators/pagination.rb
Normal file
@@ -0,0 +1,217 @@
|
||||
module Jekyll
|
||||
module Generators
|
||||
class Pagination < Generator
|
||||
# This generator is safe from arbitrary code execution.
|
||||
safe true
|
||||
|
||||
# This generator should be passive with regard to its execution
|
||||
priority :lowest
|
||||
|
||||
# Generate paginated pages if necessary.
|
||||
#
|
||||
# site - The Site.
|
||||
#
|
||||
# Returns nothing.
|
||||
def generate(site)
|
||||
if Pager.pagination_enabled?(site)
|
||||
if template = template_page(site)
|
||||
paginate(site, template)
|
||||
else
|
||||
Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
|
||||
"an index.html page to use as the pagination template. Skipping pagination."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Paginates the blog's posts. Renders the index.html file into paginated
|
||||
# directories, e.g.: page2/index.html, page3/index.html, etc and adds more
|
||||
# site-wide data.
|
||||
#
|
||||
# site - The Site.
|
||||
# page - The index.html Page that requires pagination.
|
||||
#
|
||||
# {"paginator" => { "page" => <Number>,
|
||||
# "per_page" => <Number>,
|
||||
# "posts" => [<Post>],
|
||||
# "total_posts" => <Number>,
|
||||
# "total_pages" => <Number>,
|
||||
# "previous_page" => <Number>,
|
||||
# "next_page" => <Number> }}
|
||||
def paginate(site, page)
|
||||
all_posts = site.site_payload['site']['posts']
|
||||
pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
|
||||
(1..pages).each do |num_page|
|
||||
pager = Pager.new(site, num_page, all_posts, pages)
|
||||
if num_page > 1
|
||||
newpage = Page.new(site, site.source, page.dir, page.name)
|
||||
newpage.pager = pager
|
||||
newpage.dir = Pager.paginate_path(site, num_page)
|
||||
site.pages << newpage
|
||||
else
|
||||
page.pager = pager
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Static: Fetch the URL of the template page. Used to determine the
|
||||
# path to the first pager in the series.
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
#
|
||||
# Returns the url of the template page
|
||||
def self.first_page_url(site)
|
||||
if page = Pagination.new.template_page(site)
|
||||
page.url
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Find the Jekyll::Page which will act as the pager template
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
#
|
||||
# Returns the Jekyll::Page which will act as the pager template
|
||||
def template_page(site)
|
||||
site.pages.dup.select do |page|
|
||||
Pager.pagination_candidate?(site.config, page)
|
||||
end.sort do |one, two|
|
||||
two.path.size <=> one.path.size
|
||||
end.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Pager
|
||||
attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
|
||||
:previous_page, :previous_page_path, :next_page, :next_page_path
|
||||
|
||||
# Calculate the number of pages.
|
||||
#
|
||||
# all_posts - The Array of all Posts.
|
||||
# per_page - The Integer of entries per page.
|
||||
#
|
||||
# Returns the Integer number of pages.
|
||||
def self.calculate_pages(all_posts, per_page)
|
||||
(all_posts.size.to_f / per_page.to_i).ceil
|
||||
end
|
||||
|
||||
# Determine if pagination is enabled the site.
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
#
|
||||
# Returns true if pagination is enabled, false otherwise.
|
||||
def self.pagination_enabled?(site)
|
||||
!site.config['paginate'].nil? &&
|
||||
site.pages.size > 0
|
||||
end
|
||||
|
||||
# Static: Determine if a page is a possible candidate to be a template page.
|
||||
# Page's name must be `index.html` and exist in any of the directories
|
||||
# between the site source and `paginate_path`.
|
||||
#
|
||||
# config - the site configuration hash
|
||||
# page - the Jekyll::Page about which we're inquiring
|
||||
#
|
||||
# Returns true if the
|
||||
def self.pagination_candidate?(config, page)
|
||||
page_dir = File.dirname(File.expand_path(remove_leading_slash(page.path), config['source']))
|
||||
paginate_path = remove_leading_slash(config['paginate_path'])
|
||||
paginate_path = File.expand_path(paginate_path, config['source'])
|
||||
page.name == 'index.html' &&
|
||||
in_hierarchy(config['source'], page_dir, File.dirname(paginate_path))
|
||||
end
|
||||
|
||||
# Determine if the subdirectories of the two paths are the same relative to source
|
||||
#
|
||||
# source - the site source
|
||||
# page_dir - the directory of the Jekyll::Page
|
||||
# paginate_path - the absolute paginate path (from root of FS)
|
||||
#
|
||||
# Returns whether the subdirectories are the same relative to source
|
||||
def self.in_hierarchy(source, page_dir, paginate_path)
|
||||
return false if paginate_path == File.dirname(paginate_path)
|
||||
return false if paginate_path == Pathname.new(source).parent
|
||||
page_dir == paginate_path ||
|
||||
in_hierarchy(source, page_dir, File.dirname(paginate_path))
|
||||
end
|
||||
|
||||
# Static: Return the pagination path of the page
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
# num_page - the pagination page number
|
||||
#
|
||||
# Returns the pagination path as a string
|
||||
def self.paginate_path(site, num_page)
|
||||
return nil if num_page.nil?
|
||||
return Generators::Pagination.first_page_url(site) if num_page <= 1
|
||||
format = site.config['paginate_path']
|
||||
format = format.sub(':num', num_page.to_s)
|
||||
ensure_leading_slash(format)
|
||||
end
|
||||
|
||||
# Static: Return a String version of the input which has a leading slash.
|
||||
# If the input already has a forward slash in position zero, it will be
|
||||
# returned unchanged.
|
||||
#
|
||||
# path - a String path
|
||||
#
|
||||
# Returns the path with a leading slash
|
||||
def self.ensure_leading_slash(path)
|
||||
path[0..0] == "/" ? path : "/#{path}"
|
||||
end
|
||||
|
||||
# Static: Return a String version of the input without a leading slash.
|
||||
#
|
||||
# path - a String path
|
||||
#
|
||||
# Returns the input without the leading slash
|
||||
def self.remove_leading_slash(path)
|
||||
ensure_leading_slash(path)[1..-1]
|
||||
end
|
||||
|
||||
# Initialize a new Pager.
|
||||
#
|
||||
# site - the Jekyll::Site object
|
||||
# page - The Integer page number.
|
||||
# all_posts - The Array of all the site's Posts.
|
||||
# num_pages - The Integer number of pages or nil if you'd like the number
|
||||
# of pages calculated.
|
||||
def initialize(site, page, all_posts, num_pages = nil)
|
||||
@page = page
|
||||
@per_page = site.config['paginate'].to_i
|
||||
@total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
|
||||
|
||||
if @page > @total_pages
|
||||
raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
|
||||
end
|
||||
|
||||
init = (@page - 1) * @per_page
|
||||
offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
|
||||
|
||||
@total_posts = all_posts.size
|
||||
@posts = all_posts[init..offset]
|
||||
@previous_page = @page != 1 ? @page - 1 : nil
|
||||
@previous_page_path = Pager.paginate_path(site, @previous_page)
|
||||
@next_page = @page != @total_pages ? @page + 1 : nil
|
||||
@next_page_path = Pager.paginate_path(site, @next_page)
|
||||
end
|
||||
|
||||
# Convert this Pager's data to a Hash suitable for use by Liquid.
|
||||
#
|
||||
# Returns the Hash representation of this Pager.
|
||||
def to_liquid
|
||||
{
|
||||
'page' => page,
|
||||
'per_page' => per_page,
|
||||
'posts' => posts,
|
||||
'total_posts' => total_posts,
|
||||
'total_pages' => total_pages,
|
||||
'previous_page' => previous_page,
|
||||
'previous_page_path' => previous_page_path,
|
||||
'next_page' => next_page,
|
||||
'next_page_path' => next_page_path
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,9 +8,6 @@ module Jekyll
|
||||
# Gets the name of this layout.
|
||||
attr_reader :name
|
||||
|
||||
# Gets the path to this layout.
|
||||
attr_reader :path
|
||||
|
||||
# Gets/Sets the extension of this layout.
|
||||
attr_accessor :ext
|
||||
|
||||
@@ -29,12 +26,11 @@ module Jekyll
|
||||
@site = site
|
||||
@base = base
|
||||
@name = name
|
||||
@path = site.in_source_dir(base, name)
|
||||
|
||||
self.data = {}
|
||||
|
||||
process(name)
|
||||
read_yaml(base, name)
|
||||
self.process(name)
|
||||
self.read_yaml(base, name)
|
||||
end
|
||||
|
||||
# Extract information from the layout filename.
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
module Jekyll
|
||||
class LayoutReader
|
||||
attr_reader :site
|
||||
def initialize(site)
|
||||
@site = site
|
||||
@layouts = {}
|
||||
end
|
||||
|
||||
def read
|
||||
layout_entries.each do |f|
|
||||
@layouts[layout_name(f)] = Layout.new(site, layout_directory, f)
|
||||
end
|
||||
|
||||
@layouts
|
||||
end
|
||||
|
||||
def layout_directory
|
||||
@layout_directory ||= (layout_directory_in_cwd || layout_directory_inside_source)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def layout_entries
|
||||
entries = []
|
||||
within(layout_directory) do
|
||||
entries = EntryFilter.new(site).filter(Dir['**/*.*'])
|
||||
end
|
||||
entries
|
||||
end
|
||||
|
||||
def layout_name(file)
|
||||
file.split(".")[0..-2].join(".")
|
||||
end
|
||||
|
||||
def within(directory)
|
||||
return unless File.exist?(directory)
|
||||
Dir.chdir(directory) { yield }
|
||||
end
|
||||
|
||||
def layout_directory_inside_source
|
||||
site.in_source_dir(site.config['layouts'])
|
||||
end
|
||||
|
||||
def layout_directory_in_cwd
|
||||
dir = Jekyll.sanitized_path(Dir.pwd, site.config['layouts'])
|
||||
if File.directory?(dir) && !site.safe
|
||||
dir
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
module Jekyll
|
||||
module LiquidExtensions
|
||||
|
||||
# Lookup a Liquid variable in the given context.
|
||||
#
|
||||
# context - the Liquid context in question.
|
||||
# variable - the variable name, as a string.
|
||||
#
|
||||
# Returns the value of the variable in the context
|
||||
# or the variable name if not found.
|
||||
def lookup_variable(context, variable)
|
||||
lookup = context
|
||||
|
||||
variable.split(".").each do |value|
|
||||
lookup = lookup[value]
|
||||
end
|
||||
|
||||
lookup || variable
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,105 +0,0 @@
|
||||
module Jekyll
|
||||
class LogAdapter
|
||||
attr_reader :writer, :messages
|
||||
|
||||
LOG_LEVELS = {
|
||||
:debug => ::Logger::DEBUG,
|
||||
:info => ::Logger::INFO,
|
||||
:warn => ::Logger::WARN,
|
||||
:error => ::Logger::ERROR
|
||||
}
|
||||
|
||||
# Public: Create a new instance of Jekyll's log writer
|
||||
#
|
||||
# writer - Logger compatible instance
|
||||
# log_level - (optional, symbol) the log level
|
||||
#
|
||||
# Returns nothing
|
||||
def initialize(writer, level = :info)
|
||||
@messages = []
|
||||
@writer = writer
|
||||
self.log_level = level
|
||||
end
|
||||
|
||||
# Public: Set the log level on the writer
|
||||
#
|
||||
# level - (symbol) the log level
|
||||
#
|
||||
# Returns nothing
|
||||
def log_level=(level)
|
||||
writer.level = LOG_LEVELS.fetch(level)
|
||||
end
|
||||
|
||||
# Public: Print a jekyll debug message
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def debug(topic, message = nil)
|
||||
writer.debug(message(topic, message))
|
||||
end
|
||||
|
||||
# Public: Print a jekyll message
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def info(topic, message = nil)
|
||||
writer.info(message(topic, message))
|
||||
end
|
||||
|
||||
# Public: Print a jekyll message
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def warn(topic, message = nil)
|
||||
writer.warn(message(topic, message))
|
||||
end
|
||||
|
||||
# Public: Print a jekyll error message
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def error(topic, message = nil)
|
||||
writer.error(message(topic, message))
|
||||
end
|
||||
|
||||
# Public: Print a Jekyll error message and immediately abort the process
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail (can be omitted)
|
||||
#
|
||||
# Returns nothing
|
||||
def abort_with(topic, message = nil)
|
||||
error(topic, message)
|
||||
abort
|
||||
end
|
||||
|
||||
# Internal: Build a Jekyll topic method
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns the formatted message
|
||||
def message(topic, message)
|
||||
msg = formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ')
|
||||
messages << msg
|
||||
msg
|
||||
end
|
||||
|
||||
# Internal: Format the topic
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
#
|
||||
# Returns the formatted topic statement
|
||||
def formatted_topic(topic)
|
||||
"#{topic} ".rjust(20)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,121 +0,0 @@
|
||||
module Jekyll
|
||||
class Metadata
|
||||
attr_reader :site, :metadata, :cache
|
||||
|
||||
def initialize(site)
|
||||
@site = site
|
||||
|
||||
# Read metadata from file
|
||||
read_metadata
|
||||
|
||||
# Initialize cache to an empty hash
|
||||
@cache = {}
|
||||
end
|
||||
|
||||
# Add a path to the metadata
|
||||
#
|
||||
# Returns true, also on failure.
|
||||
def add(path)
|
||||
return true unless File.exist?(path)
|
||||
|
||||
metadata[path] = {
|
||||
"mtime" => File.mtime(path),
|
||||
"deps" => []
|
||||
}
|
||||
cache[path] = true
|
||||
end
|
||||
|
||||
# Force a path to regenerate
|
||||
#
|
||||
# Returns true.
|
||||
def force(path)
|
||||
cache[path] = true
|
||||
end
|
||||
|
||||
# Clear the metadata and cache
|
||||
#
|
||||
# Returns nothing
|
||||
def clear
|
||||
@metadata = {}
|
||||
@cache = {}
|
||||
end
|
||||
|
||||
# Checks if a path should be regenerated
|
||||
#
|
||||
# Returns a boolean.
|
||||
def regenerate?(path, add = true)
|
||||
return true if disabled?
|
||||
|
||||
# Check for path in cache
|
||||
if cache.has_key? path
|
||||
return cache[path]
|
||||
end
|
||||
|
||||
# Check path that exists in metadata
|
||||
data = metadata[path]
|
||||
if data
|
||||
data["deps"].each do |dependency|
|
||||
if regenerate?(dependency)
|
||||
return cache[dependency] = cache[path] = true
|
||||
end
|
||||
end
|
||||
if data["mtime"].eql? File.mtime(path)
|
||||
return cache[path] = false
|
||||
else
|
||||
return !add || add(path)
|
||||
end
|
||||
end
|
||||
|
||||
# Path does not exist in metadata, add it
|
||||
return !add || add(path)
|
||||
end
|
||||
|
||||
# Add a dependency of a path
|
||||
#
|
||||
# Returns nothing.
|
||||
def add_dependency(path, dependency)
|
||||
return if (metadata[path].nil? || @disabled)
|
||||
|
||||
metadata[path]["deps"] << dependency unless metadata[path]["deps"].include? dependency
|
||||
regenerate? dependency
|
||||
end
|
||||
|
||||
# Write the metadata to disk
|
||||
#
|
||||
# Returns nothing.
|
||||
def write
|
||||
File.open(metadata_file, 'w') do |f|
|
||||
f.write(metadata.to_yaml)
|
||||
end
|
||||
end
|
||||
|
||||
# Produce the absolute path of the metadata file
|
||||
#
|
||||
# Returns the String path of the file.
|
||||
def metadata_file
|
||||
site.in_source_dir('.jekyll-metadata')
|
||||
end
|
||||
|
||||
# Check if metadata has been disabled
|
||||
#
|
||||
# Returns a Boolean (true for disabled, false for enabled).
|
||||
def disabled?
|
||||
@disabled = site.full_rebuild? if @disabled.nil?
|
||||
@disabled
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Read metadata from the metadata file, if no file is found,
|
||||
# initialize with an empty hash
|
||||
#
|
||||
# Returns the read metadata.
|
||||
def read_metadata
|
||||
@metadata = if !disabled? && File.file?(metadata_file)
|
||||
SafeYAML.load(File.read(metadata_file))
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,12 @@
|
||||
-# These are the same MIME types that GitHub Pages uses as of 26 January 2014
|
||||
# These are the same MIME types that GitHub Pages uses as of 17 Mar 2013.
|
||||
|
||||
text/html html htm shtml
|
||||
text/css css
|
||||
text/xml xml rss xsl xsd
|
||||
text/xml xml rss xsl
|
||||
image/gif gif
|
||||
image/jpeg jpeg jpg
|
||||
application/x-javascript js
|
||||
application/atom+xml atom
|
||||
application/json json geojson topojson
|
||||
|
||||
text/mathml mml
|
||||
text/plain txt
|
||||
@@ -18,22 +17,16 @@ text/cache-manifest manifest appcache
|
||||
text/coffeescript coffee
|
||||
text/plain pde
|
||||
text/plain md markdown
|
||||
text/vcard vcf vcard
|
||||
|
||||
image/png png
|
||||
image/svg+xml svg
|
||||
image/svg+xml svgz
|
||||
image/tiff tif tiff
|
||||
image/vnd.wap.wbmp wbmp
|
||||
image/x-icon ico
|
||||
image/x-jng jng
|
||||
image/x-ms-bmp bmp
|
||||
|
||||
application/vnd.ms-fontobject eot
|
||||
application/x-font-ttf ttf
|
||||
application/x-font-woff woff
|
||||
font/opentype otf
|
||||
|
||||
application/json json
|
||||
application/java-archive jar ear
|
||||
application/mac-binhex40 hqx
|
||||
application/msword doc
|
||||
@@ -41,19 +34,18 @@ application/pdf pdf
|
||||
application/postscript ps eps ai
|
||||
application/rdf+xml rdf
|
||||
application/rtf rtf
|
||||
text/vcard vcf vcard
|
||||
application/vnd.apple.pkpass pkpass
|
||||
application/vnd.ms-excel xls
|
||||
application/vnd.ms-powerpoint ppt
|
||||
application/vnd.wap.wmlc wmlc
|
||||
application/xhtml+xml xhtml
|
||||
application/x-cocoa cco
|
||||
application/x-chrome-extension crx
|
||||
application/x-cocoa cco
|
||||
application/x-font-ttf ttf
|
||||
application/x-java-archive-diff jardiff
|
||||
application/x-java-jnlp-file jnlp
|
||||
application/x-makeself run
|
||||
application/x-ms-application application
|
||||
application/x-ms-manifest manifest
|
||||
application/x-ms-vsto vsto
|
||||
application/x-ns-proxy-autoconfig pac
|
||||
application/x-perl pl pm
|
||||
application/x-pilot prc pdb
|
||||
@@ -71,8 +63,8 @@ application/zip zip
|
||||
|
||||
application/octet-stream bin exe dll
|
||||
application/octet-stream deb
|
||||
application/octet-stream deploy
|
||||
application/octet-stream dmg
|
||||
application/octet-stream eot
|
||||
application/octet-stream iso img
|
||||
application/octet-stream msi msp msm
|
||||
|
||||
@@ -82,14 +74,12 @@ audio/x-realaudio ra
|
||||
audio/ogg ogg
|
||||
|
||||
video/3gpp 3gpp 3gp
|
||||
video/m4v m4v
|
||||
video/mp4 mp4
|
||||
video/mpeg mpeg mpg
|
||||
video/ogg ogg ogv
|
||||
video/quicktime mov
|
||||
video/webm webm
|
||||
video/x-flv flv
|
||||
video/x-mng mng
|
||||
video/x-ms-asf asx asf
|
||||
video/x-ms-wmv wmv
|
||||
video/x-msvideo avi
|
||||
video/ogg ogv
|
||||
video/webm webm
|
||||
|
||||
@@ -9,11 +9,9 @@ module Jekyll
|
||||
|
||||
# Attributes for Liquid templates
|
||||
ATTRIBUTES_FOR_LIQUID = %w[
|
||||
content
|
||||
dir
|
||||
name
|
||||
path
|
||||
url
|
||||
content
|
||||
path
|
||||
]
|
||||
|
||||
# Initialize a new Page.
|
||||
@@ -28,13 +26,8 @@ module Jekyll
|
||||
@dir = dir
|
||||
@name = name
|
||||
|
||||
|
||||
process(name)
|
||||
read_yaml(File.join(base, dir), name)
|
||||
|
||||
data.default_proc = proc do |hash, key|
|
||||
site.frontmatter_defaults.find(File.join(dir, name), type, key)
|
||||
end
|
||||
self.process(name)
|
||||
self.read_yaml(File.join(base, dir), name)
|
||||
end
|
||||
|
||||
# The generated directory into which the page will be placed
|
||||
@@ -51,11 +44,11 @@ module Jekyll
|
||||
#
|
||||
# Returns the String permalink or nil if none has been set.
|
||||
def permalink
|
||||
return nil if data.nil? || data['permalink'].nil?
|
||||
return nil if self.data.nil? || self.data['permalink'].nil?
|
||||
if site.config['relative_permalinks']
|
||||
File.join(@dir, data['permalink'])
|
||||
File.join(@dir, self.data['permalink'])
|
||||
else
|
||||
data['permalink']
|
||||
self.data['permalink']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,7 +56,7 @@ module Jekyll
|
||||
#
|
||||
# Returns the template String.
|
||||
def template
|
||||
if site.permalink_style == :pretty
|
||||
if self.site.permalink_style == :pretty
|
||||
if index? && html?
|
||||
"/:path/"
|
||||
elsif html?
|
||||
@@ -92,8 +85,8 @@ module Jekyll
|
||||
def url_placeholders
|
||||
{
|
||||
:path => @dir,
|
||||
:basename => basename,
|
||||
:output_ext => output_ext
|
||||
:basename => self.basename,
|
||||
:output_ext => self.output_ext
|
||||
}
|
||||
end
|
||||
|
||||
@@ -104,7 +97,7 @@ module Jekyll
|
||||
# Returns nothing.
|
||||
def process(name)
|
||||
self.ext = File.extname(name)
|
||||
self.basename = name[0 .. -ext.length - 1]
|
||||
self.basename = name[0 .. -self.ext.length-1]
|
||||
end
|
||||
|
||||
# Add any necessary layouts to this post
|
||||
@@ -114,10 +107,10 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def render(layouts, site_payload)
|
||||
payload = Utils.deep_merge_hashes({
|
||||
"page" => to_liquid,
|
||||
payload = {
|
||||
"page" => self.to_liquid,
|
||||
'paginator' => pager.to_liquid
|
||||
}, site_payload)
|
||||
}.deep_merge(site_payload)
|
||||
|
||||
do_layout(payload, layouts)
|
||||
end
|
||||
@@ -126,12 +119,12 @@ module Jekyll
|
||||
#
|
||||
# Returns the path to the source file
|
||||
def path
|
||||
data.fetch('path') { relative_path.sub(/\A\//, '') }
|
||||
self.data.fetch('path', self.relative_path.sub(/\A\//, ''))
|
||||
end
|
||||
|
||||
# The path to the page source file, relative to the site source
|
||||
def relative_path
|
||||
File.join(*[@dir, @name].map(&:to_s).reject(&:empty?))
|
||||
File.join(@dir, @name)
|
||||
end
|
||||
|
||||
# Obtain destination path.
|
||||
@@ -140,14 +133,14 @@ module Jekyll
|
||||
#
|
||||
# Returns the destination file path String.
|
||||
def destination(dest)
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if url =~ /\/$/
|
||||
path = File.join(dest, self.url)
|
||||
path = File.join(path, "index.html") if self.url =~ /\/$/
|
||||
path
|
||||
end
|
||||
|
||||
# Returns the object as a debug String.
|
||||
def inspect
|
||||
"#<Jekyll:Page @name=#{name.inspect}>"
|
||||
"#<Jekyll:Page @name=#{self.name.inspect}>"
|
||||
end
|
||||
|
||||
# Returns the Boolean of whether this Page is HTML or not.
|
||||
@@ -161,7 +154,7 @@ module Jekyll
|
||||
end
|
||||
|
||||
def uses_relative_permalinks
|
||||
permalink && !@dir.empty? && site.config['relative_permalinks']
|
||||
permalink && @dir != "" && site.config['relative_permalinks']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,15 +6,22 @@ module Jekyll
|
||||
:high => 10,
|
||||
:highest => 100 }
|
||||
|
||||
# Fetch all the subclasses of this class and its subclasses' subclasses.
|
||||
# Install a hook so that subclasses are recorded. This method is only
|
||||
# ever called by Ruby itself.
|
||||
#
|
||||
# Returns an array of descendant classes.
|
||||
def self.descendants
|
||||
descendants = []
|
||||
ObjectSpace.each_object(singleton_class) do |k|
|
||||
descendants.unshift k unless k == self
|
||||
end
|
||||
descendants
|
||||
# base - The Class subclass.
|
||||
#
|
||||
# Returns nothing.
|
||||
def self.inherited(base)
|
||||
subclasses << base
|
||||
subclasses.sort!
|
||||
end
|
||||
|
||||
# The list of Classes that have been subclassed.
|
||||
#
|
||||
# Returns an Array of Class objects.
|
||||
def self.subclasses
|
||||
@subclasses ||= []
|
||||
end
|
||||
|
||||
# Get or set the priority of this plugin. When called without an
|
||||
@@ -27,7 +34,7 @@ module Jekyll
|
||||
# Returns the Symbol priority.
|
||||
def self.priority(priority = nil)
|
||||
@priority ||= nil
|
||||
if priority && PRIORITIES.key?(priority)
|
||||
if priority && PRIORITIES.has_key?(priority)
|
||||
@priority = priority
|
||||
end
|
||||
@priority || :normal
|
||||
@@ -56,15 +63,6 @@ module Jekyll
|
||||
PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
|
||||
end
|
||||
|
||||
# Spaceship is priority [higher -> lower]
|
||||
#
|
||||
# other - The class to be compared.
|
||||
#
|
||||
# Returns -1, 0, 1.
|
||||
def <=>(other)
|
||||
self.class <=> other.class
|
||||
end
|
||||
|
||||
# Initialize a new plugin. This should be overridden by the subclass.
|
||||
#
|
||||
# config - The Hash of configuration options.
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
module Jekyll
|
||||
class PluginManager
|
||||
attr_reader :site
|
||||
|
||||
# Create an instance of this class.
|
||||
#
|
||||
# site - the instance of Jekyll::Site we're concerned with
|
||||
#
|
||||
# Returns nothing
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
|
||||
# Require all the plugins which are allowed.
|
||||
#
|
||||
# Returns nothing
|
||||
def conscientious_require
|
||||
require_plugin_files
|
||||
require_gems
|
||||
end
|
||||
|
||||
# Require each of the gem plugins specified.
|
||||
#
|
||||
# Returns nothing.
|
||||
def require_gems
|
||||
site.gems.each do |gem|
|
||||
if plugin_allowed?(gem)
|
||||
Jekyll.logger.debug("PluginManager:", "Requiring #{gem}")
|
||||
require gem
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.require_from_bundler
|
||||
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
|
||||
require "bundler"
|
||||
Bundler.setup # puts all groups on the load path
|
||||
required_gems = Bundler.require(:jekyll_plugins) # requires the gems in this group only
|
||||
Jekyll.logger.debug("PluginManager:", "Required #{required_gems.map(&:name).join(', ')}")
|
||||
ENV["JEKYLL_NO_BUNDLER_REQUIRE"] = "true"
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
rescue LoadError, Bundler::GemfileNotFound
|
||||
false
|
||||
end
|
||||
|
||||
# Check whether a gem plugin is allowed to be used during this build.
|
||||
#
|
||||
# gem_name - the name of the gem
|
||||
#
|
||||
# Returns true if the gem name is in the whitelist or if the site is not
|
||||
# in safe mode.
|
||||
def plugin_allowed?(gem_name)
|
||||
!site.safe || whitelist.include?(gem_name)
|
||||
end
|
||||
|
||||
# Build an array of allowed plugin gem names.
|
||||
#
|
||||
# Returns an array of strings, each string being the name of a gem name
|
||||
# that is allowed to be used.
|
||||
def whitelist
|
||||
@whitelist ||= Array[site.config['whitelist']].flatten
|
||||
end
|
||||
|
||||
# Require all .rb files if safe mode is off
|
||||
#
|
||||
# Returns nothing.
|
||||
def require_plugin_files
|
||||
unless site.safe
|
||||
plugins_path.each do |plugins|
|
||||
Dir[File.join(plugins, "**", "*.rb")].sort.each do |f|
|
||||
require f
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Setup the plugin search path
|
||||
#
|
||||
# Returns an Array of plugin search paths
|
||||
def plugins_path
|
||||
if (site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
|
||||
[site.in_source_dir(site.config['plugins'])]
|
||||
else
|
||||
Array(site.config['plugins']).map { |d| File.expand_path(d) }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,6 @@ module Jekyll
|
||||
EXCERPT_ATTRIBUTES_FOR_LIQUID = %w[
|
||||
title
|
||||
url
|
||||
dir
|
||||
date
|
||||
id
|
||||
categories
|
||||
@@ -35,7 +34,7 @@ module Jekyll
|
||||
|
||||
attr_accessor :site
|
||||
attr_accessor :data, :extracted_excerpt, :content, :output, :ext
|
||||
attr_accessor :date, :slug, :tags, :categories
|
||||
attr_accessor :date, :slug, :published, :tags, :categories
|
||||
|
||||
attr_reader :name
|
||||
|
||||
@@ -49,27 +48,25 @@ module Jekyll
|
||||
def initialize(site, source, dir, name)
|
||||
@site = site
|
||||
@dir = dir
|
||||
@base = containing_dir(dir)
|
||||
@base = self.containing_dir(source, dir)
|
||||
@name = name
|
||||
|
||||
self.categories = dir.downcase.split('/').reject { |x| x.empty? }
|
||||
process(name)
|
||||
read_yaml(@base, name)
|
||||
self.process(name)
|
||||
self.read_yaml(@base, name)
|
||||
|
||||
data.default_proc = proc do |hash, key|
|
||||
site.frontmatter_defaults.find(File.join(dir, name), type, key)
|
||||
if self.data.has_key?('date')
|
||||
self.date = Time.parse(self.data["date"].to_s)
|
||||
end
|
||||
|
||||
if data.key?('date')
|
||||
self.date = Utils.parse_date(data["date"].to_s, "Post '#{relative_path}' does not have a valid date in the YAML front matter.")
|
||||
end
|
||||
self.published = self.published?
|
||||
|
||||
populate_categories
|
||||
populate_tags
|
||||
self.populate_categories
|
||||
self.populate_tags
|
||||
end
|
||||
|
||||
def published?
|
||||
if data.key?('published') && data['published'] == false
|
||||
if self.data.has_key?('published') && self.data['published'] == false
|
||||
false
|
||||
else
|
||||
true
|
||||
@@ -77,19 +74,19 @@ module Jekyll
|
||||
end
|
||||
|
||||
def populate_categories
|
||||
categories_from_data = Utils.pluralized_array_from_hash(data, 'category', 'categories')
|
||||
self.categories = (
|
||||
Array(categories) + categories_from_data
|
||||
).map {|c| c.to_s.downcase}.flatten.uniq
|
||||
if self.categories.empty?
|
||||
self.categories = self.data.pluralized_array('category', 'categories').map {|c| c.to_s.downcase}
|
||||
end
|
||||
self.categories.flatten!
|
||||
end
|
||||
|
||||
def populate_tags
|
||||
self.tags = Utils.pluralized_array_from_hash(data, "tag", "tags").flatten
|
||||
self.tags = self.data.pluralized_array("tag", "tags").flatten
|
||||
end
|
||||
|
||||
# Get the full path to the directory containing the post files
|
||||
def containing_dir(dir)
|
||||
site.in_source_dir(dir, '_posts')
|
||||
def containing_dir(source, dir)
|
||||
return File.join(source, dir, '_posts')
|
||||
end
|
||||
|
||||
# Read the YAML frontmatter.
|
||||
@@ -100,7 +97,7 @@ module Jekyll
|
||||
# Returns nothing.
|
||||
def read_yaml(base, name)
|
||||
super(base, name)
|
||||
self.extracted_excerpt = extract_excerpt
|
||||
self.extracted_excerpt = self.extract_excerpt
|
||||
end
|
||||
|
||||
# The post excerpt. This is either a custom excerpt
|
||||
@@ -108,19 +105,19 @@ module Jekyll
|
||||
#
|
||||
# Returns excerpt string.
|
||||
def excerpt
|
||||
data.fetch('excerpt') { extracted_excerpt.to_s }
|
||||
self.data.fetch('excerpt', self.extracted_excerpt.to_s)
|
||||
end
|
||||
|
||||
# Public: the Post title, from the YAML Front-Matter or from the slug
|
||||
#
|
||||
# Returns the post title
|
||||
def title
|
||||
data.fetch('title') { titleized_slug }
|
||||
self.data.fetch("title", self.titleized_slug)
|
||||
end
|
||||
|
||||
# Turns the post slug into a suitable title
|
||||
def titleized_slug
|
||||
slug.split('-').select {|w| w.capitalize! || w }.join(' ')
|
||||
self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')
|
||||
end
|
||||
|
||||
# Public: the path to the post relative to the site source,
|
||||
@@ -130,12 +127,12 @@ module Jekyll
|
||||
#
|
||||
# Returns the path to the file relative to the site source
|
||||
def path
|
||||
data.fetch('path') { relative_path.sub(/\A\//, '') }
|
||||
self.data.fetch('path', self.relative_path.sub(/\A\//, ''))
|
||||
end
|
||||
|
||||
# The path to the post source file, relative to the site source
|
||||
def relative_path
|
||||
File.join(*[@dir, "_posts", @name].map(&:to_s).reject(&:empty?))
|
||||
File.join(@dir, '_posts', @name)
|
||||
end
|
||||
|
||||
# Compares Post objects. First compares the Post date. If the dates are
|
||||
@@ -159,9 +156,11 @@ module Jekyll
|
||||
# Returns nothing.
|
||||
def process(name)
|
||||
m, cats, date, slug, ext = *name.match(MATCHER)
|
||||
self.date = Utils.parse_date(date, "Post '#{relative_path}' does not have a valid date in the filename.")
|
||||
self.date = Time.parse(date)
|
||||
self.slug = slug
|
||||
self.ext = ext
|
||||
rescue ArgumentError
|
||||
raise FatalException.new("Post #{name} does not have a valid date.")
|
||||
end
|
||||
|
||||
# The generated directory into which the post will be placed
|
||||
@@ -179,11 +178,11 @@ module Jekyll
|
||||
#
|
||||
# Returns the String permalink.
|
||||
def permalink
|
||||
data && data['permalink']
|
||||
self.data && self.data['permalink']
|
||||
end
|
||||
|
||||
def template
|
||||
case site.permalink_style
|
||||
case self.site.permalink_style
|
||||
when :pretty
|
||||
"/:categories/:year/:month/:day/:title/"
|
||||
when :none
|
||||
@@ -193,7 +192,7 @@ module Jekyll
|
||||
when :ordinal
|
||||
"/:categories/:year/:y_day/:title.html"
|
||||
else
|
||||
site.permalink_style.to_s
|
||||
self.site.permalink_style.to_s
|
||||
end
|
||||
end
|
||||
|
||||
@@ -215,14 +214,13 @@ module Jekyll
|
||||
:year => date.strftime("%Y"),
|
||||
:month => date.strftime("%m"),
|
||||
:day => date.strftime("%d"),
|
||||
:title => slug,
|
||||
:i_day => date.strftime("%-d"),
|
||||
:i_month => date.strftime("%-m"),
|
||||
:categories => (categories || []).map { |c| c.to_s }.join('/'),
|
||||
:title => CGI.escape(slug),
|
||||
:i_day => date.strftime("%d").to_i.to_s,
|
||||
:i_month => date.strftime("%m").to_i.to_s,
|
||||
:categories => (categories || []).map { |c| URI.escape(c.to_s) }.join('/'),
|
||||
:short_month => date.strftime("%b"),
|
||||
:short_year => date.strftime("%y"),
|
||||
:y_day => date.strftime("%j"),
|
||||
:output_ext => output_ext
|
||||
:output_ext => self.output_ext
|
||||
}
|
||||
end
|
||||
|
||||
@@ -231,7 +229,7 @@ module Jekyll
|
||||
#
|
||||
# Returns the String UID.
|
||||
def id
|
||||
File.join(dir, slug)
|
||||
File.join(self.dir, self.slug)
|
||||
end
|
||||
|
||||
# Calculate related posts.
|
||||
@@ -249,16 +247,16 @@ module Jekyll
|
||||
# Returns nothing.
|
||||
def render(layouts, site_payload)
|
||||
# construct payload
|
||||
payload = Utils.deep_merge_hashes({
|
||||
payload = {
|
||||
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
|
||||
"page" => to_liquid(self.class::EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
||||
}, site_payload)
|
||||
"page" => self.to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
||||
}.deep_merge(site_payload)
|
||||
|
||||
if generate_excerpt?
|
||||
extracted_excerpt.do_layout(payload, {})
|
||||
self.extracted_excerpt.do_layout(payload, {})
|
||||
end
|
||||
|
||||
do_layout(payload.merge({"page" => to_liquid}), layouts)
|
||||
do_layout(payload.merge({"page" => self.to_liquid}), layouts)
|
||||
end
|
||||
|
||||
# Obtain destination path.
|
||||
@@ -268,29 +266,30 @@ module Jekyll
|
||||
# Returns destination file path String.
|
||||
def destination(dest)
|
||||
# The url needs to be unescaped in order to preserve the correct filename
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if path[/\.html?$/].nil?
|
||||
path = File.join(dest, CGI.unescape(self.url))
|
||||
path = File.join(path, "index.html") if path[/\.html$/].nil?
|
||||
path
|
||||
end
|
||||
|
||||
# Returns the shorthand String identifier of this Post.
|
||||
def inspect
|
||||
"<Post: #{id}>"
|
||||
"<Post: #{self.id}>"
|
||||
end
|
||||
|
||||
def next
|
||||
pos = site.posts.index {|post| post.equal?(self) }
|
||||
if pos && pos < site.posts.length - 1
|
||||
site.posts[pos + 1]
|
||||
pos = self.site.posts.index(self)
|
||||
|
||||
if pos && pos < self.site.posts.length-1
|
||||
self.site.posts[pos+1]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def previous
|
||||
pos = site.posts.index {|post| post.equal?(self) }
|
||||
pos = self.site.posts.index(self)
|
||||
if pos && pos > 0
|
||||
site.posts[pos - 1]
|
||||
self.site.posts[pos-1]
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
module Jekyll
|
||||
class Publisher
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
|
||||
def publish?(thing)
|
||||
can_be_published?(thing) && !hidden_in_the_future?(thing)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def can_be_published?(thing)
|
||||
thing.data.fetch('published', true) || @site.unpublished
|
||||
end
|
||||
|
||||
def hidden_in_the_future?(thing)
|
||||
thing.is_a?(Post) && !@site.future && thing.date > @site.time
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,13 +10,13 @@ module Jekyll
|
||||
def initialize(post)
|
||||
@post = post
|
||||
@site = post.site
|
||||
require 'classifier-reborn' if site.lsi
|
||||
require 'classifier' if site.lsi
|
||||
end
|
||||
|
||||
def build
|
||||
return [] unless site.posts.size > 1
|
||||
return [] unless self.site.posts.size > 1
|
||||
|
||||
if site.lsi
|
||||
if self.site.lsi
|
||||
build_index
|
||||
lsi_related_posts
|
||||
else
|
||||
@@ -27,10 +27,10 @@ module Jekyll
|
||||
|
||||
def build_index
|
||||
self.class.lsi ||= begin
|
||||
lsi = ClassifierReborn::LSI.new(:auto_rebuild => false)
|
||||
lsi = Classifier::LSI.new(:auto_rebuild => false)
|
||||
display("Populating LSI...")
|
||||
|
||||
site.posts.each do |x|
|
||||
self.site.posts.each do |x|
|
||||
lsi.add_item(x)
|
||||
end
|
||||
|
||||
@@ -42,11 +42,12 @@ module Jekyll
|
||||
end
|
||||
|
||||
def lsi_related_posts
|
||||
self.class.lsi.find_related(post.content, 11) - [post]
|
||||
self.class.lsi.find_related(post.content, 11) - [self.post]
|
||||
end
|
||||
|
||||
def most_recent_posts
|
||||
@most_recent_posts ||= (site.posts.reverse - [post]).first(10)
|
||||
recent_posts = self.site.posts.reverse - [self.post]
|
||||
recent_posts.first(10)
|
||||
end
|
||||
|
||||
def display(output)
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
module Jekyll
|
||||
class Renderer
|
||||
|
||||
attr_reader :document, :site, :site_payload
|
||||
|
||||
def initialize(site, document, site_payload = nil)
|
||||
@site = site
|
||||
@document = document
|
||||
@site_payload = site_payload
|
||||
end
|
||||
|
||||
# Determine which converters to use based on this document's
|
||||
# extension.
|
||||
#
|
||||
# Returns an array of Converter instances.
|
||||
def converters
|
||||
@converters ||= site.converters.select { |c| c.matches(document.extname) }
|
||||
end
|
||||
|
||||
# Determine the extname the outputted file should have
|
||||
#
|
||||
# Returns the output extname including the leading period.
|
||||
def output_ext
|
||||
converters.first.output_ext(document.extname)
|
||||
end
|
||||
|
||||
######################
|
||||
## DAT RENDER THO
|
||||
######################
|
||||
|
||||
def run
|
||||
payload = Utils.deep_merge_hashes({
|
||||
"page" => document.to_liquid
|
||||
}, site_payload || site.site_payload)
|
||||
|
||||
info = {
|
||||
filters: [Jekyll::Filters],
|
||||
registers: { :site => site, :page => payload['page'] }
|
||||
}
|
||||
|
||||
# render and transform content (this becomes the final content of the object)
|
||||
payload["highlighter_prefix"] = converters.first.highlighter_prefix
|
||||
payload["highlighter_suffix"] = converters.first.highlighter_suffix
|
||||
|
||||
output = document.content
|
||||
|
||||
if document.render_with_liquid?
|
||||
output = render_liquid(output, payload, info)
|
||||
end
|
||||
|
||||
output = convert(output)
|
||||
document.content = output
|
||||
|
||||
if document.place_in_layout?
|
||||
place_in_layouts(
|
||||
output,
|
||||
payload,
|
||||
info
|
||||
)
|
||||
else
|
||||
output
|
||||
end
|
||||
end
|
||||
|
||||
# Convert the given content using the converters which match this renderer's document.
|
||||
#
|
||||
# content - the raw, unconverted content
|
||||
#
|
||||
# Returns the converted content.
|
||||
def convert(content)
|
||||
converters.reduce(content) do |output, converter|
|
||||
begin
|
||||
converter.convert output
|
||||
rescue => e
|
||||
Jekyll.logger.error "Conversion error:", "#{converter.class} encountered an error while converting '#{document.relative_path}':"
|
||||
Jekyll.logger.error("", e.to_s)
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Render the given content with the payload and info
|
||||
#
|
||||
# content -
|
||||
# payload -
|
||||
# info -
|
||||
# path - (optional) the path to the file, for use in ex
|
||||
#
|
||||
# Returns the content, rendered by Liquid.
|
||||
def render_liquid(content, payload, info, path = nil)
|
||||
Liquid::Template.parse(content).render!(payload, info)
|
||||
rescue Tags::IncludeTagError => e
|
||||
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || document.relative_path}"
|
||||
raise e
|
||||
rescue Exception => e
|
||||
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{path || document.relative_path}"
|
||||
raise e
|
||||
end
|
||||
|
||||
# Checks if the layout specified in the document actually exists
|
||||
#
|
||||
# layout - the layout to check
|
||||
#
|
||||
# Returns true if the layout is invalid, false if otherwise
|
||||
def invalid_layout?(layout)
|
||||
!document.data["layout"].nil? && layout.nil?
|
||||
end
|
||||
|
||||
# Render layouts and place given content inside.
|
||||
#
|
||||
# content - the content to be placed in the layout
|
||||
#
|
||||
#
|
||||
# Returns the content placed in the Liquid-rendered layouts
|
||||
def place_in_layouts(content, payload, info)
|
||||
output = content.dup
|
||||
layout = site.layouts[document.data["layout"]]
|
||||
|
||||
Jekyll.logger.warn("Build Warning:", "Layout '#{document.data["layout"]}' requested in #{document.relative_path} does not exist.") if invalid_layout? layout
|
||||
|
||||
used = Set.new([layout])
|
||||
|
||||
while layout
|
||||
payload = Utils.deep_merge_hashes(
|
||||
payload,
|
||||
{
|
||||
"content" => output,
|
||||
"page" => document.to_liquid,
|
||||
"layout" => layout.data
|
||||
}
|
||||
)
|
||||
|
||||
output = render_liquid(
|
||||
layout.content,
|
||||
payload,
|
||||
info,
|
||||
File.join(site.config['layouts'], layout.name)
|
||||
)
|
||||
|
||||
# Add layout to dependency tree
|
||||
site.metadata.add_dependency(
|
||||
site.in_source_dir(document.path),
|
||||
site.in_source_dir(layout.path)
|
||||
) if document.write?
|
||||
|
||||
if layout = site.layouts[layout.data["layout"]]
|
||||
if used.include?(layout)
|
||||
layout = nil # avoid recursive chain
|
||||
else
|
||||
used << layout
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
output
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,75 +1,64 @@
|
||||
# encoding: UTF-8
|
||||
require 'csv'
|
||||
|
||||
module Jekyll
|
||||
class Site
|
||||
attr_reader :source, :dest, :config
|
||||
attr_accessor :layouts, :posts, :pages, :static_files,
|
||||
:exclude, :include, :lsi, :highlighter, :permalink_style,
|
||||
:time, :future, :unpublished, :safe, :plugins, :limit_posts,
|
||||
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts,
|
||||
:gems, :plugin_manager
|
||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
||||
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
|
||||
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems
|
||||
|
||||
attr_accessor :converters, :generators
|
||||
attr_reader :metadata
|
||||
|
||||
# Public: Initialize a new Site.
|
||||
#
|
||||
# config - A Hash containing site configuration details.
|
||||
def initialize(config)
|
||||
@config = config.clone
|
||||
self.config = config.clone
|
||||
|
||||
%w[safe lsi highlighter baseurl exclude include future unpublished
|
||||
show_drafts limit_posts keep_files gems].each do |opt|
|
||||
%w[safe lsi pygments baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt|
|
||||
self.send("#{opt}=", config[opt])
|
||||
end
|
||||
|
||||
# Source and destination may not be changed after the site has been created.
|
||||
@source = File.expand_path(config['source']).freeze
|
||||
@dest = File.expand_path(config['destination']).freeze
|
||||
|
||||
# Build metadata
|
||||
@metadata = Metadata.new(self)
|
||||
|
||||
self.plugin_manager = Jekyll::PluginManager.new(self)
|
||||
self.plugins = plugin_manager.plugins_path
|
||||
self.source = File.expand_path(config['source'])
|
||||
self.dest = File.expand_path(config['destination'])
|
||||
self.plugins = plugins_path
|
||||
self.permalink_style = config['permalink'].to_sym
|
||||
|
||||
self.file_read_opts = {}
|
||||
self.file_read_opts[:encoding] = config['encoding'] if config['encoding']
|
||||
|
||||
self.permalink_style = config['permalink'].to_sym
|
||||
|
||||
Jekyll.sites << self
|
||||
|
||||
reset
|
||||
setup
|
||||
self.reset
|
||||
self.setup
|
||||
end
|
||||
|
||||
# Public: Read, process, and write this Site to output.
|
||||
#
|
||||
# Returns nothing.
|
||||
def process
|
||||
reset
|
||||
read
|
||||
generate
|
||||
render
|
||||
cleanup
|
||||
write
|
||||
self.reset
|
||||
self.read
|
||||
self.generate
|
||||
self.render
|
||||
self.cleanup
|
||||
self.write
|
||||
end
|
||||
|
||||
# Reset Site details.
|
||||
#
|
||||
# Returns nothing
|
||||
def reset
|
||||
self.time = (config['time'] ? Utils.parse_date(config['time'].to_s, "Invalid time in _config.yml.") : Time.now)
|
||||
self.layouts = {}
|
||||
self.posts = []
|
||||
self.pages = []
|
||||
self.static_files = []
|
||||
self.data = {}
|
||||
@collections = nil
|
||||
self.time = if self.config['time']
|
||||
Time.parse(self.config['time'].to_s)
|
||||
else
|
||||
Time.now
|
||||
end
|
||||
self.layouts = {}
|
||||
self.posts = []
|
||||
self.pages = []
|
||||
self.static_files = []
|
||||
self.categories = Hash.new { |hash, key| hash[key] = [] }
|
||||
self.tags = Hash.new { |hash, key| hash[key] = [] }
|
||||
self.data = {}
|
||||
|
||||
if limit_posts < 0
|
||||
if self.limit_posts < 0
|
||||
raise ArgumentError, "limit_posts must be a non-negative number"
|
||||
end
|
||||
end
|
||||
@@ -80,7 +69,18 @@ module Jekyll
|
||||
def setup
|
||||
ensure_not_in_dest
|
||||
|
||||
plugin_manager.conscientious_require
|
||||
# If safe mode is off, load in any Ruby files under the plugins
|
||||
# directory.
|
||||
unless self.safe
|
||||
self.plugins.each do |plugins|
|
||||
Dir[File.join(plugins, "**/*.rb")].sort.each do |f|
|
||||
require f
|
||||
end
|
||||
end
|
||||
self.gems.each do |gem|
|
||||
require gem
|
||||
end
|
||||
end
|
||||
|
||||
self.converters = instantiate_subclasses(Jekyll::Converter)
|
||||
self.generators = instantiate_subclasses(Jekyll::Generator)
|
||||
@@ -89,61 +89,22 @@ module Jekyll
|
||||
# Check that the destination dir isn't the source dir or a directory
|
||||
# parent to the source dir.
|
||||
def ensure_not_in_dest
|
||||
dest_pathname = Pathname.new(dest)
|
||||
Pathname.new(source).ascend do |path|
|
||||
if path == dest_pathname
|
||||
raise Errors::FatalException.new "Destination directory cannot be or contain the Source directory."
|
||||
dest = Pathname.new(self.dest)
|
||||
Pathname.new(self.source).ascend do |path|
|
||||
if path == dest
|
||||
raise FatalException.new "Destination directory cannot be or contain the Source directory."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Prefix a given path with the source directory.
|
||||
# Internal: Setup the plugin search path
|
||||
#
|
||||
# paths - (optional) path elements to a file or directory within the
|
||||
# source directory
|
||||
#
|
||||
# Returns a path which is prefixed with the source directory.
|
||||
def in_source_dir(*paths)
|
||||
paths.reduce(source) do |base, path|
|
||||
Jekyll.sanitized_path(base, path)
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Prefix a given path with the destination directory.
|
||||
#
|
||||
# paths - (optional) path elements to a file or directory within the
|
||||
# destination directory
|
||||
#
|
||||
# Returns a path which is prefixed with the destination directory.
|
||||
def in_dest_dir(*paths)
|
||||
paths.reduce(dest) do |base, path|
|
||||
Jekyll.sanitized_path(base, path)
|
||||
end
|
||||
end
|
||||
|
||||
# The list of collections and their corresponding Jekyll::Collection instances.
|
||||
# If config['collections'] is set, a new instance is created for each item in the collection.
|
||||
# If config['collections'] is not set, a new hash is returned.
|
||||
#
|
||||
# Returns a Hash containing collection name-to-instance pairs.
|
||||
def collections
|
||||
@collections ||= Hash[collection_names.map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ]
|
||||
end
|
||||
|
||||
# The list of collection names.
|
||||
#
|
||||
# Returns an array of collection names from the configuration,
|
||||
# or an empty array if the `collections` key is not set.
|
||||
def collection_names
|
||||
case config['collections']
|
||||
when Hash
|
||||
config['collections'].keys
|
||||
when Array
|
||||
config['collections']
|
||||
when nil
|
||||
[]
|
||||
# Returns an Array of plugin search paths
|
||||
def plugins_path
|
||||
if (config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
|
||||
[File.join(self.source, config['plugins'])]
|
||||
else
|
||||
raise ArgumentError, "Your `collections` key must be a hash or an array."
|
||||
Array(config['plugins']).map { |d| File.expand_path(d) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,10 +112,25 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def read
|
||||
self.layouts = LayoutReader.new(self).read
|
||||
read_directories
|
||||
read_data(config['data_source'])
|
||||
read_collections
|
||||
self.read_layouts
|
||||
self.read_directories
|
||||
self.read_data(config['data_source'])
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<layouts> and create a new Layout object
|
||||
# with each one.
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_layouts
|
||||
base = File.join(self.source, self.config['layouts'])
|
||||
return unless File.exists?(base)
|
||||
entries = []
|
||||
Dir.chdir(base) { entries = filter_entries(Dir['**/*.*']) }
|
||||
|
||||
entries.each do |f|
|
||||
name = f.split(".")[0..-2].join(".")
|
||||
self.layouts[name] = Layout.new(self, base, f)
|
||||
end
|
||||
end
|
||||
|
||||
# Recursively traverse directories to find posts, pages and static files
|
||||
@@ -165,29 +141,25 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_directories(dir = '')
|
||||
base = in_source_dir(dir)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
|
||||
base = File.join(self.source, dir)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
|
||||
|
||||
read_posts(dir)
|
||||
read_drafts(dir) if show_drafts
|
||||
posts.sort!
|
||||
self.read_posts(dir)
|
||||
self.read_drafts(dir) if self.show_drafts
|
||||
self.posts.sort!
|
||||
limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set
|
||||
|
||||
entries.each do |f|
|
||||
f_abs = in_source_dir(base, f)
|
||||
f_abs = File.join(base, f)
|
||||
if File.directory?(f_abs)
|
||||
f_rel = File.join(dir, f)
|
||||
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
|
||||
elsif Utils.has_yaml_header?(f_abs)
|
||||
page = Page.new(self, source, dir, f)
|
||||
pages << page if publisher.publish?(page)
|
||||
read_directories(f_rel) unless self.dest.sub(/\/$/, '') == f_abs
|
||||
elsif has_yaml_header?(f_abs)
|
||||
pages << Page.new(self, self.source, dir, f)
|
||||
else
|
||||
static_files << StaticFile.new(self, source, dir, f)
|
||||
static_files << StaticFile.new(self, self.source, dir, f)
|
||||
end
|
||||
end
|
||||
|
||||
pages.sort_by!(&:name)
|
||||
static_files.sort_by!(&:relative_path)
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_posts and create a new Post
|
||||
@@ -197,12 +169,14 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_posts(dir)
|
||||
posts = read_content(dir, '_posts', Post)
|
||||
posts = read_things(dir, '_posts', Post)
|
||||
|
||||
posts.each do |post|
|
||||
aggregate_post_info(post) if publisher.publish?(post)
|
||||
if post.published && (self.future || post.date <= self.time)
|
||||
aggregate_post_info(post)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_drafts and create a new Post
|
||||
# object with each one.
|
||||
@@ -211,18 +185,16 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_drafts(dir)
|
||||
drafts = read_content(dir, '_drafts', Draft)
|
||||
drafts = read_things(dir, '_drafts', Draft)
|
||||
|
||||
drafts.each do |draft|
|
||||
if draft.published?
|
||||
aggregate_post_info(draft)
|
||||
end
|
||||
aggregate_post_info(draft)
|
||||
end
|
||||
end
|
||||
|
||||
def read_content(dir, magic_dir, klass)
|
||||
def read_things(dir, magic_dir, klass)
|
||||
get_entries(dir, magic_dir).map do |entry|
|
||||
klass.new(self, source, dir, entry) if klass.valid?(entry)
|
||||
klass.new(self, self.source, dir, entry) if klass.valid?(entry)
|
||||
end.reject do |entry|
|
||||
entry.nil?
|
||||
end
|
||||
@@ -232,48 +204,18 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing
|
||||
def read_data(dir)
|
||||
base = in_source_dir(dir)
|
||||
read_data_to(base, self.data)
|
||||
end
|
||||
base = File.join(self.source, dir)
|
||||
return unless File.directory?(base) && (!self.safe || !File.symlink?(base))
|
||||
|
||||
# Read and parse all yaml files under <dir> and add them to the
|
||||
# <data> variable.
|
||||
#
|
||||
# dir - The string absolute path of the directory to read.
|
||||
# data - The variable to which data will be added.
|
||||
#
|
||||
# Returns nothing
|
||||
def read_data_to(dir, data)
|
||||
return unless File.directory?(dir) && (!safe || !File.symlink?(dir))
|
||||
|
||||
entries = Dir.chdir(dir) do
|
||||
Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) }
|
||||
end
|
||||
entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
|
||||
entries.delete_if { |e| File.directory?(File.join(base, e)) }
|
||||
|
||||
entries.each do |entry|
|
||||
path = in_source_dir(dir, entry)
|
||||
next if File.symlink?(path) && safe
|
||||
path = File.join(self.source, dir, entry)
|
||||
next if File.symlink?(path) && self.safe
|
||||
|
||||
key = sanitize_filename(File.basename(entry, '.*'))
|
||||
if File.directory?(path)
|
||||
read_data_to(path, data[key] = {})
|
||||
else
|
||||
case File.extname(path).downcase
|
||||
when '.csv'
|
||||
data[key] = CSV.read(path, :headers => true).map(&:to_hash)
|
||||
else
|
||||
data[key] = SafeYAML.load_file(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Read in all collections specified in the configuration
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_collections
|
||||
collections.each do |_, collection|
|
||||
collection.read unless collection.label.eql?("data")
|
||||
self.data[key] = YAML.safe_load_file(path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -281,7 +223,7 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def generate
|
||||
generators.each do |generator|
|
||||
self.generators.each do |generator|
|
||||
generator.generate(self)
|
||||
end
|
||||
end
|
||||
@@ -293,16 +235,12 @@ module Jekyll
|
||||
relative_permalinks_deprecation_method
|
||||
|
||||
payload = site_payload
|
||||
collections.each do |label, collection|
|
||||
collection.docs.each do |document|
|
||||
document.output = Jekyll::Renderer.new(self, document, payload).run if document.regenerate?
|
||||
end
|
||||
[self.posts, self.pages].flatten.each do |page_or_post|
|
||||
page_or_post.render(self.layouts, payload)
|
||||
end
|
||||
|
||||
payload = site_payload
|
||||
[posts, pages].flatten.each do |page_or_post|
|
||||
page_or_post.render(layouts, payload) if page_or_post.regenerate?
|
||||
end
|
||||
self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a } }
|
||||
self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a } }
|
||||
rescue Errno::ENOENT => e
|
||||
# ignore missing layout dir
|
||||
end
|
||||
@@ -318,10 +256,7 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing.
|
||||
def write
|
||||
each_site_file { |item|
|
||||
item.write(dest) if item.regenerate?
|
||||
}
|
||||
metadata.write unless full_rebuild?
|
||||
each_site_file { |item| item.write(self.dest) }
|
||||
end
|
||||
|
||||
# Construct a Hash of Posts indexed by the specified Post attribute.
|
||||
@@ -340,26 +275,18 @@ module Jekyll
|
||||
def post_attr_hash(post_attr)
|
||||
# Build a hash map based on the specified post attribute ( post attr =>
|
||||
# array of posts ) then sort each array in reverse order.
|
||||
hash = Hash.new { |h, key| h[key] = [] }
|
||||
posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
|
||||
hash.values.each { |posts| posts.sort!.reverse! }
|
||||
hash = Hash.new { |hsh, key| hsh[key] = Array.new }
|
||||
self.posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
|
||||
hash.values.map { |sortme| sortme.sort! { |a, b| b <=> a } }
|
||||
hash
|
||||
end
|
||||
|
||||
def tags
|
||||
post_attr_hash('tags')
|
||||
end
|
||||
|
||||
def categories
|
||||
post_attr_hash('categories')
|
||||
end
|
||||
|
||||
# Prepare site data for site payload. The method maintains backward compatibility
|
||||
# if the key 'data' is already used in _config.yml.
|
||||
#
|
||||
# Returns the Hash to be hooked to site.data.
|
||||
def site_data
|
||||
config['data'] || data
|
||||
self.config['data'] || self.data
|
||||
end
|
||||
|
||||
# The Hash payload containing site-wide data.
|
||||
@@ -376,25 +303,15 @@ module Jekyll
|
||||
# "tags" - The Hash of tag values and Posts.
|
||||
# See Site#post_attr_hash for type info.
|
||||
def site_payload
|
||||
{
|
||||
"jekyll" => {
|
||||
"version" => Jekyll::VERSION,
|
||||
"environment" => Jekyll.env
|
||||
},
|
||||
"site" => Utils.deep_merge_hashes(config,
|
||||
Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], {
|
||||
"time" => time,
|
||||
"posts" => posts.sort { |a, b| b <=> a },
|
||||
"pages" => pages,
|
||||
"static_files" => static_files,
|
||||
"html_pages" => pages.select { |page| page.html? || page.url.end_with?("/") },
|
||||
"categories" => post_attr_hash('categories'),
|
||||
"tags" => post_attr_hash('tags'),
|
||||
"collections" => collections,
|
||||
"documents" => documents,
|
||||
"data" => site_data
|
||||
}))
|
||||
}
|
||||
{"jekyll" => { "version" => Jekyll::VERSION },
|
||||
"site" => self.config.merge({
|
||||
"time" => self.time,
|
||||
"posts" => self.posts.sort { |a, b| b <=> a },
|
||||
"pages" => self.pages,
|
||||
"html_pages" => self.pages.reject { |page| !page.html? },
|
||||
"categories" => post_attr_hash('categories'),
|
||||
"tags" => post_attr_hash('tags'),
|
||||
"data" => site_data})}
|
||||
end
|
||||
|
||||
# Filter out any files/directories that are hidden or backup files (start
|
||||
@@ -405,8 +322,8 @@ module Jekyll
|
||||
# entries - The Array of String file/directory entries to filter.
|
||||
#
|
||||
# Returns the Array of filtered entries.
|
||||
def filter_entries(entries, base_directory = nil)
|
||||
EntryFilter.new(self, base_directory).filter(entries)
|
||||
def filter_entries(entries)
|
||||
EntryFilter.new(self).filter(entries)
|
||||
end
|
||||
|
||||
# Get the implementation class for the given Converter.
|
||||
@@ -414,8 +331,13 @@ module Jekyll
|
||||
# klass - The Class of the Converter to fetch.
|
||||
#
|
||||
# Returns the Converter instance implementing the given Converter.
|
||||
def find_converter_instance(klass)
|
||||
converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call
|
||||
def getConverterImpl(klass)
|
||||
matches = self.converters.select { |c| c.class == klass }
|
||||
if impl = matches.first
|
||||
impl
|
||||
else
|
||||
raise "Converter implementation not found for #{klass}"
|
||||
end
|
||||
end
|
||||
|
||||
# Create array of instances of the subclasses of the class or module
|
||||
@@ -426,10 +348,10 @@ module Jekyll
|
||||
#
|
||||
# Returns array of instances of subclasses of parameter
|
||||
def instantiate_subclasses(klass)
|
||||
klass.descendants.select do |c|
|
||||
!safe || c.safe
|
||||
klass.subclasses.select do |c|
|
||||
!self.safe || c.safe
|
||||
end.sort.map do |c|
|
||||
c.new(config)
|
||||
c.new(self.config)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -440,10 +362,10 @@ module Jekyll
|
||||
#
|
||||
# Returns the list of entries to process
|
||||
def get_entries(dir, subfolder)
|
||||
base = in_source_dir(dir, subfolder)
|
||||
return [] unless File.exist?(base)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*'], base) }
|
||||
entries.delete_if { |e| File.directory?(in_source_dir(base, e)) }
|
||||
base = File.join(self.source, dir, subfolder)
|
||||
return [] unless File.exists?(base)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
||||
entries.delete_if { |e| File.directory?(File.join(base, e)) }
|
||||
end
|
||||
|
||||
# Aggregate post information
|
||||
@@ -452,61 +374,44 @@ module Jekyll
|
||||
#
|
||||
# Returns nothing
|
||||
def aggregate_post_info(post)
|
||||
posts << post
|
||||
self.posts << post
|
||||
post.categories.each { |c| self.categories[c] << post }
|
||||
post.tags.each { |c| self.tags[c] << post }
|
||||
end
|
||||
|
||||
def relative_permalinks_deprecation_method
|
||||
if config['relative_permalinks'] && has_relative_page?
|
||||
Jekyll.logger.warn "Deprecation:", "Since v2.0, permalinks for pages" +
|
||||
$stderr.puts # Places newline after "Generating..."
|
||||
Jekyll.logger.warn "Deprecation:", "Starting in 2.0, permalinks for pages" +
|
||||
" in subfolders must be relative to the" +
|
||||
" site source directory, not the parent" +
|
||||
" directory. Check http://jekyllrb.com/docs/upgrading/"+
|
||||
" for more info."
|
||||
$stderr.print Jekyll.logger.formatted_topic("") + "..." # for "done."
|
||||
end
|
||||
end
|
||||
|
||||
def docs_to_write
|
||||
documents.select(&:write?)
|
||||
end
|
||||
|
||||
def documents
|
||||
collections.reduce(Set.new) do |docs, (_, collection)|
|
||||
docs + collection.docs + collection.files
|
||||
end.to_a
|
||||
end
|
||||
|
||||
def each_site_file
|
||||
%w(posts pages static_files docs_to_write).each do |type|
|
||||
send(type).each do |item|
|
||||
%w(posts pages static_files).each do |type|
|
||||
self.send(type).each do |item|
|
||||
yield item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def frontmatter_defaults
|
||||
@frontmatter_defaults ||= FrontmatterDefaults.new(self)
|
||||
end
|
||||
|
||||
# Whether to perform a full rebuild without metadata
|
||||
#
|
||||
# Returns a Boolean: true for a full rebuild, false for normal build
|
||||
def full_rebuild?(override = {})
|
||||
override['full_rebuild'] || config['full_rebuild']
|
||||
end
|
||||
|
||||
def publisher
|
||||
@publisher ||= Publisher.new(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def has_relative_page?
|
||||
pages.any? { |page| page.uses_relative_permalinks }
|
||||
self.pages.any? { |page| page.uses_relative_permalinks }
|
||||
end
|
||||
|
||||
def has_yaml_header?(file)
|
||||
"---" == File.open(file) { |fd| fd.read(3) }
|
||||
end
|
||||
|
||||
def limit_posts!
|
||||
limit = posts.length < limit_posts ? posts.length : limit_posts
|
||||
self.posts = posts[-limit, limit]
|
||||
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
||||
self.posts = self.posts[-limit, limit]
|
||||
end
|
||||
|
||||
def site_cleaner
|
||||
@@ -514,9 +419,9 @@ module Jekyll
|
||||
end
|
||||
|
||||
def sanitize_filename(name)
|
||||
name.gsub!(/[^\w\s_-]+/, '')
|
||||
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
||||
name.gsub(/\s+/, '_')
|
||||
name = name.gsub(/[^\w\s_-]+/, '')
|
||||
name = name.gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
||||
name = name.gsub(/\s+/, '_')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,30 +3,22 @@ module Jekyll
|
||||
# The cache of last modification times [path] -> mtime.
|
||||
@@mtimes = Hash.new
|
||||
|
||||
attr_reader :relative_path
|
||||
|
||||
# Initialize a new StaticFile.
|
||||
#
|
||||
# site - The Site.
|
||||
# base - The String path to the <source>.
|
||||
# dir - The String path between <source> and the file.
|
||||
# name - The String filename of the file.
|
||||
def initialize(site, base, dir, name, collection = nil)
|
||||
def initialize(site, base, dir, name)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = dir
|
||||
@name = name
|
||||
@collection = collection
|
||||
@relative_path = File.join(*[@dir, @name].compact)
|
||||
end
|
||||
|
||||
# Returns source file path.
|
||||
def path
|
||||
File.join(*[@base, @dir, @name].compact)
|
||||
end
|
||||
|
||||
def extname
|
||||
File.extname(path)
|
||||
File.join(@base, @dir, @name)
|
||||
end
|
||||
|
||||
# Obtain destination path.
|
||||
@@ -35,15 +27,7 @@ module Jekyll
|
||||
#
|
||||
# Returns destination file path.
|
||||
def destination(dest)
|
||||
@site.in_dest_dir(*[dest, destination_rel_dir, @name].compact)
|
||||
end
|
||||
|
||||
def destination_rel_dir
|
||||
if @collection
|
||||
@dir.gsub(/\A_/, '')
|
||||
else
|
||||
@dir
|
||||
end
|
||||
File.join(dest, @dir, @name)
|
||||
end
|
||||
|
||||
# Returns last modification time for this file.
|
||||
@@ -58,15 +42,6 @@ module Jekyll
|
||||
@@mtimes[path] != mtime
|
||||
end
|
||||
|
||||
# Whether to write the file to the filesystem
|
||||
#
|
||||
# Returns true.
|
||||
def write?
|
||||
true
|
||||
end
|
||||
|
||||
alias_method :regenerate?, :write?
|
||||
|
||||
# Write the static file to the destination directory (if modified).
|
||||
#
|
||||
# dest - The String path to the destination dir.
|
||||
@@ -79,7 +54,6 @@ module Jekyll
|
||||
@@mtimes[path] = mtime
|
||||
|
||||
FileUtils.mkdir_p(File.dirname(dest_path))
|
||||
FileUtils.rm(dest_path) if File.exist?(dest_path)
|
||||
FileUtils.cp(path, dest_path)
|
||||
|
||||
true
|
||||
@@ -92,13 +66,5 @@ module Jekyll
|
||||
@@mtimes = Hash.new
|
||||
nil
|
||||
end
|
||||
|
||||
def to_liquid
|
||||
{
|
||||
"path" => File.join("", relative_path),
|
||||
"modified_time" => mtime.to_s,
|
||||
"extname" => File.extname(relative_path)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,58 +1,89 @@
|
||||
module Jekyll
|
||||
class Stevenson < ::Logger
|
||||
def initialize
|
||||
@progname = nil
|
||||
@level = DEBUG
|
||||
@default_formatter = Formatter.new
|
||||
@logdev = $stdout
|
||||
@formatter = proc do |severity, datetime, progname, msg|
|
||||
"#{msg}"
|
||||
end
|
||||
class Stevenson
|
||||
attr_accessor :log_level
|
||||
|
||||
DEBUG = 0
|
||||
INFO = 1
|
||||
WARN = 2
|
||||
ERROR = 3
|
||||
|
||||
# Public: Create a new instance of Stevenson, Jekyll's logger
|
||||
#
|
||||
# level - (optional, integer) the log level
|
||||
#
|
||||
# Returns nothing
|
||||
def initialize(level = INFO)
|
||||
@log_level = level
|
||||
end
|
||||
|
||||
# Public: Print a jekyll debug message to stdout
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def debug(topic, message = nil)
|
||||
$stdout.puts(message(topic, message)) if log_level <= DEBUG
|
||||
end
|
||||
|
||||
def add(severity, message = nil, progname = nil, &block)
|
||||
severity ||= UNKNOWN
|
||||
@logdev = set_logdevice(severity)
|
||||
|
||||
if @logdev.nil? or severity < @level
|
||||
return true
|
||||
end
|
||||
progname ||= @progname
|
||||
if message.nil?
|
||||
if block_given?
|
||||
message = yield
|
||||
else
|
||||
message = progname
|
||||
progname = @progname
|
||||
end
|
||||
end
|
||||
@logdev.puts(
|
||||
format_message(format_severity(severity), Time.now, progname, message))
|
||||
true
|
||||
# Public: Print a jekyll message to stdout
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def info(topic, message = nil)
|
||||
$stdout.puts(message(topic, message)) if log_level <= INFO
|
||||
end
|
||||
|
||||
# Log a +WARN+ message
|
||||
def warn(progname = nil, &block)
|
||||
add(WARN, nil, progname.yellow, &block)
|
||||
# Public: Print a jekyll message to stderr
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def warn(topic, message = nil)
|
||||
$stderr.puts(message(topic, message).yellow) if log_level <= WARN
|
||||
end
|
||||
|
||||
# Log an +ERROR+ message
|
||||
def error(progname = nil, &block)
|
||||
add(ERROR, nil, progname.red, &block)
|
||||
# Public: Print a jekyll error message to stderr
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns nothing
|
||||
def error(topic, message = nil)
|
||||
$stderr.puts(message(topic, message).red) if log_level <= ERROR
|
||||
end
|
||||
|
||||
def close
|
||||
# No LogDevice in use
|
||||
# Public: Print a Jekyll error message to stderr and immediately abort the process
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail (can be omitted)
|
||||
#
|
||||
# Returns nothing
|
||||
def abort_with(topic, message = nil)
|
||||
error(topic, message)
|
||||
abort
|
||||
end
|
||||
|
||||
private
|
||||
# Public: Build a Jekyll topic method
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
# message - the message detail
|
||||
#
|
||||
# Returns the formatted message
|
||||
def message(topic, message)
|
||||
formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ')
|
||||
end
|
||||
|
||||
def set_logdevice(severity)
|
||||
if severity > INFO
|
||||
$stderr
|
||||
else
|
||||
$stdout
|
||||
end
|
||||
# Public: Format the topic
|
||||
#
|
||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||
#
|
||||
# Returns the formatted topic statement
|
||||
def formatted_topic(topic)
|
||||
"#{topic} ".rjust(20)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
48
lib/jekyll/tags/gist.rb
Normal file
48
lib/jekyll/tags/gist.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
# Gist Liquid Tag
|
||||
#
|
||||
# Example:
|
||||
# {% gist 1234567 %}
|
||||
# {% gist 1234567 file.rb %}
|
||||
|
||||
module Jekyll
|
||||
class GistTag < Liquid::Tag
|
||||
|
||||
def render(context)
|
||||
if tag_contents = determine_arguments(@markup.strip)
|
||||
gist_id, filename = tag_contents[0], tag_contents[1]
|
||||
gist_script_tag(gist_id, filename)
|
||||
else
|
||||
raise ArgumentError.new <<-eos
|
||||
Syntax error in tag 'gist' while parsing the following markup:
|
||||
|
||||
#{@markup}
|
||||
|
||||
Valid syntax:
|
||||
for public gists: {% gist 1234567 %}
|
||||
for private gists: {% gist user/1234567 %}
|
||||
eos
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def determine_arguments(input)
|
||||
matched = if input.include?("/")
|
||||
input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
|
||||
else
|
||||
input.match(/\A(\d+) ?(\S*)\Z/)
|
||||
end
|
||||
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
|
||||
end
|
||||
|
||||
def gist_script_tag(gist_id, filename = nil)
|
||||
if filename.empty?
|
||||
"<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
|
||||
else
|
||||
"<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('gist', Jekyll::GistTag)
|
||||
@@ -4,11 +4,12 @@ module Jekyll
|
||||
include Liquid::StandardFilters
|
||||
|
||||
# The regular expression syntax checker. Start with the language specifier.
|
||||
# Follow that by zero or more space separated options that take one of three
|
||||
# forms: name, name=value, or name="<quoted list>"
|
||||
# Follow that by zero or more space separated options that take one of two
|
||||
# forms:
|
||||
#
|
||||
# <quoted list> is a space-separated list of numbers
|
||||
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/
|
||||
# 1. name
|
||||
# 2. name=value
|
||||
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
super
|
||||
@@ -16,18 +17,18 @@ module Jekyll
|
||||
@lang = $1.downcase
|
||||
@options = {}
|
||||
if defined?($2) && $2 != ''
|
||||
# Split along 3 possible forms -- key="<quoted list>", key=value, or key
|
||||
$2.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt|
|
||||
$2.split.each do |opt|
|
||||
key, value = opt.split('=')
|
||||
# If a quoted list, convert to array
|
||||
if value && value.include?("\"")
|
||||
value.gsub!(/"/, "")
|
||||
value = value.split
|
||||
if value.nil?
|
||||
if key == 'linenos'
|
||||
value = 'inline'
|
||||
else
|
||||
value = true
|
||||
end
|
||||
end
|
||||
@options[key.to_sym] = value || true
|
||||
@options[key] = value
|
||||
end
|
||||
end
|
||||
@options[:linenos] = "inline" if @options.key?(:linenos) and @options[:linenos] == true
|
||||
else
|
||||
raise SyntaxError.new <<-eos
|
||||
Syntax Error in tag 'highlight' while parsing the following markup:
|
||||
@@ -40,82 +41,41 @@ eos
|
||||
end
|
||||
|
||||
def render(context)
|
||||
prefix = context["highlighter_prefix"] || ""
|
||||
suffix = context["highlighter_suffix"] || ""
|
||||
code = super.to_s.strip
|
||||
|
||||
is_safe = !!context.registers[:site].safe
|
||||
|
||||
output =
|
||||
case context.registers[:site].highlighter
|
||||
when 'pygments'
|
||||
render_pygments(code, is_safe)
|
||||
when 'rouge'
|
||||
render_rouge(code)
|
||||
else
|
||||
render_codehighlighter(code)
|
||||
end
|
||||
|
||||
rendered_output = add_code_tag(output)
|
||||
prefix + rendered_output + suffix
|
||||
end
|
||||
|
||||
def sanitized_opts(opts, is_safe)
|
||||
if is_safe
|
||||
Hash[[
|
||||
[:startinline, opts.fetch(:startinline, nil)],
|
||||
[:hl_linenos, opts.fetch(:hl_linenos, nil)],
|
||||
[:linenos, opts.fetch(:linenos, nil)],
|
||||
[:encoding, opts.fetch(:encoding, 'utf-8')],
|
||||
[:cssclass, opts.fetch(:cssclass, nil)]
|
||||
].reject {|f| f.last.nil? }]
|
||||
if context.registers[:site].pygments
|
||||
render_pygments(context, super)
|
||||
else
|
||||
opts
|
||||
render_codehighlighter(context, super)
|
||||
end
|
||||
end
|
||||
|
||||
def render_pygments(code, is_safe)
|
||||
def render_pygments(context, code)
|
||||
require 'pygments'
|
||||
|
||||
@options[:encoding] = 'utf-8'
|
||||
|
||||
highlighted_code = Pygments.highlight(
|
||||
code,
|
||||
:lexer => @lang,
|
||||
:options => sanitized_opts(@options, is_safe)
|
||||
output = add_code_tags(
|
||||
Pygments.highlight(code, :lexer => @lang, :options => @options),
|
||||
@lang
|
||||
)
|
||||
|
||||
if highlighted_code.nil?
|
||||
Jekyll.logger.error "There was an error highlighting your code:"
|
||||
puts
|
||||
Jekyll.logger.error code
|
||||
puts
|
||||
Jekyll.logger.error "While attempting to convert the above code, Pygments.rb" +
|
||||
" returned an unacceptable value."
|
||||
Jekyll.logger.error "This is usually a timeout problem solved by running `jekyll build` again."
|
||||
raise ArgumentError.new("Pygments.rb returned an unacceptable value when attempting to highlight some code.")
|
||||
end
|
||||
|
||||
highlighted_code
|
||||
output = context["pygments_prefix"] + output if context["pygments_prefix"]
|
||||
output = output + context["pygments_suffix"] if context["pygments_suffix"]
|
||||
output
|
||||
end
|
||||
|
||||
def render_rouge(code)
|
||||
require 'rouge'
|
||||
formatter = Rouge::Formatters::HTML.new(line_numbers: @options[:linenos], wrap: false)
|
||||
lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
||||
code = formatter.format(lexer.lex(code))
|
||||
"<div class=\"highlight\"><pre>#{code}</pre></div>"
|
||||
def render_codehighlighter(context, code)
|
||||
#The div is required because RDiscount blows ass
|
||||
<<-HTML
|
||||
<div>
|
||||
<pre><code class='#{@lang}'>#{h(code).strip}</code></pre>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
def render_codehighlighter(code)
|
||||
"<div class=\"highlight\"><pre>#{h(code).strip}</pre></div>"
|
||||
end
|
||||
|
||||
def add_code_tag(code)
|
||||
def add_code_tags(code, lang)
|
||||
# Add nested <code> tags to code blocks
|
||||
code = code.sub(/<pre>\n*/,'<pre><code class="language-' + @lang.to_s.gsub("+", "-") + '" data-lang="' + @lang.to_s + '">')
|
||||
code = code.sub(/\n*<\/pre>/,"</code></pre>")
|
||||
code.strip
|
||||
code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
|
||||
code = code.sub(/<\/pre>/,"</code></pre>")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
module Jekyll
|
||||
module Tags
|
||||
class IncludeTagError < StandardError
|
||||
@@ -13,33 +11,16 @@ module Jekyll
|
||||
|
||||
class IncludeTag < Liquid::Tag
|
||||
|
||||
attr_reader :includes_dir
|
||||
SYNTAX_EXAMPLE = "{% include file.ext param='value' param2='value' %}"
|
||||
|
||||
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
||||
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
||||
|
||||
class << self
|
||||
def source_cache
|
||||
@@source_cache ||= {}
|
||||
end
|
||||
end
|
||||
INCLUDES_DIR = '_includes'
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
super
|
||||
@includes_dir = tag_includes_dir
|
||||
matched = markup.strip.match(VARIABLE_SYNTAX)
|
||||
if matched
|
||||
@file = matched['variable'].strip
|
||||
@params = matched['params'].strip
|
||||
else
|
||||
@file, @params = markup.strip.split(' ', 2);
|
||||
end
|
||||
@file, @params = markup.strip.split(' ', 2);
|
||||
validate_params if @params
|
||||
@tag_name = tag_name
|
||||
end
|
||||
|
||||
def syntax_example
|
||||
"{% #{@tag_name} file.ext param='value' param2='value' %}"
|
||||
end
|
||||
|
||||
def parse_params(context)
|
||||
@@ -67,11 +48,11 @@ module Jekyll
|
||||
raise ArgumentError.new <<-eos
|
||||
Invalid syntax for include tag. File contains invalid characters or sequences:
|
||||
|
||||
#{file}
|
||||
#{@file}
|
||||
|
||||
Valid syntax:
|
||||
|
||||
#{syntax_example}
|
||||
#{SYNTAX_EXAMPLE}
|
||||
|
||||
eos
|
||||
end
|
||||
@@ -83,11 +64,11 @@ eos
|
||||
raise ArgumentError.new <<-eos
|
||||
Invalid syntax for include tag:
|
||||
|
||||
#{@params}
|
||||
#{@params}
|
||||
|
||||
Valid syntax:
|
||||
|
||||
#{syntax_example}
|
||||
#{SYNTAX_EXAMPLE}
|
||||
|
||||
eos
|
||||
end
|
||||
@@ -98,35 +79,22 @@ eos
|
||||
context.registers[:site].file_read_opts
|
||||
end
|
||||
|
||||
# Render the variable if required
|
||||
def render_variable(context)
|
||||
if @file.match(VARIABLE_SYNTAX)
|
||||
partial = Liquid::Template.parse(@file)
|
||||
partial.render!(context)
|
||||
def retrieve_variable(context)
|
||||
if /\{\{([\w\-\.]+)\}\}/ =~ @file
|
||||
raise ArgumentError.new("No variable #{$1} was found in include tag") if context[$1].nil?
|
||||
context[$1]
|
||||
end
|
||||
end
|
||||
|
||||
def tag_includes_dir
|
||||
'_includes'
|
||||
end
|
||||
|
||||
def render(context)
|
||||
site = context.registers[:site]
|
||||
dir = resolved_includes_dir(context)
|
||||
dir = File.join(context.registers[:site].source, INCLUDES_DIR)
|
||||
validate_dir(dir, context.registers[:site].safe)
|
||||
|
||||
file = render_variable(context) || @file
|
||||
file = retrieve_variable(context) || @file
|
||||
validate_file_name(file)
|
||||
|
||||
path = File.join(dir, file)
|
||||
validate_path(path, dir, site.safe)
|
||||
|
||||
# Add include to dependency tree
|
||||
if context.registers[:page] and context.registers[:page].has_key? "path"
|
||||
site.metadata.add_dependency(
|
||||
site.in_source_dir(context.registers[:page]["path"]),
|
||||
path
|
||||
)
|
||||
end
|
||||
validate_file(path, context.registers[:site].safe)
|
||||
|
||||
begin
|
||||
partial = Liquid::Template.parse(source(path, context))
|
||||
@@ -136,51 +104,34 @@ eos
|
||||
partial.render!(context)
|
||||
end
|
||||
rescue => e
|
||||
raise IncludeTagError.new e.message, File.join(@includes_dir, @file)
|
||||
raise IncludeTagError.new e.message, File.join(INCLUDES_DIR, @file)
|
||||
end
|
||||
end
|
||||
|
||||
def resolved_includes_dir(context)
|
||||
File.join(File.realpath(context.registers[:site].source), @includes_dir)
|
||||
end
|
||||
|
||||
def validate_path(path, dir, safe)
|
||||
if safe && !realpath_prefixed_with?(path, dir)
|
||||
raise IOError.new "The included file '#{path}' should exist and should not be a symlink"
|
||||
elsif !File.exist?(path)
|
||||
raise IOError.new "Included file '#{path_relative_to_source(dir, path)}' not found"
|
||||
def validate_dir(dir, safe)
|
||||
if File.symlink?(dir) && safe
|
||||
raise IOError.new "Includes directory '#{dir}' cannot be a symlink"
|
||||
end
|
||||
end
|
||||
|
||||
def path_relative_to_source(dir, path)
|
||||
File.join(@includes_dir, path.sub(Regexp.new("^#{dir}"), ""))
|
||||
def validate_file(file, safe)
|
||||
if !File.exists?(file)
|
||||
raise IOError.new "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory"
|
||||
elsif File.symlink?(file) && safe
|
||||
raise IOError.new "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink"
|
||||
end
|
||||
end
|
||||
|
||||
def realpath_prefixed_with?(path, dir)
|
||||
File.exist?(path) && File.realpath(path).start_with?(dir)
|
||||
def blank?
|
||||
false
|
||||
end
|
||||
|
||||
# This method allows to modify the file content by inheriting from the class.
|
||||
def source(file, context)
|
||||
self.class.source_cache[file] ||= File.read(file, file_read_opts(context))
|
||||
end
|
||||
end
|
||||
|
||||
class IncludeRelativeTag < IncludeTag
|
||||
def tag_includes_dir
|
||||
'.'
|
||||
end
|
||||
|
||||
def page_path(context)
|
||||
context.registers[:page].nil? ? includes_dir : File.dirname(context.registers[:page]["path"])
|
||||
end
|
||||
|
||||
def resolved_includes_dir(context)
|
||||
context.registers[:site].in_source_dir(page_path(context))
|
||||
File.read_with_options(file, file_read_opts(context))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('include', Jekyll::Tags::IncludeTag)
|
||||
Liquid::Template.register_tag('include_relative', Jekyll::Tags::IncludeRelativeTag)
|
||||
|
||||
@@ -3,22 +3,15 @@ module Jekyll
|
||||
class PostComparer
|
||||
MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)$/
|
||||
|
||||
attr_reader :path, :date, :slug, :name
|
||||
attr_accessor :date, :slug
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
all, @path, @date, @slug = *name.sub(/^\//, "").match(MATCHER)
|
||||
raise ArgumentError.new("'#{name}' does not contain valid date and/or title.") unless all
|
||||
|
||||
@name_regex = /^#{path}#{date}-#{slug}\.[^.]+/
|
||||
all, path, date, slug = *name.sub(/^\//, "").match(MATCHER)
|
||||
@slug = path ? path + slug : slug
|
||||
@date = Time.parse(date)
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
other.name.match(@name_regex)
|
||||
end
|
||||
|
||||
def deprecated_equality(other)
|
||||
date = Utils.parse_date(name, "'#{name}' does not contain valid date and/or title.")
|
||||
slug == post_slug(other) &&
|
||||
date.year == other.date.year &&
|
||||
date.month == other.date.month &&
|
||||
@@ -45,15 +38,7 @@ module Jekyll
|
||||
def initialize(tag_name, post, tokens)
|
||||
super
|
||||
@orig_post = post.strip
|
||||
begin
|
||||
@post = PostComparer.new(@orig_post)
|
||||
rescue
|
||||
raise ArgumentError.new <<-eos
|
||||
Could not parse name of post "#{@orig_post}" in tag 'post_url'.
|
||||
|
||||
Make sure the post exists and the name is correct.
|
||||
eos
|
||||
end
|
||||
@post = PostComparer.new(@orig_post)
|
||||
end
|
||||
|
||||
def render(context)
|
||||
@@ -65,19 +50,6 @@ eos
|
||||
end
|
||||
end
|
||||
|
||||
# New matching method did not match, fall back to old method
|
||||
# with deprecation warning if this matches
|
||||
|
||||
site.posts.each do |p|
|
||||
if @post.deprecated_equality p
|
||||
Jekyll::Deprecator.deprecation_message "A call to '{{ post_url #{name} }}' did not match " +
|
||||
"a post using the new matching method of checking name " +
|
||||
"(path-date-slug) equality. Please make sure that you " +
|
||||
"change this tag to match the post's name exactly."
|
||||
return p.url
|
||||
end
|
||||
end
|
||||
|
||||
raise ArgumentError.new <<-eos
|
||||
Could not find post "#{@orig_post}" in tag 'post_url'.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require 'uri'
|
||||
|
||||
# Public: Methods that generate a URL for a resource such as a Post or a Page.
|
||||
#
|
||||
# Examples
|
||||
@@ -24,9 +22,9 @@ module Jekyll
|
||||
# template. Instead, the given permalink will be
|
||||
# used as URL.
|
||||
def initialize(options)
|
||||
@template = options[:template]
|
||||
@template = options[:template]
|
||||
@placeholders = options[:placeholders] || {}
|
||||
@permalink = options[:permalink]
|
||||
@permalink = options[:permalink]
|
||||
|
||||
if (@template || @permalink).nil?
|
||||
raise ArgumentError, "One of :template or :permalink must be supplied."
|
||||
@@ -37,86 +35,33 @@ module Jekyll
|
||||
#
|
||||
# Returns the String URL
|
||||
def to_s
|
||||
sanitize_url(generated_permalink || generated_url)
|
||||
end
|
||||
|
||||
# Generates a URL from the permalink
|
||||
#
|
||||
# Returns the _unsanitized String URL
|
||||
def generated_permalink
|
||||
(@generated_permlink ||= generate_url(@permalink)) if @permalink
|
||||
end
|
||||
|
||||
# Generates a URL from the template
|
||||
#
|
||||
# Returns the _unsanitized String URL
|
||||
def generated_url
|
||||
@generated_url ||= generate_url(@template)
|
||||
sanitize_url(@permalink || generate_url)
|
||||
end
|
||||
|
||||
# Internal: Generate the URL by replacing all placeholders with their
|
||||
# respective values in the given template
|
||||
# respective values
|
||||
#
|
||||
# Returns the _unsanitizied_ String URL
|
||||
def generate_url(template)
|
||||
@placeholders.inject(template) do |result, token|
|
||||
break result if result.index(':').nil?
|
||||
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
|
||||
def generate_url
|
||||
@placeholders.inject(@template) do |result, token|
|
||||
result.gsub(/:#{token.first}/, token.last)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a sanitized String URL
|
||||
def sanitize_url(in_url)
|
||||
url = in_url \
|
||||
# Remove all double slashes
|
||||
.gsub(/\/\//, '/') \
|
||||
# Remove every URL segment that consists solely of dots
|
||||
.split('/').reject{ |part| part =~ /^\.+$/ }.join('/') \
|
||||
# Always add a leading slash
|
||||
.gsub(/\A([^\/])/, '/\1')
|
||||
# Remove all double slashes
|
||||
url = in_url.gsub(/\/\//, "/")
|
||||
|
||||
# Remove every URL segment that consists solely of dots
|
||||
url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
|
||||
|
||||
# Append a trailing slash to the URL if the unsanitized URL had one
|
||||
url << "/" if in_url[-1].eql?('/')
|
||||
url += "/" if in_url =~ /\/$/
|
||||
|
||||
# Always add a leading slash
|
||||
url.gsub!(/\A([^\/])/, '/\1')
|
||||
url
|
||||
end
|
||||
|
||||
# Escapes a path to be a valid URL path segment
|
||||
#
|
||||
# path - The path to be escaped.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# URL.escape_path("/a b")
|
||||
# # => "/a%20b"
|
||||
#
|
||||
# Returns the escaped path.
|
||||
def self.escape_path(path)
|
||||
# Because URI.escape doesn't escape '?', '[' and ']' by default,
|
||||
# specify unsafe string (except unreserved, sub-delims, ":", "@" and "/").
|
||||
#
|
||||
# URI path segment is defined in RFC 3986 as follows:
|
||||
# segment = *pchar
|
||||
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
# unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
# pct-encoded = "%" HEXDIG HEXDIG
|
||||
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
# / "*" / "+" / "," / ";" / "="
|
||||
URI.escape(path, /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8')
|
||||
end
|
||||
|
||||
# Unescapes a URL path segment
|
||||
#
|
||||
# path - The path to be unescaped.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# URL.unescape_path("/a%20b")
|
||||
# # => "/a b"
|
||||
#
|
||||
# Returns the unescaped path.
|
||||
def self.unescape_path(path)
|
||||
URI.unescape(path.encode('utf-8'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
module Jekyll
|
||||
module Utils
|
||||
extend self
|
||||
|
||||
# Merges a master hash with another hash, recursively.
|
||||
#
|
||||
# master_hash - the "parent" hash whose values will be overridden
|
||||
# other_hash - the other hash whose values will be persisted after the merge
|
||||
#
|
||||
# This code was lovingly stolen from some random gem:
|
||||
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
||||
#
|
||||
# Thanks to whoever made it.
|
||||
def deep_merge_hashes(master_hash, other_hash)
|
||||
target = master_hash.dup
|
||||
|
||||
other_hash.each_key do |key|
|
||||
if other_hash[key].is_a? Hash and target[key].is_a? Hash
|
||||
target[key] = Utils.deep_merge_hashes(target[key], other_hash[key])
|
||||
next
|
||||
end
|
||||
|
||||
target[key] = other_hash[key]
|
||||
end
|
||||
|
||||
target
|
||||
end
|
||||
|
||||
# Read array from the supplied hash favouring the singular key
|
||||
# and then the plural key, and handling any nil entries.
|
||||
#
|
||||
# hash - the hash to read from
|
||||
# singular_key - the singular key
|
||||
# plural_key - the plural key
|
||||
#
|
||||
# Returns an array
|
||||
def pluralized_array_from_hash(hash, singular_key, plural_key)
|
||||
[].tap do |array|
|
||||
array << (value_from_singular_key(hash, singular_key) || value_from_plural_key(hash, plural_key))
|
||||
end.flatten.compact
|
||||
end
|
||||
|
||||
def value_from_singular_key(hash, key)
|
||||
hash[key] if (hash.key?(key) || (hash.default_proc && hash[key]))
|
||||
end
|
||||
|
||||
def value_from_plural_key(hash, key)
|
||||
if hash.key?(key) || (hash.default_proc && hash[key])
|
||||
val = hash[key]
|
||||
case val
|
||||
when String
|
||||
val.split
|
||||
when Array
|
||||
val.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def transform_keys(hash)
|
||||
result = {}
|
||||
hash.each_key do |key|
|
||||
result[yield(key)] = hash[key]
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Apply #to_sym to all keys in the hash
|
||||
#
|
||||
# hash - the hash to which to apply this transformation
|
||||
#
|
||||
# Returns a new hash with symbolized keys
|
||||
def symbolize_hash_keys(hash)
|
||||
transform_keys(hash) { |key| key.to_sym rescue key }
|
||||
end
|
||||
|
||||
# Apply #to_s to all keys in the Hash
|
||||
#
|
||||
# hash - the hash to which to apply this transformation
|
||||
#
|
||||
# Returns a new hash with stringified keys
|
||||
def stringify_hash_keys(hash)
|
||||
transform_keys(hash) { |key| key.to_s rescue key }
|
||||
end
|
||||
|
||||
# Parse a date/time and throw an error if invalid
|
||||
#
|
||||
# input - the date/time to parse
|
||||
# msg - (optional) the error message to show the user
|
||||
#
|
||||
# Returns the parsed date if successful, throws a FatalException
|
||||
# if not
|
||||
def parse_date(input, msg = "Input could not be parsed.")
|
||||
Time.parse(input).localtime
|
||||
rescue ArgumentError
|
||||
raise Errors::FatalException.new("Invalid date '#{input}': " + msg)
|
||||
end
|
||||
|
||||
# Determines whether a given file has
|
||||
#
|
||||
# Returns true if the YAML front matter is present.
|
||||
def has_yaml_header?(file)
|
||||
!!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
|
||||
end
|
||||
|
||||
# Slugify a filename or title.
|
||||
#
|
||||
# name - the filename or title to slugify
|
||||
#
|
||||
# Returns the given filename or title in lowercase, with every
|
||||
# sequence of spaces and non-alphanumeric characters replaced with a
|
||||
# hyphen.
|
||||
def slugify(string)
|
||||
unless string.nil?
|
||||
string \
|
||||
# Replace each non-alphanumeric character sequence with a hyphen
|
||||
.gsub(/[^[:alnum:]]+/i, '-') \
|
||||
# Remove leading/trailing hyphen
|
||||
.gsub(/^\-|\-$/i, '') \
|
||||
# Downcase it
|
||||
.downcase
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
module Jekyll
|
||||
VERSION = '2.5.3'
|
||||
end
|
||||
3
lib/site_template/.gitignore
vendored
3
lib/site_template/.gitignore
vendored
@@ -1,2 +1 @@
|
||||
_site
|
||||
.sass-cache
|
||||
_site
|
||||
@@ -1,14 +1,3 @@
|
||||
# Site settings
|
||||
title: Your awesome title
|
||||
email: your-email@domain.com
|
||||
description: > # this means to ignore newlines until "baseurl:"
|
||||
Write an awesome description for your new site here. You can edit this
|
||||
line in _config.yml. It will appear in your document head meta (for
|
||||
Google search results) and in your feed.xml site description.
|
||||
baseurl: "" # the subpath of your site, e.g. /blog/
|
||||
url: "http://yourdomain.com" # the base hostname & protocol for your site
|
||||
twitter_username: jekyllrb
|
||||
github_username: jekyll
|
||||
|
||||
# Build settings
|
||||
markdown: kramdown
|
||||
name: Your New Jekyll Site
|
||||
markdown: redcarpet
|
||||
pygments: true
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<footer class="site-footer">
|
||||
|
||||
<div class="wrapper">
|
||||
|
||||
<h2 class="footer-heading">{{ site.title }}</h2>
|
||||
|
||||
<div class="footer-col-wrapper">
|
||||
<div class="footer-col footer-col-1">
|
||||
<ul class="contact-list">
|
||||
<li>{{ site.title }}</li>
|
||||
<li><a href="mailto:{{ site.email }}">{{ site.email }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-col footer-col-2">
|
||||
<ul class="social-media-list">
|
||||
{% if site.github_username %}
|
||||
<li>
|
||||
<a href="https://github.com/{{ site.github_username }}">
|
||||
<span class="icon icon--github">
|
||||
<svg viewBox="0 0 16 16">
|
||||
<path fill="#828282" d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761 c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32 c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472 c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037 C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65 c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261 c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082 c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129 c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z"/>
|
||||
</svg>
|
||||
</span>
|
||||
|
||||
<span class="username">{{ site.github_username }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if site.twitter_username %}
|
||||
<li>
|
||||
<a href="https://twitter.com/{{ site.twitter_username }}">
|
||||
<span class="icon icon--twitter">
|
||||
<svg viewBox="0 0 16 16">
|
||||
<path fill="#828282" d="M15.969,3.058c-0.586,0.26-1.217,0.436-1.878,0.515c0.675-0.405,1.194-1.045,1.438-1.809
|
||||
c-0.632,0.375-1.332,0.647-2.076,0.793c-0.596-0.636-1.446-1.033-2.387-1.033c-1.806,0-3.27,1.464-3.27,3.27 c0,0.256,0.029,0.506,0.085,0.745C5.163,5.404,2.753,4.102,1.14,2.124C0.859,2.607,0.698,3.168,0.698,3.767 c0,1.134,0.577,2.135,1.455,2.722C1.616,6.472,1.112,6.325,0.671,6.08c0,0.014,0,0.027,0,0.041c0,1.584,1.127,2.906,2.623,3.206 C3.02,9.402,2.731,9.442,2.433,9.442c-0.211,0-0.416-0.021-0.615-0.059c0.416,1.299,1.624,2.245,3.055,2.271 c-1.119,0.877-2.529,1.4-4.061,1.4c-0.264,0-0.524-0.015-0.78-0.046c1.447,0.928,3.166,1.469,5.013,1.469 c6.015,0,9.304-4.983,9.304-9.304c0-0.142-0.003-0.283-0.009-0.423C14.976,4.29,15.531,3.714,15.969,3.058z"/>
|
||||
</svg>
|
||||
</span>
|
||||
|
||||
<span class="username">{{ site.twitter_username }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-col footer-col-3">
|
||||
<p class="text">{{ site.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
@@ -1,12 +0,0 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</title>
|
||||
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
|
||||
|
||||
<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">
|
||||
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
|
||||
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}">
|
||||
</head>
|
||||
@@ -1,27 +0,0 @@
|
||||
<header class="site-header">
|
||||
|
||||
<div class="wrapper">
|
||||
|
||||
<a class="site-title" href="{{ site.baseurl }}/">{{ site.title }}</a>
|
||||
|
||||
<nav class="site-nav">
|
||||
<a href="#" class="menu-icon">
|
||||
<svg viewBox="0 0 18 15">
|
||||
<path fill="#424242" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/>
|
||||
<path fill="#424242" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/>
|
||||
<path fill="#424242" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/>
|
||||
</svg>
|
||||
</a>
|
||||
|
||||
<div class="trigger">
|
||||
{% for page in site.pages %}
|
||||
{% if page.title %}
|
||||
<a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{{ page.title }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
|
||||
</header>
|
||||
@@ -1,20 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>{{ page.title }}</title>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
{% include head.html %}
|
||||
<!-- syntax highlighting CSS -->
|
||||
<link rel="stylesheet" href="/css/syntax.css">
|
||||
|
||||
<body>
|
||||
<!-- Custom CSS -->
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
|
||||
{% include header.html %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="page-content">
|
||||
<div class="wrapper">
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="site">
|
||||
<div class="header">
|
||||
<h1 class="title"><a href="/">{{ site.name }}</a></h1>
|
||||
<a class="extra" href="/">home</a>
|
||||
</div>
|
||||
|
||||
{% include footer.html %}
|
||||
{{ content }}
|
||||
|
||||
</body>
|
||||
<div class="footer">
|
||||
<div class="contact">
|
||||
<p>
|
||||
Your Name<br />
|
||||
What You Are<br />
|
||||
you@example.com
|
||||
</p>
|
||||
</div>
|
||||
<div class="contact">
|
||||
<p>
|
||||
<a href="https://github.com/yourusername">github.com/yourusername</a><br />
|
||||
<a href="https://twitter.com/yourusername">twitter.com/yourusername</a><br />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
layout: default
|
||||
---
|
||||
<article class="post">
|
||||
|
||||
<header class="post-header">
|
||||
<h1 class="post-title">{{ page.title }}</h1>
|
||||
</header>
|
||||
|
||||
<div class="post-content">
|
||||
{{ content }}
|
||||
</div>
|
||||
|
||||
</article>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user