diff --git a/.eleventy.js b/.eleventy.js index 1359374..d659e88 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -48,8 +48,6 @@ module.exports = function (eleventyConfig) { return str.split('/').map(part => encodeURI(part)).join('/') }); - // TODO: this appears to potentially be dependent on rendering order - // TODO: actually add to the post ui eleventyConfig.addFilter("related", function(obj) { const post = this.ctx; const posts = this.ctx.collections.posts.map(post => post.data); @@ -64,13 +62,14 @@ module.exports = function (eleventyConfig) { serializer: (doc) => [doc.title, doc.description], weights: [10, 10], })(post, posts).map(result => { + console.log(result.document); return { relative: result.relative + tagScore(post, result.document), document: result.document } }); - return results.filter(result => result.relative > 0.0).slice(0,3); + return results.filter(result => result.relative > 0.2).sort((a, b) => a.relative - b.relative).reverse().slice(0,3); }); eleventyConfig.addCollection('posts', collection => { diff --git a/src/_includes/layouts/post.njk b/src/_includes/layouts/post.njk index 01c1f6c..954a2c3 100644 --- a/src/_includes/layouts/post.njk +++ b/src/_includes/layouts/post.njk @@ -17,8 +17,8 @@ subhead: blog {{ content | timeToRead }} to read by {{ site.name }} - {% if tags %} + in {% for tag in tags %} {{ tag }}{% if not loop.last %}, {% endif %} @@ -47,4 +47,35 @@ subhead: blog + {% for rel in "" | related %} + {% if loop.first %} + {% endif %} + {% endfor %} {% endblock %} diff --git a/src/css/style.scss b/src/css/style.scss index 755037c..9d579ec 100644 --- a/src/css/style.scss +++ b/src/css/style.scss @@ -79,6 +79,26 @@ time, border-bottom: 1px dotted rgb(219, 103, 167); } +.related { + margin-top: 18px; + border-top: 1px dotted rgb(219, 103, 167); + + h3 { + margin-top: 4px; + margin-bottom: 0; + } + + ul { + margin-top: 4px; + padding-left: 0; + + h4 { + margin-top: 4px; + margin-bottom: 0; + } + } +} + .article_header>h1, .page_header>h1 { margin: 0.1rem; diff --git a/src/posts.njk b/src/posts.njk index 7941be5..2c8c6cd 100644 --- a/src/posts.njk +++ b/src/posts.njk @@ -22,8 +22,8 @@ permalink: /posts/{% if pagination.pageNumber > 0 %}page/{{ pagination.pageNumbe {{ entry.content | timeToRead }} to read by {{ site.name }} - {% if entry.data.tags %} + in {% for tag in entry.data.tags %} {{ tag }}{% if not loop.last %}, {% endif %} diff --git a/src/tagged.njk b/src/tagged.njk index a39a7c4..ca6c337 100644 --- a/src/tagged.njk +++ b/src/tagged.njk @@ -29,8 +29,8 @@ date: git Last Modified {% endif %} by {{ site.name }} - {% if entry.data.tags %} + in {% for tag in entry.data.tags %} {{ tag }}{% if not loop.last %}, {% endif %}