diff options
Diffstat (limited to '')
-rw-r--r-- | _includes/feed.atom | 2 | ||||
-rw-r--r-- | _plugins/generate-feeds-for-categories.rb | 48 | ||||
-rw-r--r-- | _plugins/generate-pastebin-plaintext-alternate.rb | 4 | ||||
-rw-r--r-- | _plugins/has-category-filter.rb | 13 |
4 files changed, 64 insertions, 3 deletions
diff --git a/_includes/feed.atom b/_includes/feed.atom index c4a0e3d..e627f9c 100644 --- a/_includes/feed.atom +++ b/_includes/feed.atom @@ -12,7 +12,7 @@ <email>{{ site.author.email | xml_escape }}</email> </author> - {% assign entries = include.entries | where:"lang", include.lang | sort: "date" | reverse %} + {% assign entries = include.entries | where:"lang", include.lang | has_category:include.categories_filter | sort: "date" | reverse %} {% for entry in entries %} <entry xml:lang="{{ entry.lang }}"> <title type="html">{{ entry.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title> diff --git a/_plugins/generate-feeds-for-categories.rb b/_plugins/generate-feeds-for-categories.rb new file mode 100644 index 0000000..f5cc8db --- /dev/null +++ b/_plugins/generate-feeds-for-categories.rb @@ -0,0 +1,48 @@ +module Jekyll + class FeedsForCategoriesGenerator < Generator + safe true + + def gen_categories_index(site) + categories_index = {} + site.collections.each do |collection| + collection_name, collection_documents = collection + collection_documents.docs.each do |document| + lang = document.data["lang"] + categories = document.data["eu_categories"] + if categories != nil + categories.split(",").each do |category| + categories_index[collection_name] ||= {} + categories_index[collection_name][lang] ||= {} + categories_index[collection_name][lang][category] ||= [] + + categories_index[collection_name][lang][category] << document + end + end + end + end + categories_index + end + + def generate(site) + gen_categories_index(site).each do |collection_name, langs| + langs.each do |lang, categories| + categories.each do |category_name, articles| + category = category_name.gsub(/ /, '-') + feed_name = "feed.#{collection_name}-by-category.#{lang}.#{category}.atom" + page = PageWithoutAFile.new(site, site.source, "", feed_name) + page.content = <<-EOF +{% include feed.atom entries=site.#{collection_name} kind="#{collection_name}" lang="#{lang}" categories_filter="#{category_name}" %} + EOF + site.pages << page + end + end + end + end + end + + class PageWithoutAFile < Jekyll::Page + def read_yaml(*) + @data ||= {} + end + end +end diff --git a/_plugins/generate-pastebin-plaintext-alternate.rb b/_plugins/generate-pastebin-plaintext-alternate.rb index 93cc74e..3b5fb9a 100644 --- a/_plugins/generate-pastebin-plaintext-alternate.rb +++ b/_plugins/generate-pastebin-plaintext-alternate.rb @@ -20,7 +20,7 @@ module Jekyll .gsub(/<span class=".*?">(.*?)<\/span>/m, '\1') content = CGI.unescapeHTML unhighlighted_code name = "#{document.url}.#{n}.txt" - plain = PageWithoutAFile.new(site, site.source, "", name) + plain = PlaintextPageWithoutAFile.new(site, site.source, "", name) plain.content = content site.pages << plain n += 1 @@ -33,7 +33,7 @@ module Jekyll # Taken from: # https://github.com/jekyll/jekyll-feed/blob/c552b8ef7bd7a4babcfb5aec2b22283a5bc354dd/lib/jekyll-feed/page-without-a-file.rb#L4 - class PageWithoutAFile < Jekyll::Page + class PlaintextPageWithoutAFile < Jekyll::Page def read_yaml(*) @data ||= { "plaintext" => "true" diff --git a/_plugins/has-category-filter.rb b/_plugins/has-category-filter.rb new file mode 100644 index 0000000..fee9b0d --- /dev/null +++ b/_plugins/has-category-filter.rb @@ -0,0 +1,13 @@ +module Jekyll + module CategoryFilter + def has_category(input, category) + if category + input.select { |entry| entry.data["eu_categories"]&.split(',')&.include? category } + else + input + end + end + end +end + +Liquid::Template.register_filter(Jekyll::CategoryFilter) |