upgrade to 3.0
This commit is contained in:
@@ -23,6 +23,65 @@ export default function(eleventyConfig) {
|
||||
return array.slice(0, n);
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('mentionsForUrl', (webmentions, url) => {
|
||||
const allowedTypes = ['in-reply-to', 'mention-of']
|
||||
|
||||
const allowedHTML = {
|
||||
allowedTags: ['b', 'i', 'em', 'strong', 'a'],
|
||||
allowedAttributes: {
|
||||
a: ['href']
|
||||
}
|
||||
}
|
||||
|
||||
const clean = (entry) => {
|
||||
const { html, text } = entry.content
|
||||
if (html) {
|
||||
entry.content.value = sanitizeHTML(text, allowedHTML)
|
||||
};
|
||||
return entry;
|
||||
}
|
||||
|
||||
// sort webmentions by published timestamp chronologically.
|
||||
// swap a.published and b.published to reverse order.
|
||||
const orderByDate = (a, b) => new Date(b.published) - new Date(a.published)
|
||||
|
||||
// only allow webmentions that have an author name and a timestamp
|
||||
const checkRequiredFields = (entry) => {
|
||||
const { author, published } = entry
|
||||
return !!author && !!author.name && !!published
|
||||
}
|
||||
|
||||
return webmentions
|
||||
.filter((entry) => entry['wm-target'] === url)
|
||||
.filter((entry) => allowedTypes.includes(entry['wm-property']))
|
||||
.filter(checkRequiredFields)
|
||||
.sort(orderByDate)
|
||||
.map(clean)
|
||||
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('likesForUrl', (webmentions, url) => {
|
||||
const allowedTypes = ['like-of']
|
||||
return webmentions
|
||||
.filter((entry) => entry['wm-target'] === url)
|
||||
.filter((entry) => allowedTypes.includes(entry['wm-property']))
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('repostsForUrl', (webmentions, url) => {
|
||||
const allowedTypes = ['repost-of']
|
||||
return webmentions
|
||||
.filter((entry) => entry['wm-target'] === url)
|
||||
.filter((entry) => allowedTypes.includes(entry['wm-property']))
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('size', (mentions) => {
|
||||
return !mentions ? 0 : mentions.length
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('webmentionsByType', (mentions, mentionType) => {
|
||||
return mentions.filter(entry => !!entry['mentionType'])
|
||||
});
|
||||
|
||||
// Return the smallest number argument
|
||||
eleventyConfig.addFilter("min", (...numbers) => {
|
||||
return Math.min.apply(null, numbers);
|
||||
|
||||
Reference in New Issue
Block a user