chore: drop webmentions

This commit is contained in:
Cory Dransfeldt 2024-02-10 20:23:04 -08:00
parent 6a8fa53478
commit fdcdb2e0ce
No known key found for this signature in database
11 changed files with 2 additions and 272 deletions

View file

@ -56,70 +56,6 @@ export default {
return tagMap[url] || ''
},
// webmentions
webmentionsByUrl: (webmentions, url) => {
if (!webmentions) return null;
const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']
const data = {
'like-of': [],
'repost-of': [],
'in-reply-to': [],
'mention-of': [],
'link-to': [],
}
const hasRequiredReplyFields = (entry) => {
const { author, published, content } = entry
return author.name && author.photo && published && content
}
const hasRequiredMentionFields = (entry) => {
const { name, url } = entry
return name && url
}
const filtered =
webmentions
.filter((entry) => entry['wm-target'] === `${BASE_URL}${url}`)
.filter((entry) => allowedTypes.includes(entry['wm-property'])) || []
filtered.forEach((m) => {
if (data[m['wm-property']]) {
const isReply = m['wm-property'] === 'in-reply-to'
const isMention = m['wm-property'] === 'mention-of'
const isValidReply = (isReply || isMention) && hasRequiredReplyFields(m)
if (isReply || isMention) {
if (isValidReply) {
m.sanitized = sanitizeHTML(m.content.html)
data[m['wm-property']].unshift(m)
}
if (isMention && hasRequiredMentionFields(m)) data['link-to'].push(m)
return
}
data[m['wm-property']].unshift(m)
}
})
data['in-reply-to'] = [...data['in-reply-to'], ...data['mention-of']]
data['in-reply-to'].sort((a, b) =>
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
},
webmentionsSanitizeComments: (comment) => {
return comment.replace(/\?\?\?\?/g, '');
},
// dates
readableDate: (date) => {
return DateTime.fromISO(date).toFormat('LLLL d, yyyy')

View file

@ -18,15 +18,6 @@ export const img = async (
sizes = '90vw',
formats = ['avif', 'webp', 'jpeg']
) => {
const isLocal = src?.includes('src/assets');
const imageExists = async () => {
try {
return await fetch(src, { method: 'HEAD' }).then((res) => res.ok);
} catch {
return false;
}
};
const generateImage = async () => {
const widths = [320, 570, 880, 1024, 1248];
const metadata = await Image(src, {
@ -70,7 +61,7 @@ export const img = async (
};
if (process.env.ELEVENTY_PRODUCTION) {
return isLocal ? await generateImage() : await imageExists().then(async (exists) => (exists ? await generateImage() : await generatePlaceholder()));
return await generateImage();
} else {
return await generatePlaceholder();
}