feat: tag authors of shared links on mastodon if possible

This commit is contained in:
Cory Dransfeldt 2024-07-04 15:11:43 -07:00
parent 8ea14491b9
commit 2d1cdc54f6
No known key found for this signature in database
7 changed files with 17 additions and 37 deletions

View file

@ -74,9 +74,18 @@ export const allContent = (collection) => {
const addContent = (items, icon, getTitle, getDate) => { const addContent = (items, icon, getTitle, getDate) => {
if (items) { if (items) {
items.forEach(item => { items.forEach(item => {
let attribution;
if (item?.['authors']?.['mastodon']) {
const mastoUrl = new URL(item['authors']['mastodon'])
attribution = `${mastoUrl.pathname.replace('/', '')}@${mastoUrl.host}`
} else if (!item?.['authors']?.['mastodon'] && item?.['authors']?.['name']) {
attribution = item['authors']['name']
}
const content = { const content = {
url: `${BASE_URL}${item['url']}`, url: `${BASE_URL}${item['url']}`,
title: `${icon}: ${getTitle(item)}${item?.['authors']?.['name'] ? ' via ' + item['authors']['name'] : ''}${item?.['tags']?.length > 0 ? ' ' + tagsToHashtags(item['tags']) : ''}` title: `${icon}: ${getTitle(item)}${attribution ? ' via ' + attribution : ''}${item?.['tags']?.length > 0 ? ' ' + tagsToHashtags(item['tags']) : ''}`
} }
if (item?.['link']) content['url'] = item?.['link'] if (item?.['link']) content['url'] = item?.['link']
if (item?.['slug']) content['url'] = new URL(item['slug'], BASE_URL).toString() if (item?.['slug']) content['url'] = new URL(item['slug'], BASE_URL).toString()

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.9.19", "version": "19.10.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.9.19", "version": "19.10.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.4.0", "@cdransf/api-text": "^1.4.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.9.19", "version": "19.10.0",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -28,7 +28,7 @@ const fetchAllLinks = async () => {
while (fetchMore) { while (fetchMore) {
const { data, error } = await supabase const { data, error } = await supabase
.from('links') .from('links')
.select('*, authors (name, url)') .select('*, authors (name, url, mastodon)')
.order('date', { ascending: false }) .order('date', { ascending: false })
.range(page * PAGE_SIZE, (page + 1) * PAGE_SIZE - 1) .range(page * PAGE_SIZE, (page + 1) * PAGE_SIZE - 1)

View file

@ -1,18 +0,0 @@
{%- assign entries = data | normalizeEntries -%}
{
"version": "https://jsonfeed.org/version/1",
"title": "{{ title }}",
"icon": "https://cdn.coryd.dev/assets/avatar.png",
"home_page_url": "{{ meta.url }}",
"feed_url": "{{ permalink | absoluteUrl: meta.url }}",
"items": [{% for entry in entries limit: 20 -%}
{
"id": "{{ entry.url | btoa }}",
"title": "{{ entry.title | replaceQuotes }}",
"url": "{{ entry.url }}",
"content_text": "{{ entry.excerpt | replaceQuotes }}",
"date_published": "{{ entry.date | stringToRFC822Date }}"
}{% if not forloop.last %},{% endif %}
{%- endfor %}
]
}

View file

@ -1,12 +0,0 @@
---
layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/all.json"
---
{% render "partials/feeds/json.liquid"
permalink:"/feeds/all.json"
title:"Cory Dransfeldt: all activity"
data:collections.allContent
updated:collections.allContent[0].date
site:site
%}

View file

@ -20,8 +20,6 @@ description: These are awesome blogs that I enjoy and you may enjoy too.
<td class="blog-roll-icons"> <td class="blog-roll-icons">
{%- if blog.rss_feed -%} {%- if blog.rss_feed -%}
<a href="{{ blog.rss_feed }}">{% tablericon "rss" "Subscribe via RSS" %}</a> <a href="{{ blog.rss_feed }}">{% tablericon "rss" "Subscribe via RSS" %}</a>
{%- else -%}
{%- endif -%} {%- endif -%}
{%- if blog.json_feed -%} {%- if blog.json_feed -%}
/ <a href="{{ blog.json_feed }}">{% tablericon "json" "Subscribe via JSON" %}</a> / <a href="{{ blog.json_feed }}">{% tablericon "json" "Subscribe via JSON" %}</a>
@ -29,6 +27,9 @@ description: These are awesome blogs that I enjoy and you may enjoy too.
{%- if blog.newsletter -%} {%- if blog.newsletter -%}
/ <a href="{{ blog.newsletter }}">{% tablericon "mail-plus" "Newsletter subscription" %}</a> / <a href="{{ blog.newsletter }}">{% tablericon "mail-plus" "Newsletter subscription" %}</a>
{%- endif -%} {%- endif -%}
{%- if blog.mastodon -%}
/ <a href="{{ blog.mastodon }}">{% tablericon "brand-mastodon" "Mastodon" %}</a>
{%- endif -%}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}