chore: consolidate filters

This commit is contained in:
Cory Dransfeldt 2024-05-05 15:08:55 -07:00
parent a7fa7379ad
commit 13b80c09cc
No known key found for this signature in database
6 changed files with 14 additions and 17 deletions

View file

@ -8,7 +8,6 @@ import markdownItFootnote from 'markdown-it-footnote'
import htmlmin from 'html-minifier-terser' import htmlmin from 'html-minifier-terser'
import filters from './config/filters/index.js' import filters from './config/filters/index.js'
import { slugifyString } from './config/utils/index.js'
import { minifyJsComponents } from './config/events/index.js' import { minifyJsComponents } from './config/events/index.js'
import { searchIndex, tagList, tagsSortedByCount, links, tagMap, booksToRead } from './config/collections/index.js' import { searchIndex, tagList, tagsSortedByCount, links, tagMap, booksToRead } from './config/collections/index.js'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
@ -97,10 +96,10 @@ export default async function (eleventyConfig) {
if (!content) return if (!content) return
return md.render(content) return md.render(content)
}) })
Object.keys(filters).forEach((filterName) => { Object.keys(filters).forEach((filterName) => {
eleventyConfig.addLiquidFilter(filterName, filters[filterName]) eleventyConfig.addLiquidFilter(filterName, filters[filterName])
}) })
eleventyConfig.addFilter('slugify', slugifyString)
// shortcodes // shortcodes
eleventyConfig.addShortcode('appVersion', () => appVersion) eleventyConfig.addShortcode('appVersion', () => appVersion)

View file

@ -1,6 +1,7 @@
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import markdownIt from 'markdown-it'
import { URL } from 'url' import { URL } from 'url'
import slugify from 'slugify'
import markdownIt from 'markdown-it'
import sanitizeHtml from 'sanitize-html'; import sanitizeHtml from 'sanitize-html';
import authors from '../data/author-map.js' import authors from '../data/author-map.js'
@ -23,6 +24,13 @@ export default {
return string.replace(utmPattern, '') return string.replace(utmPattern, '')
}, },
replaceQuotes: (string) => string.replace(/"/g, "'"), replaceQuotes: (string) => string.replace(/"/g, "'"),
slugifyString: (str) => {
return slugify(str, {
replacement: '-',
remove: /[#,&,+()$~%.'":*?<>{}]/g,
lower: true,
})
},
// navigation // navigation
isLinkActive: (category, page) => { isLinkActive: (category, page) => {
@ -45,7 +53,6 @@ export default {
return visitors(b) - visitors(a) return visitors(b) - visitors(a)
}) })
}, },
tagLookup: (url, tagMap) => { tagLookup: (url, tagMap) => {
if (!url) return if (!url) return
if (url.includes('openlibrary.org')) return `#Books #NowReading ${tagMap[url]}`.trim() if (url.includes('openlibrary.org')) return `#Books #NowReading ${tagMap[url]}`.trim()

View file

@ -1,9 +0,0 @@
import slugify from 'slugify'
export const slugifyString = (str) => {
return slugify(str, {
replacement: '-',
remove: /[#,&,+()$~%.'":*?<>{}]/g,
lower: true,
})
}

4
package-lock.json generated
View file

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

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "13.7.1", "version": "13.7.2",
"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

@ -25,7 +25,7 @@
<meta property="og:url" content="{{ fullUrl }}" /> <meta property="og:url" content="{{ fullUrl }}" />
<meta <meta
property="og:image" property="og:image"
content="{%- if schema == 'blog' %}{{ meta.url }}/assets/img/ogi/{{ title | slugify }}-preview.png{%- else -%}{{ meta.meta_data.opengraph_default }}{% endif -%}" content="{%- if schema == 'blog' %}{{ meta.url }}/assets/img/ogi/{{ title | slugifyString }}-preview.png{%- else -%}{{ meta.meta_data.opengraph_default }}{% endif -%}"
/> />
<meta name="theme-color" content="{{ meta.themeColor }}" /> <meta name="theme-color" content="{{ meta.themeColor }}" />
<meta name="generator" content="Eleventy"> <meta name="generator" content="Eleventy">