From 1892bc38d8416a6ec79f37c41a9ffb38b6f44938 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 24 Jan 2025 18:36:15 +0100 Subject: minimalize layout --- _plugins/authors.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 _plugins/authors.rb (limited to '_plugins/authors.rb') diff --git a/_plugins/authors.rb b/_plugins/authors.rb new file mode 100644 index 0000000..a2e0a53 --- /dev/null +++ b/_plugins/authors.rb @@ -0,0 +1,38 @@ +require 'set' + +module Jekyll + class FormatAuthors < Liquid::Tag + def initialize(tag_name, input, tokens) + super + @args = input.split(" ").map { |arg| arg.strip() } + end + + def transform_authors(author_meta, git_authors) + authors = Set[] + for substitute in author_meta do + for name in substitute['git'] do + if git_authors.include?(name) + authors.add(substitute['name']) + end + end + end + return authors.to_a() + end + + def join_names(authors) + return "nobody?" if authors.length == 0 + return "#{authors[0]}" if authors.length == 1 + return "#{authors[0..-2].join(", ")} and #{authors[-1]}" + end + + def render(context) + author_meta = context[@args[0]] + git_authors = context[@args[1]] + authors = transform_authors(author_meta, git_authors) + return join_names(authors) + end + end +end + +Liquid::Template.register_tag('fmt_authors', Jekyll::FormatAuthors) + -- cgit v1.2.3