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

New upstream version 0.12.1

parent a93fa344
......@@ -18,3 +18,4 @@ Gemfile.lock
spec/dest
.bundle
spec/fixtures/.jekyll-metadata
spec/fixtures/.jekyll-cache
require: rubocop-jekyll
inherit_gem:
jekyll: .rubocop.yml
rubocop-jekyll: .rubocop.yml
AllCops:
TargetRubyVersion: 2.3
Include:
- lib/*.rb
- lib/**/*.rb
Exclude:
- .rubocop.yml
- .codeclimate.yml
- .travis.yml
- .gitignore
- .rspec
- .rubocop.yml
- .travis.yml
- Gemfile.lock
- CHANGELOG.md
- readme.md
- History.markdown
- LICENSE.txt
- README.md
- Readme.md
- ReadMe.md
- COPYING
- LICENSE
- test/**/*
- vendor/**/*
- features/**/*
- script/**/*
- spec/**/*
- vendor/**/*
Naming/MemoizedInstanceVariableName:
Exclude:
- lib/jekyll-feed/page-without-a-file.rb
language: ruby
cache: bundler
sudo: false
rvm:
- 2.5
- 2.4
- 2.3
- 2.2
- &latest_ruby 2.6
- 2.4
- 2.3
env:
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:
- gem update --system
- gem install bundler
before_script: bundle update
script: script/cibuild
notifications:
......
......@@ -3,6 +3,9 @@
source "https://rubygems.org"
gemspec
if ENV["JEKYLL_VERSION"]
gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
install_if -> { Gem.win_platform? } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
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
* Define path with __dir (#187)
......@@ -7,6 +52,7 @@
* Fix: Add note about using plugins instead of gems key (#197)
* Add documentation for disabling smartify filter (#205)
* Use `https` in more places. (#165)
### Development Fixes
......@@ -14,15 +60,11 @@
* Test feeds that have a `site.lang` (#164)
* Test against Ruby 2.5 (#201)
## 0.9.3 / 2017-03-28
### Minor Enhancements
* fix <entry> template for posts with post.lang defined (#168)
### Documentation
* Use `https` in more places. (#165)
## 0.9.3 / 2017-03-28
## 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 `/
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
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|
spec.license = "MIT"
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!^(test|spec|features)/!)
spec.test_files = spec.files.grep(%r!^spec/!)
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 "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "0.51"
spec.add_development_dependency "typhoeus", "~> 0.7"
spec.add_development_dependency "rubocop-jekyll", "~> 0.5"
spec.add_development_dependency "typhoeus", ">= 0.7", "< 2.0"
end
......@@ -7,12 +7,20 @@
<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 %}/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ '/' | absolute_url | xml_escape }}</id>
<id>{{ page.url | absolute_url | xml_escape }}</id>
{% if site.title %}
<title type="html">{{ site.title | smartify | xml_escape }}</title>
{% elsif site.name %}
<title type="html">{{ site.name | smartify | xml_escape }}</title>
{% assign title = site.title | default: site.name %}
{% if page.collection != "posts" %}
{% assign collection = page.collection | capitalize %}
{% 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 %}
{% if site.description %}
......@@ -31,7 +39,10 @@
</author>
{% 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 %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
<title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title>
......@@ -72,9 +83,9 @@
{% assign post_image = post.image.path | default: post.image %}
{% if post_image %}
{% unless post_image contains "://" %}
{% assign post_image = post_image | absolute_url | xml_escape %}
{% assign post_image = post_image | absolute_url %}
{% 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 %}
</entry>
{% endfor %}
......
......@@ -8,8 +8,15 @@ module JekyllFeed
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
return if file_exists?(feed_path)
@site.pages << content_for_file(feed_path, feed_source_path)
collections.each do |name, meta|
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
private
......@@ -18,40 +25,88 @@ module JekyllFeed
# 1. A '>', which closes an XML tag or
# 2. A '}', which closes a Liquid tag
# We will strip all of this whitespace to minify the template
MINIFY_REGEX = %r!(?<=>|})\s+!
# Path to feed from config, or feed.xml for default
def feed_path
if @site.config["feed"] && @site.config["feed"]["path"]
@site.config["feed"]["path"]
else
"feed.xml"
MINIFY_REGEX = %r!(?<=>|})\s+!.freeze
# Returns the plugin's config or an empty hash if not set
def config
@config ||= @site.config["feed"] || {}
end
# 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
@collections
end
# Path to feed.xml template file
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
# Checks if a file already exists in the site source
def file_exists?(file_path)
if @site.respond_to?(:in_source_dir)
File.exist? @site.in_source_dir(file_path)
else
File.exist? Jekyll.sanitized_path(@site.source, file_path)
end
File.exist? @site.in_source_dir(file_path)
end
# Generates contents for a file
def content_for_file(file_path, file_source_path)
file = PageWithoutAFile.new(@site, __dir__, "", file_path)
file.content = File.read(file_source_path).gsub(MINIFY_REGEX, "")
file.data["layout"] = nil
file.data["sitemap"] = false
file.data["xsl"] = file_exists?("feed.xslt.xml")
file.output
file
def make_page(file_path, collection: "posts", category: nil)
PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file|
file.content = feed_template
file.data.merge!(
"layout" => nil,
"sitemap" => false,
"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
......@@ -14,7 +14,7 @@ module JekyllFeed
private
def config
@context.registers[:site].config
@config ||= @context.registers[:site].config
end
def attributes
......@@ -27,11 +27,7 @@ module JekyllFeed
end
def path
if config["feed"] && config["feed"]["path"]
config["feed"]["path"]
else
"feed.xml"
end
config.dig("feed", "path") || "feed.xml"
end
def title
......
......@@ -2,6 +2,6 @@
module Jekyll
module Feed
VERSION = "0.9.3"
VERSION = "0.12.1"
end
end
---
category: news
---
Look at me! I'm a collection doc in a category!
......@@ -4,6 +4,6 @@ defaults:
-
scope:
path: ""
type: page
type: pages
values:
layout: some_default
---
excerpt: "Foo"
image: "/image.png"
category: news
---
# 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!
......@@ -3,6 +3,7 @@ tags:
- '"/><VADER>'
image:
path: "/object-image.png"
category: updates
---
March the fourth!
This diff is collapsed.
require 'jekyll'
require 'typhoeus'
require 'nokogiri'
require 'rss'
require File.expand_path('../lib/jekyll-feed', __dir__)
# frozen_string_literal: true
require "jekyll"
require "typhoeus" unless Gem.win_platform?
require "nokogiri"
require "rss"
require File.expand_path("../lib/jekyll-feed", __dir__)
Jekyll.logger.log_level = :error
RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.order = 'random'
config.order = "random"
SOURCE_DIR = File.expand_path("fixtures", __dir__)
DEST_DIR = File.expand_path("dest", __dir__)
......@@ -23,6 +25,6 @@ RSpec.configure do |config|
end
def make_context(registers = {})
Liquid::Context.new({}, {}, { site: site }.merge(registers))
Liquid::Context.new({}, {}, { :site => site }.merge(registers))
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