Commit 2d8df733 authored by Daniel Leidert's avatar Daniel Leidert

New upstream version 0.12.1

parent a93fa344
...@@ -18,3 +18,4 @@ Gemfile.lock ...@@ -18,3 +18,4 @@ Gemfile.lock
spec/dest spec/dest
.bundle .bundle
spec/fixtures/.jekyll-metadata spec/fixtures/.jekyll-metadata
spec/fixtures/.jekyll-cache
require: rubocop-jekyll
inherit_gem: inherit_gem:
jekyll: .rubocop.yml rubocop-jekyll: .rubocop.yml
AllCops: AllCops:
TargetRubyVersion: 2.3 TargetRubyVersion: 2.3
Include: Include:
- lib/*.rb - lib/**/*.rb
Exclude: Exclude:
- .rubocop.yml
- .codeclimate.yml
- .travis.yml
- .gitignore - .gitignore
- .rspec - .rspec
- .rubocop.yml
- .travis.yml
- Gemfile.lock - Gemfile.lock
- CHANGELOG.md - History.markdown
- readme.md - LICENSE.txt
- README.md - README.md
- Readme.md
- ReadMe.md
- COPYING
- LICENSE
- test/**/*
- vendor/**/*
- features/**/*
- script/**/* - script/**/*
- spec/**/* - vendor/**/*
Naming/MemoizedInstanceVariableName:
Exclude:
- lib/jekyll-feed/page-without-a-file.rb
language: ruby language: ruby
cache: bundler cache: bundler
sudo: false
rvm: rvm:
- 2.5 - &latest_ruby 2.6
- 2.4 - 2.4
- 2.3 - 2.3
- 2.2
env: env:
global: global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
matrix:
- JEKYLL_VERSION="~> 3.8"
matrix:
include:
- rvm: *latest_ruby
env: JEKYLL_VERSION="~> 3.7.4"
- rvm: *latest_ruby
env: JEKYLL_VERSION=">= 4.0.0.pre.alpha1"
before_install: before_install:
- gem update --system - gem update --system
- gem install bundler
before_script: bundle update before_script: bundle update
script: script/cibuild script: script/cibuild
notifications: notifications:
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec gemspec
if ENV["JEKYLL_VERSION"] gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
install_if -> { Gem.win_platform? } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
end end
## 0.12.1 / 2019-03-23
* Release: v0.12.0 (#271)
### Bug Fixes
* Re-introduce Ruby 2.3 support and test Jekyll 3.7+ (#272)
## 0.12.0 / 2019-03-21
* Allow Jekyll v4 (still alpha)
### Development Fixes
* style: fix offenses in specs (#248)
* dev: update CI and style settings (#258)
* Enable testing for Windows platform (#265)
## 0.11.0 / 2018-09-09
### Development Fixes
* Require Ruby 2.3 (#222)
* Refactor to remove redundant calls and variables (#240)
### Minor Enhancements
* Categories and collections (#228)
* Remove check for older version of Jekyll (#234)
## 0.10.0 / 2018-06-04
### Bug Fixes
* Escape image URL (#209)
### Development Fixes
* Rubocop 0.55 (#223)
* Bump Rubocop (#230)
### Minor Enhancements
* Support Typhoeus 1.0 (#232)
## 0.9.3 / 2018-02-04 ## 0.9.3 / 2018-02-04
* Define path with __dir (#187) * Define path with __dir (#187)
...@@ -7,6 +52,7 @@ ...@@ -7,6 +52,7 @@
* Fix: Add note about using plugins instead of gems key (#197) * Fix: Add note about using plugins instead of gems key (#197)
* Add documentation for disabling smartify filter (#205) * Add documentation for disabling smartify filter (#205)
* Use `https` in more places. (#165)
### Development Fixes ### Development Fixes
...@@ -14,15 +60,11 @@ ...@@ -14,15 +60,11 @@
* Test feeds that have a `site.lang` (#164) * Test feeds that have a `site.lang` (#164)
* Test against Ruby 2.5 (#201) * Test against Ruby 2.5 (#201)
## 0.9.3 / 2017-03-28
### Minor Enhancements ### Minor Enhancements
* fix <entry> template for posts with post.lang defined (#168) * fix <entry> template for posts with post.lang defined (#168)
### Documentation ## 0.9.3 / 2017-03-28
* Use `https` in more places. (#165)
## 0.9.1 / 2017-02-17 ## 0.9.1 / 2017-02-17
......
...@@ -140,6 +140,48 @@ Want to style what your feed looks like in the browser? Simply add an XSLT at `/ ...@@ -140,6 +140,48 @@ Want to style what your feed looks like in the browser? Simply add an XSLT at `/
Great question. In short, Atom is a better format. Think of it like RSS 3.0. For more information, see [this discussion on why we chose Atom over RSS 2.0](https://github.com/jekyll/jekyll-rss-feed/issues/2). Great question. In short, Atom is a better format. Think of it like RSS 3.0. For more information, see [this discussion on why we chose Atom over RSS 2.0](https://github.com/jekyll/jekyll-rss-feed/issues/2).
## Categories
Jekyll Feed can generate feeds for each category. Simply define which categories you'd like feeds for in your config:
```yml
feed:
categories:
- news
- updates
```
## Collections
Jekyll Feed can generate feeds for collections other than the Posts collection. This works best for chronological collections (e.g., collections with dates in the filenames). Simply define which collections you'd like feeds for in your config:
```yml
feed:
collections:
- changes
```
By default, collection feeds will be outputted to `/feed/<COLLECTION>.xml`. If you'd like to customize the output path, specify a collection's custom path as follows:
```yml
feed:
collections:
changes:
path: "/changes.xml"
```
Finally, collections can also have category feeds which are outputted as `/feed/<COLLECTION>/<CATEGORY>.xml`. Specify categories like so:
```yml
feed:
collections:
changes:
path: "/changes.xml"
categories:
- news
- updates
```
## Contributing ## Contributing
1. Fork it (https://github.com/jekyll/jekyll-feed/fork) 1. Fork it (https://github.com/jekyll/jekyll-feed/fork)
......
version: "{build}"
clone_depth: 5
build: off
environment:
NOKOGIRI_USE_SYSTEM_LIBRARIES: true
JEKYLL_VERSION: "~> 3.8"
matrix:
- RUBY_FOLDER_VER: "26"
JEKYLL_VERSION : "~> 3.7.4"
- RUBY_FOLDER_VER: "26"
JEKYLL_VERSION : ">= 4.0.0.pre.alpha1"
- RUBY_FOLDER_VER: "26"
- RUBY_FOLDER_VER: "24"
- RUBY_FOLDER_VER: "23"
install:
- SET PATH=C:\Ruby%RUBY_FOLDER_VER%-x64\bin;%PATH%
- bundle install --retry 5 --jobs=%NUMBER_OF_PROCESSORS% --clean --path vendor\bundle
test_script:
- ruby --version
- gem --version
- bundler --version
- bash ./script/test
cache:
# If one of the files after the right arrow changes, cache will be invalidated
- 'vendor\bundle -> appveyor.yml, Gemfile, jekyll-feed.gemspec'
...@@ -14,16 +14,17 @@ Gem::Specification.new do |spec| ...@@ -14,16 +14,17 @@ Gem::Specification.new do |spec|
spec.license = "MIT" spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0") spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r!^spec/!)
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
spec.require_paths = ["lib"] spec.require_paths = ["lib"]
spec.add_dependency "jekyll", "~> 3.3" spec.required_ruby_version = ">= 2.3.0"
spec.add_development_dependency "bundler", "~> 1.15" spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "nokogiri", "~> 1.6" spec.add_development_dependency "nokogiri", "~> 1.6"
spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "0.51" spec.add_development_dependency "rubocop-jekyll", "~> 0.5"
spec.add_development_dependency "typhoeus", "~> 0.7" spec.add_development_dependency "typhoeus", ">= 0.7", "< 2.0"
end end
...@@ -7,12 +7,20 @@ ...@@ -7,12 +7,20 @@
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" /> <link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/> <link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
<updated>{{ site.time | date_to_xmlschema }}</updated> <updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ '/' | absolute_url | xml_escape }}</id> <id>{{ page.url | absolute_url | xml_escape }}</id>
{% if site.title %} {% assign title = site.title | default: site.name %}
<title type="html">{{ site.title | smartify | xml_escape }}</title> {% if page.collection != "posts" %}
{% elsif site.name %} {% assign collection = page.collection | capitalize %}
<title type="html">{{ site.name | smartify | xml_escape }}</title> {% assign title = title | append: " | " | append: collection %}
{% endif %}
{% if page.category %}
{% assign category = page.category | capitalize %}
{% assign title = title | append: " | " | append: category %}
{% endif %}
{% if title %}
<title type="html">{{ title | smartify | xml_escape }}</title>
{% endif %} {% endif %}
{% if site.description %} {% if site.description %}
...@@ -31,7 +39,10 @@ ...@@ -31,7 +39,10 @@
</author> </author>
{% endif %} {% endif %}
{% assign posts = site.posts | where_exp: "post", "post.draft != true" %} {% assign posts = site[page.collection] | where_exp: "post", "post.draft != true" | sort: "date" | reverse %}
{% if page.category %}
{% assign posts = posts | where: "category",page.category %}
{% endif %}
{% for post in posts limit: 10 %} {% for post in posts limit: 10 %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}> <entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
<title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title> <title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title>
...@@ -72,9 +83,9 @@ ...@@ -72,9 +83,9 @@
{% assign post_image = post.image.path | default: post.image %} {% assign post_image = post.image.path | default: post.image %}
{% if post_image %} {% if post_image %}
{% unless post_image contains "://" %} {% unless post_image contains "://" %}
{% assign post_image = post_image | absolute_url | xml_escape %} {% assign post_image = post_image | absolute_url %}
{% endunless %} {% endunless %}
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image }}" /> <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image | xml_escape }}" />
{% endif %} {% endif %}
</entry> </entry>
{% endfor %} {% endfor %}
......
...@@ -8,8 +8,15 @@ module JekyllFeed ...@@ -8,8 +8,15 @@ module JekyllFeed
# Main plugin action, called by Jekyll-core # Main plugin action, called by Jekyll-core
def generate(site) def generate(site)
@site = site @site = site
return if file_exists?(feed_path) collections.each do |name, meta|
@site.pages << content_for_file(feed_path, feed_source_path) Jekyll.logger.info "Jekyll Feed:", "Generating feed for #{name}"
(meta["categories"] + [nil]).each do |category|
path = feed_path(:collection => name, :category => category)
next if file_exists?(path)
@site.pages << make_page(path, :collection => name, :category => category)
end
end
end end
private private
...@@ -18,40 +25,88 @@ module JekyllFeed ...@@ -18,40 +25,88 @@ module JekyllFeed
# 1. A '>', which closes an XML tag or # 1. A '>', which closes an XML tag or
# 2. A '}', which closes a Liquid tag # 2. A '}', which closes a Liquid tag
# We will strip all of this whitespace to minify the template # We will strip all of this whitespace to minify the template
MINIFY_REGEX = %r!(?<=>|})\s+! MINIFY_REGEX = %r!(?<=>|})\s+!.freeze
# Path to feed from config, or feed.xml for default # Returns the plugin's config or an empty hash if not set
def feed_path def config
if @site.config["feed"] && @site.config["feed"]["path"] @config ||= @site.config["feed"] || {}
@site.config["feed"]["path"] end
else
"feed.xml" # Determines the destination path of a given feed
#
# collection - the name of a collection, e.g., "posts"
# category - a category within that collection, e.g., "news"
#
# Will return "/feed.xml", or the config-specified default feed for posts
# Will return `/feed/category.xml` for post categories
# WIll return `/feed/collection.xml` for other collections
# Will return `/feed/collection/category.xml` for other collection categories
def feed_path(collection: "posts", category: nil)
prefix = collection == "posts" ? "/feed" : "/feed/#{collection}"
return "#{prefix}/#{category}.xml" if category
collections.dig(collection, "path") || "#{prefix}.xml"
end
# Returns a hash representing all collections to be processed and their metadata
# in the form of { collection_name => { categories = [...], path = "..." } }
def collections
return @collections if defined?(@collections)
@collections = if config["collections"].is_a?(Array)
config["collections"].map { |c| [c, {}] }.to_h
elsif config["collections"].is_a?(Hash)
config["collections"]
else
{}
end
@collections = normalize_posts_meta(@collections)
@collections.each_value do |meta|
meta["categories"] = (meta["categories"] || []).to_set
end end
@collections
end end
# Path to feed.xml template file # Path to feed.xml template file
def feed_source_path def feed_source_path
File.expand_path "feed.xml", __dir__ @feed_source_path ||= File.expand_path "feed.xml", __dir__
end
def feed_template
@feed_template ||= File.read(feed_source_path).gsub(MINIFY_REGEX, "")
end end
# Checks if a file already exists in the site source # Checks if a file already exists in the site source
def file_exists?(file_path) def file_exists?(file_path)
if @site.respond_to?(:in_source_dir) File.exist? @site.in_source_dir(file_path)
File.exist? @site.in_source_dir(file_path)
else
File.exist? Jekyll.sanitized_path(@site.source, file_path)
end
end end
# Generates contents for a file # Generates contents for a file
def content_for_file(file_path, file_source_path)
file = PageWithoutAFile.new(@site, __dir__, "", file_path) def make_page(file_path, collection: "posts", category: nil)
file.content = File.read(file_source_path).gsub(MINIFY_REGEX, "") PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file|
file.data["layout"] = nil file.content = feed_template
file.data["sitemap"] = false file.data.merge!(
file.data["xsl"] = file_exists?("feed.xslt.xml") "layout" => nil,
file.output "sitemap" => false,
file "xsl" => file_exists?("feed.xslt.xml"),
"collection" => collection,
"category" => category
)
file.output
end
end
# Special case the "posts" collection, which, for ease of use and backwards
# compatability, can be configured via top-level keys or directly as a collection
def normalize_posts_meta(hash)
hash["posts"] ||= {}
hash["posts"]["path"] ||= config["path"]
hash["posts"]["categories"] ||= config["categories"]
config["path"] ||= hash["posts"]["path"]
hash
end end
end end
end end
...@@ -14,7 +14,7 @@ module JekyllFeed ...@@ -14,7 +14,7 @@ module JekyllFeed
private private
def config def config
@context.registers[:site].config @config ||= @context.registers[:site].config
end end
def attributes def attributes
...@@ -27,11 +27,7 @@ module JekyllFeed ...@@ -27,11 +27,7 @@ module JekyllFeed
end end
def path def path
if config["feed"] && config["feed"]["path"] config.dig("feed", "path") || "feed.xml"
config["feed"]["path"]
else
"feed.xml"
end
end end
def title def title
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
module Jekyll module Jekyll
module Feed module Feed
VERSION = "0.9.3" VERSION = "0.12.1"
end end
end end
---
category: news
---
Look at me! I'm a collection doc in a category!
...@@ -4,6 +4,6 @@ defaults: ...@@ -4,6 +4,6 @@ defaults:
- -
scope: scope:
path: "" path: ""
type: page type: pages
values: values:
layout: some_default layout: some_default
--- ---
excerpt: "Foo" excerpt: "Foo"
image: "/image.png" image: "/image.png"
category: news
--- ---
# December the twelfth, actually. # December the twelfth, actually.
--- ---
image: "https://cdn.example.org/absolute.png" image: https://cdn.example.org/absolute.png?h=188&w=250
category: news
--- ---
March the second! March the second!
...@@ -3,6 +3,7 @@ tags: ...@@ -3,6 +3,7 @@ tags:
- '"/><VADER>' - '"/><VADER>'
image: image:
path: "/object-image.png" path: "/object-image.png"
category: updates
--- ---
March the fourth! March the fourth!
This diff is collapsed.
require 'jekyll' # frozen_string_literal: true
require 'typhoeus'
require 'nokogiri' require "jekyll"
require 'rss' require "typhoeus" unless Gem.win_platform?
require File.expand_path('../lib/jekyll-feed', __dir__) require "nokogiri"
require "rss"
require File.expand_path("../lib/jekyll-feed", __dir__)
Jekyll.logger.log_level = :error Jekyll.logger.log_level = :error
RSpec.configure do |config| RSpec.configure do |config|
config.run_all_when_everything_filtered = true config.run_all_when_everything_filtered = true
config.filter_run :focus config.filter_run :focus
config.order = 'random' config.order = "random"
SOURCE_DIR = File.expand_path("fixtures", __dir__) SOURCE_DIR = File.expand_path("fixtures", __dir__)
DEST_DIR = File.expand_path("dest", __dir__) DEST_DIR = File.expand_path("dest", __dir__)
...@@ -23,6 +25,6 @@ RSpec.configure do |config| ...@@ -23,6 +25,6 @@ RSpec.configure do |config|
end end
def make_context(registers = {}) def make_context(registers = {})
Liquid::Context.new({}, {}, { site: site }.merge(registers)) Liquid::Context.new({}, {}, { :site => site }.merge(registers))
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment