From 918a812d92489d4af1d0f59d4abc1b19c7a076ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 21 May 2018 09:41:41 +0200 Subject: [PATCH] Add logic to exclude some pages based on some tags --- docs/_includes/custom/shuffle_panel.html | 19 ++++++++++++++---- docs/_plugins/custom_filters.rb | 25 +++++++++++------------- docs/_plugins/eval_tag.rb | 3 +-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/docs/_includes/custom/shuffle_panel.html b/docs/_includes/custom/shuffle_panel.html index 8e8512cb60..f537106ca6 100644 --- a/docs/_includes/custom/shuffle_panel.html +++ b/docs/_includes/custom/shuffle_panel.html @@ -1,13 +1,23 @@ - + + + + + + + + {% capture titlemaker %} {{ include.titlemaker | default: "page.title" }} {% endcapture %} +{% assign include_tags = {{ include.tags | split: "," }} %} +{% assign exclude_tags = {{ include.except_tags | split: "," }} %} +
@@ -30,9 +40,10 @@

    {% for page in site.pages %} - {% capture alltags %}{{ page.tags | contains_all: include.tags }}{% endcapture %} - - {% if alltags contains "true" %} + {% capture included %}{{ page.tags | intersect: include_tags | equals: include_tags }}{% endcapture %} + {% capture excluded %}{{ page.tags | intersect: exclude_tags | empty }}{% endcapture %} + + {% if included contains "true" and excluded contains "true" %}
  • {% eval titlemaker %}
  • {% endif %} {% endfor %} diff --git a/docs/_plugins/custom_filters.rb b/docs/_plugins/custom_filters.rb index 7ba31c7114..a61e33e9e8 100644 --- a/docs/_plugins/custom_filters.rb +++ b/docs/_plugins/custom_filters.rb @@ -1,27 +1,24 @@ module CustomFilters - def contains_all(input, test) - if !test - !input - elsif !input - false + def intersect(xs, ys) + if !xs || !ys + [] else - test.split(",").all? {|val| input.include?(val)} - + Array(xs) & Array(ys) end end - def intersect(xs, ys) - xs & ys + def equals(xs, ys) + a = Array(xs) + b = Array(ys) + + ((a | b) - (a & b)).empty? end - def union(xs, ys) - xs | ys + def empty(xs) + Array(xs).empty? end - def diff(xs, ys) - xs - ys - end end Liquid::Template.register_filter(CustomFilters) \ No newline at end of file diff --git a/docs/_plugins/eval_tag.rb b/docs/_plugins/eval_tag.rb index 45fac0ac49..f4f50d95d3 100644 --- a/docs/_plugins/eval_tag.rb +++ b/docs/_plugins/eval_tag.rb @@ -1,6 +1,5 @@ -# This tag takes a variable name as an input, and evaluates its value twice -# (follows one indirection) +# This tag takes a variable name as an input, and evaluates its value twice (dereferences it once) # E.g. if the symbol table is E = {"foo" => "bar", "bar" => "baz"}, # then {% eval foo %} ~> E[E["foo"]] ~> E["bar"] ~> "baz"