aboutsummaryrefslogtreecommitdiff
path: root/_plugins
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-11-14 12:59:13 -0300
committerEuAndreh <eu@euandre.org>2020-11-14 13:51:07 -0300
commit4feb22921294fed75806564bde27b0ee746227aa (patch)
tree3f5b77e5a63b087f3ef5fd52ff1ad2482d23872c /_plugins
parentplaintext generator: Filter the collection instead of each document (diff)
downloadeuandre.org-4feb22921294fed75806564bde27b0ee746227aa.tar.gz
euandre.org-4feb22921294fed75806564bde27b0ee746227aa.tar.xz
Generate feeds for each categorized entries
Diffstat (limited to '')
-rw-r--r--_plugins/generate-feeds-for-categories.rb48
-rw-r--r--_plugins/generate-pastebin-plaintext-alternate.rb4
-rw-r--r--_plugins/has-category-filter.rb13
3 files changed, 63 insertions, 2 deletions
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)