From 1e5e8dc485e8d06e154d5eb8261acbca426f65cb Mon Sep 17 00:00:00 2001 From: Filip Ginter Date: Mon, 21 Dec 2015 11:06:51 +0200 Subject: [PATCH] adding stats to the layout with file_exists plugin --- _layouts/postag.html | 10 ++++++++++ _plugins/file_exists.rb | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 _plugins/file_exists.rb diff --git a/_layouts/postag.html b/_layouts/postag.html index e244a20245c..df1cf8b56c2 100644 --- a/_layouts/postag.html +++ b/_layouts/postag.html @@ -6,6 +6,16 @@

{{ page.title }}: {{ page.shortdef }}

{{ content }} + + +{% capture langdir %}{{ page.path | split:"/" | first | split:"-" | first | replace_first:'_',''}}{% endcapture %} +{% capture statspath %}stats/{{langdir}}/{{page.title}}.md{% endcapture %} +{% capture statsexist %}{% file_exists _includes/{{statspath}} %}{% endcapture %} +{% if statsexist == "true" %} +{% capture statsinclude %}{% include {{statspath}} %}{% endcapture %} +{{ statsinclude | markdownify }} +{% endif %} +
{% for r in site.data.postags %}{% if r.label == page.title %} diff --git a/_plugins/file_exists.rb b/_plugins/file_exists.rb new file mode 100644 index 00000000000..3ce25b570f6 --- /dev/null +++ b/_plugins/file_exists.rb @@ -0,0 +1,20 @@ +module Jekyll + class FileExistsTag < Liquid::Tag + + def initialize(tag_name, path, tokens) + super + @path = path + end + + def render(context) + # ref https://gist.github.com/vanto/1455726 + # pipe param through liquid to make additional replacements possible + url = Liquid::Template.parse(@path).render context + + # check if file exists (returns true or false) + "#{File.exist?(url.strip!)}" + end + end +end + +Liquid::Template.register_tag('file_exists', Jekyll::FileExistsTag)