From 1be374c912f37fbcb8f3def46d032b842f565217 Mon Sep 17 00:00:00 2001 From: marleyrae Date: Wed, 21 Jun 2023 12:13:56 -0700 Subject: [PATCH] :sparkles: feat: Add noreferrer plugin --- .eleventy.js | 97 +++++++++++++++++++++++++---------------------- package-lock.json | 20 ++++++++++ package.json | 1 + 3 files changed, 72 insertions(+), 46 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index fc1606e..c8ad073 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,59 +1,64 @@ const esbuild = require('esbuild') module.exports = function (eleventyConfig) { - // Process SCSS - eleventyConfig.addPlugin(require('eleventy-sass'), { - postcss: require('postcss')([ - require('postcss-preset-env'), - require('cssnano'), - ]), - }) + // Process SCSS + eleventyConfig.addPlugin(require('eleventy-sass'), { + postcss: require('postcss')([ + require('postcss-preset-env'), + require('cssnano'), + ]), + }) - // Copy CSS assets - eleventyConfig.addPassthroughCopy('src/style/assets') + // Add noopener to links + eleventyConfig.addPlugin(require('eleventy-plugin-automatic-noopener'), { + noreferrer: true, + }) - // Copy collections & links - eleventyConfig.addPassthroughCopy('src/collections/images/**/*') - eleventyConfig.addPassthroughCopy('src/images') + // Copy CSS assets + eleventyConfig.addPassthroughCopy('src/style/assets') - // Process JS - eleventyConfig.addTemplateFormats('js') - eleventyConfig.addExtension('js', { - outputFileExtension: 'js', - compile: async (content, path) => { - if (path !== './src/js/main.js') { - return - } + // Copy collections & links + eleventyConfig.addPassthroughCopy('src/collections/images/**/*') + eleventyConfig.addPassthroughCopy('src/images') - return async () => { - const output = await esbuild.build({ - target: 'es2020', - entryPoints: [path], - minify: true, - bundle: true, - write: false, - }) + // Process JS + eleventyConfig.addTemplateFormats('js') + eleventyConfig.addExtension('js', { + outputFileExtension: 'js', + compile: async (content, path) => { + if (path !== './src/js/main.js') { + return + } - return output.outputFiles[0].text - } - }, - }) + return async () => { + const output = await esbuild.build({ + target: 'es2020', + entryPoints: [path], + minify: true, + bundle: true, + write: false, + }) - // Convert img filename to alt text - eleventyConfig.addFilter('toAlt', (text) => { - const basename = text.split('.') - return basename[0].replace(/-/g, ' ') - }) + return output.outputFiles[0].text + } + }, + }) - // Convert diary date path to slug - eleventyConfig.addFilter('datePathSlugify', (path) => { - const folders = path.split('/') - const file = folders.pop().split('.') - return `${folders[3]}/${folders[4]}/${file[0]}` - }) + // Convert img filename to alt text + eleventyConfig.addFilter('toAlt', (text) => { + const basename = text.split('.') + return basename[0].replace(/-/g, ' ') + }) - // RSS - eleventyConfig.addPlugin(require('@11ty/eleventy-plugin-rss')) + // Convert diary date path to slug + eleventyConfig.addFilter('datePathSlugify', (path) => { + const folders = path.split('/') + const file = folders.pop().split('.') + return `${folders[3]}/${folders[4]}/${file[0]}` + }) - return {dir: {input: 'src', output: 'dist'}} + // RSS + eleventyConfig.addPlugin(require('@11ty/eleventy-plugin-rss')) + + return {dir: {input: 'src', output: 'dist'}} } diff --git a/package-lock.json b/package-lock.json index 81d0094..6248bc0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@11ty/eleventy-plugin-vite": "^4.0.0", "alpinejs": "^3.12.2", + "eleventy-plugin-automatic-noopener": "^2.0.2", "eleventy-sass": "^2.2.1", "esbuild": "0.17.19" }, @@ -2587,6 +2588,25 @@ "integrity": "sha512-jdie3RiEgygvDTyS2sgjq71B36q2cDSBfPlwzUyuOrfYTNoYWyBxxjGJV/HAu3A2hB0Y+HesvCVkVAFoCKwCSw==", "dev": true }, + "node_modules/eleventy-plugin-automatic-noopener": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/eleventy-plugin-automatic-noopener/-/eleventy-plugin-automatic-noopener-2.0.2.tgz", + "integrity": "sha512-uMHHAG7SUwiuNTd1yPTe8ijIjyTghV9JVXJ/vOUdbu+r3O0aJJ3ARsKAz83GMdSFivrY4XOnenlCOXeovGNBQw==", + "dependencies": { + "posthtml": "^0.16.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "@11ty/eleventy": "*" + }, + "peerDependenciesMeta": { + "@11ty/eleventy": { + "optional": true + } + } + }, "node_modules/eleventy-sass": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/eleventy-sass/-/eleventy-sass-2.2.1.tgz", diff --git a/package.json b/package.json index a28fc7a..10a74d0 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dependencies": { "@11ty/eleventy-plugin-vite": "^4.0.0", "alpinejs": "^3.12.2", + "eleventy-plugin-automatic-noopener": "^2.0.2", "eleventy-sass": "^2.2.1", "esbuild": "0.17.19" }