Skip to content

Commit

Permalink
Merge pull request #357 from photogabble/feature/355-add-series-links
Browse files Browse the repository at this point in the history
Add series links for notes that belong to one
  • Loading branch information
carbontwelve authored Oct 3, 2024
2 parents 51d13c6 + c2d3fbb commit 63c8e83
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const topics = (collection) => {
carry.set(`list/${(post.data?.list_slug ?? post.fileSlug)}`, post);
break;
case 'series':
carry.set(`series/${post.fileSlug}`, post);
carry.set(post.data?.sidebar_topic ?? `series/${post.fileSlug}`, post);
break;
case 'index':
(post.data?.topic || post.data?.sidebar_topic || post.data?.sidebar_resource) &&
Expand Down
15 changes: 15 additions & 0 deletions lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ export const includesTag = memoize(
{cacheKey: arguments_ => `${arguments_[0].join(',')}_${arguments_[1]}`}
);

/**
* Check if a given tag list contains a special tag.
*
* @param tags {Array<string>}
* @param slug {string}
* @returns {boolean}
*/
export const includesSpecialTag = memoize(
(tags, slug) => tags.find(tag => tag.toLowerCase().startsWith(slug.toLowerCase())) !== undefined,
{cacheKey: arguments_ => `${arguments_[0].join(',')}_${arguments_[1]}`}
)

/**
* Excludes special tags matching key. If key is empty then it excludes all special tags.
*
Expand Down Expand Up @@ -919,6 +931,9 @@ export const registerFilters = (eleventyConfig) => {
eleventyConfig.addFilter('includesTag', includesTag);
eleventyConfig.addFilter('excerpt', excerpt);

// This is used by page.njk for displaying the series sidebar component
eleventyConfig.addFilter('includesSpecialTag', includesSpecialTag);

// Used for debugging
eleventyConfig.addFilter('debug', debug);
eleventyConfig.addFilter('json', json);
Expand Down
16 changes: 16 additions & 0 deletions src/_includes/components/side-bars/series.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% set seriesId = tags | specialTagValue('series') %}
{% set seriesMeta = collections.topics | whereKeyEquals('topic', 'series/' + seriesId) | first %}

<section class="post-list">
<header class="post-list__inline-header">
<h3>{{ seriesMeta.name }}</h3> {{ seriesMeta.items.length }} {% if seriesMeta.items.length > 1 %}items{% else %}item{% endif %}
</header>
<ol class="post-list__chronological">
{%- for post in seriesMeta.items -%}
{% include "components/post-list-line.njk" %}
{%- endfor -%}
</ol>
<footer>
<nav><a href="{{ seriesMeta.permalink }}">{{ seriesMeta.name }} Overview</a> | <a href="/series/">All Series</a></nav>
</footer>
</section>
3 changes: 3 additions & 0 deletions src/_includes/layouts/page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
{% endblock %}

{% block sidebar %}
{% if tags | includesSpecialTag('series') %}
{% include 'components/side-bars/series.njk' %}
{% endif %}
{% if sidebar_component %}
{% set sidebar_component_include = 'components/side-bars/' + sidebar_component + '.njk' %}
{% include sidebar_component_include %}
Expand Down

0 comments on commit 63c8e83

Please sign in to comment.