diff --git a/.eleventy.js b/.eleventy.js index 9d9f8566..7ef2a30a 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -10,6 +10,8 @@ const markdownItAnchor = require('markdown-it-anchor') const markdownItFootnote = require('markdown-it-footnote') const filters = require('./config/filters/index.js') +const { slugifyString } = require('./config/utils') +const { svgToJpeg } = require('./config/events/index.js') const CleanCSS = require('clean-css') const { execSync } = require('child_process') @@ -128,10 +130,13 @@ module.exports = function (eleventyConfig) { eleventyConfig.addLiquidFilter('dateToRfc822', pluginRss.dateToRfc822) eleventyConfig.addLiquidFilter('absoluteUrl', pluginRss.absoluteUrl) eleventyConfig.addFilter('cssmin', (code) => new CleanCSS({}).minify(code).styles) + eleventyConfig.addFilter('slugify', slugifyString) // shortcodes eleventyConfig.addShortcode('image', img) + // events + eleventyConfig.on('afterBuild', svgToJpeg) eleventyConfig.on('eleventy.after', () => { execSync(`npx pagefind --site _site --glob "**/*.html"`, { encoding: 'utf-8' }) }) diff --git a/config/events/index.js b/config/events/index.js new file mode 100644 index 00000000..b959ff1f --- /dev/null +++ b/config/events/index.js @@ -0,0 +1,29 @@ +const fs = require('fs') +const Image = require('@11ty/eleventy-img') + +const svgToJpeg = function () { + const socialPreviewImagesDir = '_site/assets/img/social-preview/' + fs.readdir(socialPreviewImagesDir, (err, files) => { + if (!!files && files.length > 0) { + files.forEach((fileName) => { + if (fileName.endsWith('.svg')) { + let imageUrl = socialPreviewImagesDir + fileName + Image(imageUrl, { + formats: ['jpeg'], + outputDir: './' + socialPreviewImagesDir, + filenameFormat: function (id, src, width, format) { + let outputFileName = fileName.substring(0, fileName.length - 4) + return `${outputFileName}.${format}` + }, + }) + } + }) + } else { + console.log('⚠ No social images found') + } + }) +} + +module.exports = { + svgToJpeg, +} diff --git a/config/filters/index.js b/config/filters/index.js index ad266c5e..c77cc5d9 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -20,6 +20,17 @@ module.exports = { const replacement = '&' return string.replace(pattern, replacement) }, + splitlines: (input, maxCharLength) => { + const parts = input.split(' ') + const lines = parts.reduce(function (acc, cur) { + if (!acc.length) return [cur] + let lastOne = acc[acc.length - 1] + if (lastOne.length + cur.length > maxCharLength) return [...acc, cur] + acc[acc.length - 1] = lastOne + ' ' + cur + return acc + }, []) + return lines + }, stripUtm: (string) => { if (!string) return return string.replace(utmPattern, '') @@ -99,9 +110,15 @@ module.exports = { readableDate: (date) => { return DateTime.fromISO(date).toFormat('LLLL d, yyyy') }, + dateToReadableDate: (date) => { + return new Date(date) + .toLocaleString('en-US', { + timeZone: 'America/Los_Angeles', + }) + .split(',')[0] + }, toDateTime: (date) => { const formatted = DateTime.fromISO(date) - const trail = (number) => { return parseInt(number, 10) < 10 ? `0${number}` : number } diff --git a/config/utils/index.js b/config/utils/index.js new file mode 100644 index 00000000..edd9142d --- /dev/null +++ b/config/utils/index.js @@ -0,0 +1,13 @@ +const slugify = require('slugify') + +const slugifyString = (str) => { + return slugify(str, { + replacement: '-', + remove: /[#,&,+()$~%.'":*?<>{}]/g, + lower: true, + }) +} + +module.exports = { + slugifyString, +} diff --git a/package-lock.json b/package-lock.json index 52fe2cbb..8df9f5ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,6 +52,7 @@ "prettier": "^3.1.1", "prettier-plugin-tailwindcss": "^0.5.9", "sanitize-html": "^2.11.0", + "slugify": "^1.6.6", "striptags": "^3.2.0", "tailwind-scrollbar": "^3.0.5", "tailwindcss": "^3.3.6" diff --git a/package.json b/package.json index a97d37d6..0c23ef73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "2.6.0", + "version": "2.7.0", "description": "The source for my personal site, blog and portfolio. Built using 11ty and hosted on Netlify.", "main": "index.html", "scripts": { @@ -61,6 +61,7 @@ "prettier": "^3.1.1", "prettier-plugin-tailwindcss": "^0.5.9", "sanitize-html": "^2.11.0", + "slugify": "^1.6.6", "striptags": "^3.2.0", "tailwind-scrollbar": "^3.0.5", "tailwindcss": "^3.3.6" diff --git a/src/_includes/base.liquid b/src/_includes/base.liquid index 48be4953..597f1255 100644 --- a/src/_includes/base.liquid +++ b/src/_includes/base.liquid @@ -12,6 +12,12 @@ + diff --git a/src/posts/2013/arcade-fire-reflektor-999.md b/src/posts/2013/arcade-fire-reflektor-999.md index a880615e..5c2a7ee6 100644 --- a/src/posts/2013/arcade-fire-reflektor-999.md +++ b/src/posts/2013/arcade-fire-reflektor-999.md @@ -1,6 +1,6 @@ --- date: '2013-09-04' -title: 'Arcade Fire - Reflektor 9/9/9' +title: 'Arcade Fire - Reflektor' description: "This sample sounds promising. I can't wait to hear more from Reflektor on the 9th." draft: false tags: ['music'] diff --git a/src/posts/2017/installing-http2-ubuntu-16.04.md b/src/posts/2017/installing-http2-ubuntu-16.04.md index 4bed9003..1994e5f3 100644 --- a/src/posts/2017/installing-http2-ubuntu-16.04.md +++ b/src/posts/2017/installing-http2-ubuntu-16.04.md @@ -1,6 +1,6 @@ --- date: '2017-03-19' -title: 'Installing HTTP/2 on Ubuntu 16.04 with virtual hosts' +title: 'Installing HTTP2 on Ubuntu 16.04 with virtual hosts' description: "Now that HTTP/2 is fairly stable and widely available, I decided to try and install and run it on this server. I'm currently running the Ubuntu 16.04.2 LTS with virtual hosts configured, so I can serve a number of sites beyond this one. All the sites this server hosts are also served securely using certificates from LetsEncrypt." draft: false tags: ['Apache', 'development'] diff --git a/src/posts/2018/att-buying-web-based-ad-targeting-post.md b/src/posts/2018/att-buying-web-based-ad-targeting-post.md deleted file mode 100644 index 68c4c1de..00000000 --- a/src/posts/2018/att-buying-web-based-ad-targeting-post.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -date: '2018-06-25' -title: 'AT&T buying web-based ad targeting company' -description: "AT&T controlling your internet connection, the media you use it to consume and the means to target ads at you based on those habits is truly a nightmare." -draft: false -tags: ['net neutrality', 'privacy'] ---- - -AT&T controlling your internet connection, the media you use it to consume and the means to target ads at you based on those habits is truly a nightmare. - -Run an adblocker. Run a VPN. Skip as much of their media as you can. - -_[Via Ars Technica:](https://arstechnica.com/?p=1336343)_ diff --git a/src/posts/2018/att-ceo-criticizes-disparate-state-net-neutrality-regulations.md b/src/posts/2018/att-ceo-criticizes-disparate-state-net-neutrality-regulations.md deleted file mode 100644 index ebfd513e..00000000 --- a/src/posts/2018/att-ceo-criticizes-disparate-state-net-neutrality-regulations.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -date: '2018-11-13' -title: 'AT&T CEO criticizes disparate state net neutrality regulations after helping to dismantle unified, national rules' -description: 'AT&T CEO Randall Stephenson yesterday urged Congress to pass net neutrality and consumer data privacy laws that would prevent states from issuing their own stricter laws.' -draft: false -tags: ['politics', 'net neutrality'] ---- - -**[Jon Brodkin:](https://arstechnica.com/?p=1410725)** - -> "We've got a mess coming at us, literally states independently going out and designing their own privacy regulation," [Randall] Stephenson said. "How do you do business in a world where you have 50 different regulations and rules around privacy?" - -If Stephenson was actually concerned about the impact of a fractured regulatory landscape on his company, he could have left existing net neutrality rules in place. Rather he and other telecoms elected to force through a roughshod repeal of national rules without any consideration of public opinion or possible consequences. - -Any new national legislation backed by AT&T is likely to seriously disadvantage consumers and competitors and support net neutrality in name only. diff --git a/src/posts/2023/automating-and-overengineering-my-now-page.md b/src/posts/2023/automating-and-overengineering-my-now-page.md index b3f8c4ee..1c881cfb 100644 --- a/src/posts/2023/automating-and-overengineering-my-now-page.md +++ b/src/posts/2023/automating-and-overengineering-my-now-page.md @@ -1,6 +1,6 @@ --- date: '2023-02-06' -title: 'Automating (and probably overengineering) my /now page' +title: 'Automating (and probably overengineering) my now page' description: "omg.lol (where I point my domain) and host most of my site content recently launched support for /now pages." draft: false tags: ['automation', 'development', 'Next.js', 'JavaScript'] diff --git a/src/posts/2023/building-my-now-page-using-eleventy.md b/src/posts/2023/building-my-now-page-using-eleventy.md index 45a889d0..f6dae008 100644 --- a/src/posts/2023/building-my-now-page-using-eleventy.md +++ b/src/posts/2023/building-my-now-page-using-eleventy.md @@ -1,6 +1,6 @@ --- date: '2023-03-18' -title: 'Building my /now page using Eleventy' +title: 'Building my now page using Eleventy' description: "As part of my commitment to writing about things I've written in other frameworks in Eleventy, this is how I re-engineered my /now page in Eleventy." draft: false tags: ['Eleventy', 'JavaScript', 'Last.fm', 'Oku', 'Trakt', 'Letterboxd', 'API'] diff --git a/src/posts/2023/talk-building-now-page-with-11ty.md b/src/posts/2023/talk-building-now-page-with-11ty.md index dae735dd..9f152a23 100644 --- a/src/posts/2023/talk-building-now-page-with-11ty.md +++ b/src/posts/2023/talk-building-now-page-with-11ty.md @@ -1,6 +1,6 @@ --- date: '2023-04-24' -title: 'Talk: Building a /now page with Eleventy' +title: 'Talk: Building a now page with Eleventy' description: "My talk from the Eleventy meetup about building my now page (you even get to see how much I resemble my avatar)." draft: false tags: ['Eleventy', 'JavaScript', 'automation'] diff --git a/src/social-preview.liquid b/src/social-preview.liquid new file mode 100644 index 00000000..239ee60d --- /dev/null +++ b/src/social-preview.liquid @@ -0,0 +1,65 @@ +--- +pagination: + data: collections.posts + size: 1 + alias: preview +permalink: '/assets/img/social-preview/{{ preview.data.title | slugify }}-preview.svg' +eleventyExcludeFromCollections: true +--- + + + {% assign titleInLines = preview.data.title | splitlines: 36 %} + {% assign numberOfLines = titleInLines.length %} + {% if numberOfLines == 2 %} + {% assign verticalStartingPoint = 250 %} + {% elsif numberOfLines == 3 %} + {% assign verticalStartingPoint = 210 %} + {% elsif numberOfLines == 4 %} + {% assign verticalStartingPoint = 170 %} + {% elsif numberOfLines == 5 %} + {% assign verticalStartingPoint = 130 %} + {% else %} + {% assign verticalStartingPoint = 290 %} + {% endif %} + + + + + + + {{ preview.date | dateToReadableDate}} + + + + + + {% for line in titleInLines %} + {% capture spacing %}{{ forloop.index0 | times: 50 }}{% endcapture %} + + {{ line }} + + {% endfor %} + + + + + {{ meta.siteName }} • {{ meta.url | replace: "https://", "" | replace: "http://", "" }} + + \ No newline at end of file