diff options
-rw-r--r-- | _data/authors.yml | 4 | ||||
-rw-r--r-- | _layouts/default.html | 2 | ||||
-rw-r--r-- | _plugins/authors.rb | 38 | ||||
-rw-r--r-- | _plugins/datefmt.rb | 8 | ||||
-rw-r--r-- | _plugins/filters.rb | 14 | ||||
-rw-r--r-- | _plugins/meta.rb | 5 | ||||
-rw-r--r-- | _plugins/toc.rb | 92 |
7 files changed, 67 insertions, 96 deletions
diff --git a/_data/authors.yml b/_data/authors.yml index 286b392..0ad373a 100644 --- a/_data/authors.yml +++ b/_data/authors.yml @@ -1,7 +1,7 @@ -- name: Loek +- nick: Loek git: - Loek Le Blansch - lonkaars -- name: Willem +- nick: Willem git: - Willem Paternotte diff --git a/_layouts/default.html b/_layouts/default.html index efb2c87..fe0fc36 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -40,7 +40,7 @@ <div class="column"> <span class="title">about this post</span> <ul> - <li>written by {% fmt_authors site.data.authors page.meta.authors %}</li> + <li>written by {{ page.authors | map: 'nick' | sentence_join }}</li> <li>published on {{ page.meta.date | datefmt }}</li> </ul> <ul> diff --git a/_plugins/authors.rb b/_plugins/authors.rb deleted file mode 100644 index a2e0a53..0000000 --- a/_plugins/authors.rb +++ /dev/null @@ -1,38 +0,0 @@ -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) - diff --git a/_plugins/datefmt.rb b/_plugins/datefmt.rb deleted file mode 100644 index 7c2274f..0000000 --- a/_plugins/datefmt.rb +++ /dev/null @@ -1,8 +0,0 @@ -module DateFormatter - def datefmt(input) - return input.strftime("%F") - end -end - -Liquid::Template.register_filter(DateFormatter) - diff --git a/_plugins/filters.rb b/_plugins/filters.rb new file mode 100644 index 0000000..2526573 --- /dev/null +++ b/_plugins/filters.rb @@ -0,0 +1,14 @@ +module Filters + def datefmt(input) + return input.strftime("%F") + end + + def sentence_join(items) + return "" if items == nil or items.length == 0 + return "#{items[0]}" if items.length == 1 + return "#{items[0..-2].join(", ")} and #{items[-1]}" + end +end + +Liquid::Template.register_filter(Filters) + diff --git a/_plugins/meta.rb b/_plugins/meta.rb index f0d420f..85f3a75 100644 --- a/_plugins/meta.rb +++ b/_plugins/meta.rb @@ -8,6 +8,11 @@ module Meta # directly add generated page metadata to `page.meta` in liquid page.data['meta'] = site.data['post'][page.slug] + # set page.authors to author metadata from git+yaml + page.data['authors'] = site.data['authors'].filter { |author| + author['git'].intersect?(page.data['meta']['authors']) + } + # set page.date to generated date_initial page.data['date'] = page.data['meta']['date_initial'] end diff --git a/_plugins/toc.rb b/_plugins/toc.rb index 80acc82..09ef946 100644 --- a/_plugins/toc.rb +++ b/_plugins/toc.rb @@ -1,64 +1,62 @@ require 'nokogiri' -module Jekyll - class TOC < Liquid::Tag - def render context - # load HTML into nokogiri - html = context.registers[:page]['content'] - doc = Nokogiri::HTML(html) - - # enumerate over all h1-4 headings - @els = doc.css("h1, h2, h3, h4") - toc = output_toc() - return '' if toc.empty? - return '<aside id="toc" class="plainlink">%s</aside>' % [ toc ] - end - - def output_toc - # empty toc (this check prevents crash) - return "" if @els.length == 0 +class TOC < Liquid::Tag + def render context + # load HTML into nokogiri + html = context.registers[:page]['content'] + doc = Nokogiri::HTML(html) + + # enumerate over all h1-4 headings + @els = doc.css("h1, h2, h3, h4") + toc = output_toc() + return '' if toc.empty? + return '<aside id="toc" class="plainlink">%s</aside>' % [ toc ] + end - output = '<ul>' + def output_toc + # empty toc (this check prevents crash) + return "" if @els.length == 0 - current_level = el_level(@els[0]) + output = '<ul>' - while @els.length > 0 - el = @els[0] - el_next = @els[1] - level = el_level(el) - level_next = el_level(el_next || el) # || el to prevent crash on end of list + current_level = el_level(@els[0]) - if level >= level_next - output += '<li>' - else - output += '<li class="stub"><details>' - output += '<summary>' - end + while @els.length > 0 + el = @els[0] + el_next = @els[1] + level = el_level(el) + level_next = el_level(el_next || el) # || el to prevent crash on end of list - output += '<a href="#%s">%s</a>' % [ el['id'], el.inner_html ] - @els.shift() + if level >= level_next + output += '<li>' + else + output += '<li class="stub"><details>' + output += '<summary>' + end - if level >= level_next - output += '</li>' - else - output += '</summary>' - output += output_toc - output += '</details></li>' - end + output += '<a href="#%s">%s</a>' % [ el['id'], el.inner_html ] + @els.shift() - break if level_next < level + if level >= level_next + output += '</li>' + else + output += '</summary>' + output += output_toc + output += '</details></li>' end - output += '</ul>' - - return output + break if level_next < level end - def el_level el - return Integer(el.name[1..]) - end + output += '</ul>' + + return output + end + + def el_level el + return Integer(el.name[1..]) end end -Liquid::Template.register_tag('toc', Jekyll::TOC) +Liquid::Template.register_tag('toc', TOC) |