Automated updates: 2020-06-15

This commit is contained in:
John Colagioia 2020-06-15 08:07:14 -04:00
parent 372d6898a1
commit 3b2983b0e6
1 changed files with 31 additions and 29 deletions

View File

@ -24,52 +24,54 @@ However, publishing the single update post doesn't solve the discoverability pro
I resolved the problem by adding an `update` section to my post headers (you can see this in version control, like in [Sunday's file](https://github.com/jcolag/entropy-arbitrage/blob/master/2020-06-07-updates.md)). Then, I needed code in my template to check the page for companions and list them if available. It looks something like this, with the most obnoxious part being that [Liquid templates](https://shopify.github.io/liquid/) have no interest in creating arrays.
```html
{% assign pagename = page.path | split: '/' | last %}
{% assign related = "" %}
{% for post in site.posts %}
{% for update in post.update %}
{% assign name = update | split: '/' | last %}
{% if name == pagename %}
{% assign dest = post.title %}
{% assign dest = dest | append: "," %}
{% assign dest = dest | append: post.url %}
{% assign dest = dest | append: "," %}
{% assign dest = dest | append: post.date %}
{% assign dest = dest | append: ";" %}
{% assign related = related | append: dest %}
{% endif %}
{% endfor %}
{% endfor %}
{% assign related = related | split: ";" %}
{% if related.size > 0 %}
{ % assign pagename = page.path | split: '/' | last %}
{ % assign related = "" %}
{ % for post in site.posts %}
{ % for update in post.update %}
{ % assign name = update | split: '/' | last %}
{ % if name == pagename %}
{ % assign dest = post.title %}
{ % assign dest = dest | append: "," %}
{ % assign dest = dest | append: post.url %}
{ % assign dest = dest | append: "," %}
{ % assign dest = dest | append: post.date %}
{ % assign dest = dest | append: ";" %}
{ % assign related = related | append: dest %}
{ % endif %}
{ % endfor %}
{ % endfor %}
{ % assign related = related | split: ";" %}
{ % if related.size > 0 %}
<div class="post-content">
<b>Hi!</b>
It looks like this post has since been rethought in various
ways, so you may want to look at
{% if related.size == 1 %}
{ % if related.size == 1 %}
this
{% else %}
{ % else %}
these
{% endif %}
{ % endif %}
after you're done reading here.
<ul>
{% for r in related %}
{% assign rel = r | split: "," %}
{% if rel.size > 1 %}
{ % for r in related %}
{ % assign rel = r | split: "," %}
{ % if rel.size > 1 %}
<li>
<a href="{{ rel[1] }}">
{{ rel[0] }}
{ { rel[0] }}
</a>
from
{{ rel[2] | date: date_format }}
{ { rel[2] | date: date_format }}
</li>
{% endif %}
{% endfor %}
{ % endif %}
{ % endfor %}
</ul>
</div>
{% endif %}
{ % endif %}
```
(As usual, I had to add spaces to get the Liquid template code to display, because otherwise, the blog software tries to interpret it. You'll need to remove those spaces, if you copy and paste the code.)
This takes the internal name of the blog post and tries to match it to the `update` lists of all the other posts, creating a delimited list of titles, file names, and dates. Then, it breaks that string up into an array and, if the array has anything in it, shows them as hyperlinks to the referencing pages. Note that I may need to swing back and change those delimiters, since the odds of finding a comma seem unpleasantly high.
I don't know if I'm interested in doing so, yet, but a similar process could probably be used to suggest a few related posts to readers. Too much?