Skip to content

Commit

Permalink
Make related notes section not just based on recency (Jekyll's default).
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-p-randall committed Jun 30, 2024
1 parent a730ea4 commit 15e2381
Show file tree
Hide file tree
Showing 20 changed files with 537 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ defaults:
path: ""
type: posts
values:
layout: single
layout: single-custom-related-categories
author_profile: false # true
breadcrumbs: true
comments: true
Expand Down
23 changes: 23 additions & 0 deletions _includes/related-single-categories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- {% assign tags_common_sorted = commonTags.tags | sort_natural %} -->

<h3><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h3>
{% include page__meta.html type=include.type %}
<p>
{{ post.excerpt }}
</p>
<!--<details class="tags" style="font-size: .9em;"><summary>
{{ site.data.ui-text[site.locale].categories_label | default: "Categories" }}
</summary>
<div>
<ul class="list-unstyled">
{% for category in post.categories %}
<li style="font-size: .9em;">-->
<p>Category:
<a href="{{ category | slugify | prepend: path_type | prepend: site.tag_archive.path | relative_url }}" class="page__taxonomy-item p-category" rel="category">{{ category }}</a><!-- {% unless forloop.last %}<span class="sep">, </span>{% endunless %}-->

</p>
<!--</li>
{% endfor %}
</ul>
</div>
</details>-->
20 changes: 20 additions & 0 deletions _includes/related-single-tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- {% assign tags_common_sorted = commonTags.tags | sort_natural %} -->

<h3><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h3>
{% include page__meta.html type=include.type %}
<p>
{{ post.excerpt }}
</p>
<details class="tags" style="font-size: .9em;"><summary>
{{ site.data.ui-text[site.locale].tags_label | default: "Tags" }}
</summary>
<div>
<ul class="list-unstyled">
{% for tag in post.tags %}
<li style="font-size: .9em;">
<a href="{{ tag | slugify | prepend: path_type | prepend: site.tag_archive.path | relative_url }}" class="page__taxonomy-item p-category" rel="tag">{{ tag }}</a><!-- {% unless forloop.last %}<span class="sep">, </span>{% endunless %}-->
</li>
{% endfor %}
</ul>
</div>
</details>
202 changes: 202 additions & 0 deletions _layouts/single-custom-related-categories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
---
layout: default
---

{% if page.header.overlay_color or page.header.overlay_image or page.header.image %}
{% include page__hero.html %}
{% elsif page.header.video.id and page.header.video.provider %}
{% include page__hero_video.html %}
{% endif %}

{% assign breadcrumbs_enabled = site.breadcrumbs %}
{% if page.breadcrumbs != null %}
{% assign breadcrumbs_enabled = page.breadcrumbs %}
{% endif %}
{% if page.url != "/" and breadcrumbs_enabled %}
{% unless paginator %}
{% include breadcrumbs.html %}
{% endunless %}
{% endif %}

<div id="main" role="main">
{% include sidebar.html %}
<article class="page h-entry" itemscope itemtype="https://schema.org/CreativeWork">
{% if page.title %}<meta itemprop="headline" content="{{ page.title | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
{% if page.excerpt %}<meta itemprop="description" content="{{ page.excerpt | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
{% if page.date %}<meta itemprop="datePublished" content="{{ page.date | date_to_xmlschema }}">{% endif %}
{% if page.last_modified_at %}<meta itemprop="dateModified" content="{{ page.last_modified_at | date_to_xmlschema }}">{% endif %}

<div class="page__inner-wrap">
{% unless page.header.overlay_color or page.header.overlay_image %}
<header>
{% if page.title %}<h1 id="page-title" class="page__title p-name" itemprop="headline">
<a href="{{ page.url | absolute_url }}" class="u-url" itemprop="url">{{ page.title | markdownify | remove: "<p>" | remove: "</p>" }}</a>
</h1>{% endif %}
{% include page__meta.html %}
</header>
{% endunless %}

<section class="page__content e-content" itemprop="text">
{% if page.toc %}
<aside class="sidebar__right {% if page.toc_sticky %}sticky{% endif %}">
<nav class="toc">
<header><h2 class="nav__title"><i class="fas fa-{{ page.toc_icon | default: 'file-alt' }}"></i> {{ page.toc_label | default: site.data.ui-text[site.locale].toc_label | default: "On this page" }}</h2></header>{% comment %}these were h4{% endcomment %}
{% include toc.html sanitize=true html=content h_min=1 h_max=6 class="toc__menu" skip_no_ids=true %}
</nav>
</aside>
{% endif %}
{% comment %}{% include light-mode-only-notice.html %}{% endcomment %}
{{ content }}
{% if page.categories contains "photonic-jukebox" %}
{% include p-j-info.html %}
{% else %}
{% endif %}
{% if page.categories contains "notes" %}
{% include notes-index-mention.html %}
{% else %}
{% endif %}
{% if page.link %}<div><a href="{{ page.link }}" class="btn btn--primary">{{ site.data.ui-text[site.locale].ext_link_label | default: "Direct Link" }}</a></div>{% endif %}
</section>
{% comment %}{% endcomment %}
<aside style="font-size: 0.9em; margin-top: 1em;">
<h2 id="bonus-info">Bonus Info</h2>
<h3 id="backlinks-page" style="margin-bottom: 1em">Other places I mention this page <!-- Notes mentioning this note--></h3>
{% if page.backlinks.size > 0 %}
<div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(2, 0.5fr);">
{% for backlink in page.backlinks %}
{% if backlink.dir != "/_posts/" %}
<div class="backlink-box">
<a class="internal-link"
href="{{ site.baseurl }}{{ backlink.url }}{%- if site.use_html_extension -%}.html{%- endif -%}">{{
backlink.title }}</a><br>
<div style="font-size: 0.9em; margin: 0;">{{ backlink.excerpt | markdownify | truncatewords: 20 }}</div> <!-- initially was backlink.excerpt | strip_html | truncatewords: 20 -->
</div>
{% endif %}
{% endfor %}
</div>
{% else %}
<div style="font-size: 0.9em">
<p>I don't mention this page elsewhere… <strong>yet</strong>.<!-- There are no notes linking to this note. -->
</p>
</div>
{% endif %}
<h3 id="page-info">Page Info</h3>
<div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(2, 0.5fr);">
<div class="backlink-box">
<a class="internal-link"
href="{{ site.github.repository_url }}/commits/develop/{{ page.relative_path }}">View page revision history</a></div>
<div class="backlink-box">
<a class="internal-link"
href="{{ site.github.repository_url }}/blob/develop/{{ page.relative_path }}">View page source</a></div>
</div>
</aside>{% comment %}{% endcomment %}
</section>
<footer class="page__meta">
{% if site.data.ui-text[site.locale].meta_label %}
<h4 class="page__meta-title">{{ site.data.ui-text[site.locale].meta_label }}</h4>
{% endif %}
{% include article_author.html %}
{% include page__taxonomy.html %}
{% include page__date.html %}
</footer>

{% if page.share %}{% include social-share.html %}{% endif %}
{% include post_pagination.html %}
</div>
{% if jekyll.environment == 'production' and site.comments.provider and page.comments %}
{% include comments.html %}
{% endif %}
</article>

<!-- {% if page.id and page.related and site.related_posts.size > 0 %} -->
<div class="page__related">
<h2 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h2>
<div class="grid__wrapper">
{% assign maxRelated = 3 %}
{% assign minCommonTags = 1 %}
{% assign maxRelatedCounter = 0 %}

{% for post in site.posts %}

{% assign sameTagCount = 0 %}
{% assign commonTags = '' %}

{% if post.tags != empty %}
{% for tag in post.tags %}
{% if post.url != page.url %}
{% if page.tags contains tag %}
{% assign sameTagCount = sameTagCount | plus: 1 %}
<!--
{% capture tagmarkup %} {{ tag }} {% endcapture %}
{% assign commonTags = commonTags | append: tagmarkup %} -->
{% endif %}
{% endif %}
{% endfor %}

{% if sameTagCount >= minCommonTags %}
<div class="grid__item">
{% include related-single-tags.html %}
<!--<h3><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h3>
{{ commonTags }}<br />
{{ post.date }}<br />
{{ post.excerpt }}-->
{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
{% if maxRelatedCounter >= maxRelated %}
{% break %}
{% endif %}
</div>
{% endif %}
{% endif %}

{% if post.tags == empty %}
{% for category in post.categories %}
{% if post.url != page.url %}
{% if page.categories contains category %}
{% assign sameTagCount = sameTagCount | plus: 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% if sameTagCount >= minCommonTags %}
<div class="grid__item">
{% include related-single-categories.html %}
{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
{% if maxRelatedCounter >= maxRelated %}
{% break %}
{% endif %}
</div>
{% endif %}

{% endif %}
{% endfor %}
</div>
</div>
<!--
{% if maxRelatedCounter == 0 %}
{% if page.id and page.related and site.related_posts.size > 0 %}
{% for post in site.related_posts limit:3 %} {% comment %} default was limit:4 {% endcomment %}
{% include archive-single.html type="grid" %}
{% endfor %}
{% elsif page.id and page.related %}
{% for post in site.posts limit:3 %} {% comment %} default was limit:4 {% endcomment %}
{% if post.id == page.id %}
{% continue %}
{% endif %}
{% include archive-single.html type="grid" %}
{% endfor %}
{% endif %}
</div>
-->
</div>
</div>
<!-- {% endif %}-->

{% endif %}
</div>






Loading

0 comments on commit 15e2381

Please sign in to comment.