feat: Add noreferrer plugin

This commit is contained in:
marleyrae 2023-06-21 12:13:56 -07:00
parent 2074751fab
commit 1be374c912
3 changed files with 72 additions and 46 deletions

View file

@ -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'}}
}

20
package-lock.json generated
View file

@ -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",

View file

@ -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"
}