diff --git a/.eleventy.js b/.eleventy.js
index 40e03275..9da8e941 100644
--- a/.eleventy.js
+++ b/.eleventy.js
@@ -1,63 +1,69 @@
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
+const filters = require('./config/filters.js')
-module.exports = function(eleventyConfig) {
- // Plugins
- eleventyConfig.addPlugin(syntaxHighlight)
-
- // To enable merging of tags
- eleventyConfig.setDataDeepMerge(true)
+module.exports = function (eleventyConfig) {
+ // Plugins
+ eleventyConfig.addPlugin(syntaxHighlight)
- // Copy these static files to _site folder
- eleventyConfig.addPassthroughCopy('src/assets')
- eleventyConfig.addPassthroughCopy('src/manifest.json')
-
- // To create excerpts
- eleventyConfig.setFrontMatterParsingOptions({
- excerpt: true,
- excerpt_alias: 'post_excerpt',
- excerpt_separator: ''
- })
-
- // To create a filter to determine duration of post
- eleventyConfig.addFilter('readTime', (value) => {
- const content = value
- const textOnly = content.replace(/(<([^>]+)>)/gi, '')
- const readingSpeedPerMin = 450
- return Math.max(1, Math.floor(textOnly.length / readingSpeedPerMin))
- })
-
- // Enable us to iterate over all the tags, excluding posts and all
- eleventyConfig.addCollection('tagList', collection => {
- const tagsSet = new Set()
- collection.getAll().forEach(item => {
- if (!item.data.tags) return
- item.data.tags
- .filter(tag => !['posts', 'all'].includes(tag))
- .forEach(tag => tagsSet.add(tag))
+ // filters
+ Object.keys(filters).forEach((filterName) => {
+ eleventyConfig.addFilter(filterName, filters[filterName])
})
- return Array.from(tagsSet).sort()
- })
- const md = markdownIt({ html: true, linkify: true })
- md.use(markdownItAnchor, {
- level: [1, 2],
- permalink: markdownItAnchor.permalink.headerLink({
- safariReaderFix: true,
- class: 'header-anchor',
+ // To enable merging of tags
+ eleventyConfig.setDataDeepMerge(true)
+
+ // Copy these static files to _site folder
+ eleventyConfig.addPassthroughCopy('src/assets')
+ eleventyConfig.addPassthroughCopy('src/manifest.json')
+
+ // To create excerpts
+ eleventyConfig.setFrontMatterParsingOptions({
+ excerpt: true,
+ excerpt_alias: 'post_excerpt',
+ excerpt_separator: '',
})
- })
- eleventyConfig.setLibrary('md', md)
- // asset_img shortcode
- eleventyConfig.addLiquidShortcode('asset_img', (filename, alt) => {
- return ``
- })
+ // To create a filter to determine duration of post
+ eleventyConfig.addFilter('readTime', (value) => {
+ const content = value
+ const textOnly = content.replace(/(<([^>]+)>)/gi, '')
+ const readingSpeedPerMin = 450
+ return Math.max(1, Math.floor(textOnly.length / readingSpeedPerMin))
+ })
- return {
- dir: {
- input: 'src'
+ // Enable us to iterate over all the tags, excluding posts and all
+ eleventyConfig.addCollection('tagList', (collection) => {
+ const tagsSet = new Set()
+ collection.getAll().forEach((item) => {
+ if (!item.data.tags) return
+ item.data.tags
+ .filter((tag) => !['posts', 'all'].includes(tag))
+ .forEach((tag) => tagsSet.add(tag))
+ })
+ return Array.from(tagsSet).sort()
+ })
+
+ const md = markdownIt({ html: true, linkify: true })
+ md.use(markdownItAnchor, {
+ level: [1, 2],
+ permalink: markdownItAnchor.permalink.headerLink({
+ safariReaderFix: true,
+ class: 'header-anchor',
+ }),
+ })
+ eleventyConfig.setLibrary('md', md)
+
+ // asset_img shortcode
+ eleventyConfig.addLiquidShortcode('asset_img', (filename, alt) => {
+ return `
`
+ })
+
+ return {
+ dir: {
+ input: 'src',
+ },
}
- }
}
diff --git a/config/filters.js b/config/filters.js
new file mode 100644
index 00000000..cd12c47b
--- /dev/null
+++ b/config/filters.js
@@ -0,0 +1,62 @@
+const sanitizeHTML = require('sanitize-html')
+
+module.exports = {
+ trim: (string, limit) => {
+ return string.length <= limit ? string : `${string.slice(0, limit)}...`
+ },
+ postPath: (path) => {
+ if (path.includes('micro/')) return path
+ return `/micro/${path}`
+ },
+ stripIndex: (path) => {
+ return path.replace('/index.html', '/')
+ },
+ getFirstAttachment: (post) => {
+ if (post && post.attachments && post.attachments.length > 0) {
+ return post.attachments[0].url ? post.attachments[0].url : post.attachments[0]
+ }
+
+ return '/assets/img/social-card.png'
+ },
+ webmentionsByUrl: (webmentions, url) => {
+ const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']
+
+ const data = {
+ 'like-of': [],
+ 'repost-of': [],
+ 'in-reply-to': [],
+ }
+
+ const hasRequiredFields = (entry) => {
+ const { author, published, content } = entry
+ return author.name && published && content
+ }
+
+ const filtered = webmentions
+ .filter((entry) => entry['wm-target'] === `https://coryd.dev${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 isValidReply = isReply && hasRequiredFields(m)
+ if (isReply) {
+ if (isValidReply) {
+ m.sanitized = sanitizeHTML(m.content.html)
+ data[m['wm-property']].unshift(m)
+ }
+
+ return
+ }
+
+ data[m['wm-property']].unshift(m)
+ }
+ })
+
+ data['in-reply-to'].sort((a, b) =>
+ a.published > b.published ? 1 : b.published > a.published ? -1 : 0
+ )
+
+ return data
+ },
+}
diff --git a/package.json b/package.json
index 1dbb853c..1f23e8ae 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"postcss": "^8.4.5",
"prettier": "^2.8.4",
"prettier-plugin-tailwindcss": "^0.2.4",
+ "sanitize-html": "^2.10.0",
"vercel-submodules": "^1.0.10"
},
"dependencies": {
diff --git a/src/_includes/base.liquid b/src/_includes/base.liquid
index 72d7099e..a21bf412 100644
--- a/src/_includes/base.liquid
+++ b/src/_includes/base.liquid
@@ -1,10 +1,15 @@