Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feeds for all #276

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
{% endif %}
{% if page.category %}
{% assign category = page.category | capitalize %}
{% assign title = title | append: " | " | append: category %}
{% assign title = title | append: " : " | append: category %}
{% elsif page.tag %}
{% assign tag = page.tag | capitalize %}
{% assign title = title | append: " ][ " | append: tag %}
{% endif %}

{% if title %}
Expand All @@ -40,8 +43,13 @@
{% endif %}

{% assign posts = site[page.collection] | where_exp: "post", "post.draft != true" | sort: "date" | reverse %}

{% if page.category %}
{% assign posts = posts | where: "category",page.category %}
{%- assign catlist = posts | where_exp: "post","post.categories contains page.category" -%}
{%- assign catsingular = posts | where: "category",page.category -%}
{%- assign posts = catlist | push: catsingular -%}
{% elsif page.tag %}
{% assign posts = posts | where_exp: "post","post.tags contains page.tag" %}
{% endif %}
{% for post in posts limit: 10 %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
Expand Down
73 changes: 68 additions & 5 deletions lib/jekyll-feed/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,65 @@

module JekyllFeed
class Generator < Jekyll::Generator
include Jekyll::Filters
safe true
priority :lowest

# Main plugin action, called by Jekyll-core
# def generate(site)
# @site = site
# 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
def generate(site)
puts "jekyll-feed: local modified version"
@site = site
collections.each do |name, meta|
Jekyll.logger.info "Jekyll Feed:", "Generating feed for #{name}"
#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)
#Jekyll.logger.info "categories: ", "#{category}"
if category == "feedsforall"
@site.categories.each do |cat|
kitty = slugify(cat[0], "pretty")
path = feed_path(:collection => name, :category => "category/#{kitty}")
next if file_exists?(path)

#Jekyll.logger.info "feed cat:", "should generate feed for #{kitty}"
@site.pages << make_page(path, :collection => name, :category => cat[0])
end
else
#Jekyll.logger.info "feed cat:", "else generate feed for #{category}"
path = category ? feed_path(:collection => name, :category => "category/#{category}") : feed_path(:collection => name, :category => category)
next if file_exists?(path)

@site.pages << make_page(path, :collection => name, :category => category)
end
end
(meta["tags"] + [nil]).each do |tag|
#Jekyll.logger.info "tag: ", "#{tag}"
if tag == "feedsforall"
@site.tags.each do |stag|
fawn = slugify(stag[0], "pretty")
path = feed_path(:collection => name, :category => "tag/#{fawn}")
next if file_exists?(path)

#Jekyll.logger.info "feed tag:", "should generate feed for #{fawn}"
@site.pages << make_tag_page(path, :collection => name, :tag => stag)
end
elsif tag
#Jekyll.logger.info "feed tag:", "else generate feed for #{tag}"
path = feed_path(:collection => name, :category => "tag/#{tag}")
next if file_exists?(path)

@site.pages << make_tag_page(path, :collection => name, :tag => tag) if tag
end
end
end
end
Expand Down Expand Up @@ -64,6 +110,7 @@ def collections
@collections = normalize_posts_meta(@collections)
@collections.each_value do |meta|
meta["categories"] = (meta["categories"] || []).to_set
meta["tags"] = (meta["tags"] || []).to_set
end

@collections
Expand Down Expand Up @@ -99,12 +146,28 @@ def make_page(file_path, collection: "posts", category: nil)
end
end

def make_tag_page(file_path, collection: "posts", tag: 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,
"tag" => tag[0]
)
#Jekyll.logger.info "feed tag:", "Generating feed for #{tag[0]}"
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"]
hash["posts"]["tags"] ||= config["tags"]
config["path"] ||= hash["posts"]["path"]
hash
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-feed/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Jekyll
module Feed
VERSION = "0.12.1"
VERSION = "0.12.1.2"
end
end