Skip to content
Snippets Groups Projects
Commit 4fc646e9 authored by Kevin Lin's avatar Kevin Lin
Browse files

Evaluate links in module events

parent 0b0e9850
No related branches found
No related tags found
No related merge requests found
{% capture eval_workspace %}
{% comment %}
Evaluate Liquid tags stored in plaintext.
Supports:
`link` tag for site.pages. Does not raise errors on invalid links.
Parameters:
`content` (string): String containing Liquid tags.
{% endcomment %}
{% capture tags %}{{ "{%|" }}%}{% endcapture %}
{% assign tags = tags | split: "|" %}
{% assign join = "|" %}
{% capture parts %}{% include split.liquid content=include.content queries=tags join=join %}{% endcapture %}
{% assign parts = parts | split: join %}
{% assign result = "" %}
{% for part in parts %}
{% assign subparts = part | split: " " %}
{% assign rest = subparts | slice: 1, subparts.size | join: " " %}
{% case subparts[0] %}
{% when "link" %}
{% comment %}
Jekyll 4.0 supports Liquefied link tags: https://github.com/jekyll/jekyll/pull/6269
{% endcomment %}
{% for page in site.pages %}
{% if page.path == rest %}
{% assign link = page.url | relative_url %}
{% assign result = result | append: link %}
{% endif %}
{% endfor %}
{% else %}
{% assign result = result | append: part %}
{% endcase %}
{% endfor %}
{% endcapture %}{% assign eval_workspace = '' %}{{ result }}
{% capture split_workspace %}
{% comment %}
Split the string on all of the delimiters and join the result.
Parameters:
`content` (string): String to split.
`delimiters` (array of strings): Boundary strings defining what to split.
`join` (string): Join the resulting parts on this string.
{% endcomment %}
{% assign queries = include.queries | default: empty %}
{% assign join = include.join | default: "|" %}
{% if queries.size == 0 %}
{% assign result = include.content %}
{% else %}
{% assign result = include.content | split: queries[0] | join: join %}
{% assign rest = queries | slice: 1, queries.size %}
{% for query in rest %}
{% assign temp = result | split: join %}
{% assign result = "" %}
{% for part in temp %}
{% assign split = part | split: query %}
{% for subpart in split %}
{% comment %}
Suppress repeated delimiters (empty strings).
{% endcomment %}
{% if subpart != "" %}
{% assign result = result | append: join | append: subpart %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
{% endcapture %}{% assign split_workspace = '' %}{{ result }}
......@@ -5,7 +5,11 @@
{% for day in page.days %}
<dt class="module-day">{{ day.date | date: '%b %e' }}</dt>
{% for event in day.events %}
<dd class="module-event">{{ event | first | markdownify }} {{ event | last | markdownify }}</dd>
{% assign main = event | first %}
{% assign info = event | last %}
{% capture main %}{% include eval.liquid content=main %}{% endcapture %}
{% capture info %}{% include eval.liquid content=info %}{% endcapture %}
<dd class="module-event">{{ main | markdownify }} {{ info | markdownify }}</dd>
{% endfor %}
{% endfor %}
</dl>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment