From ccd2fbf05846a34fd1ada02d22d7ccbcd8fd0f50 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Mon, 1 Jan 2024 16:49:17 -0800 Subject: [PATCH] chore: return null and skip rendering webmentions container + extra border if there are no mentions --- config/filters/index.js | 9 +++++++++ package.json | 2 +- src/_includes/partials/webmentions/container.liquid | 6 +++--- src/assets/styles/index.css | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/filters/index.js b/config/filters/index.js index 05ede053..cfeb738a 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -56,6 +56,8 @@ export default { return tagMap[url] || '' }, webmentionsByUrl: (webmentions, url) => { + if (!webmentions) return null; + const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of'] const data = { 'like-of': [], @@ -103,6 +105,13 @@ export default { a.published > b.published ? 1 : b.published > a.published ? -1 : 0 ) + // delete empty keys + Object.keys(data).forEach((key) => { + if (data[key].length === 0) delete data[key] + }); + + if (!Object.keys(data).length) return null; + return data }, diff --git a/package.json b/package.json index 5ac68671..8a597c83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "4.1.0", + "version": "4.2.0", "description": "The source for my personal site, blog and portfolio. Built using 11ty and hosted on Netlify.", "type": "module", "scripts": { diff --git a/src/_includes/partials/webmentions/container.liquid b/src/_includes/partials/webmentions/container.liquid index ef7450f9..8a911b4a 100644 --- a/src/_includes/partials/webmentions/container.liquid +++ b/src/_includes/partials/webmentions/container.liquid @@ -1,9 +1,9 @@ -{% if webmentions %} +{% assign mentions = webmentions.mentions | webmentionsByUrl: page.url %} +{% if mentions %}
- {% assign mentions = webmentions.mentions | webmentionsByUrl: page.url %} {% render "partials/webmentions/interaction.liquid", mentions: mentions, type: 'repost-of' %} {% render "partials/webmentions/interaction.liquid", mentions: mentions, type: 'like-of' %} {% render "partials/webmentions/comments.liquid", mentions: mentions %} {% render "partials/webmentions/links.liquid", mentions: mentions %}
-{% endif %} +{% endif %} \ No newline at end of file diff --git a/src/assets/styles/index.css b/src/assets/styles/index.css index 7f949859..d0f5dd92 100644 --- a/src/assets/styles/index.css +++ b/src/assets/styles/index.css @@ -705,6 +705,7 @@ article .now__section--header { .webmentions__wrapper { border-top: 1px solid var(--gray-200); margin-top: 1.5rem; + margin-bottom: 3.25rem; padding-top: 2rem; } @@ -783,7 +784,7 @@ article .now__section--header { } .author__wrapper { - margin-top: 3rem; + margin-top: 1.5rem; padding: 3rem 0 1rem; border-top: 1px solid var(--gray-200); }