Skip to content

Commit

Permalink
Merge pull request #11 from etchteam/release/v2
Browse files Browse the repository at this point in the history
Release v2
  • Loading branch information
gavmck authored Oct 14, 2024
2 parents c75087e + d18490c commit f4df641
Show file tree
Hide file tree
Showing 105 changed files with 8,721 additions and 2,859 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Build
run: npm run build
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no-install -- lint-staged
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.11.1
20.12.2
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": "explicit"
}
}
Empty file removed dist/.gitkeep
Empty file.
72 changes: 72 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import browserslist from 'browserslist';
import { transform, browserslistToTargets } from 'lightningcss';
import markdownIt from 'markdown-it';
import { eleventyImagePlugin } from '@11ty/eleventy-img';
import webc from '@11ty/eleventy-plugin-webc';
import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import renderSvg from './lib/renderSvg.js';
import findCollectionItem from './lib/findCollectionItem.js';

async function transformCSS(content) {
if (this.type !== 'css') {
return content;
}

const targets = browserslistToTargets(browserslist('> 0.25% and not dead'));
const { code } = transform({
code: Buffer.from(content),
minify: true,
sourceMap: false,
targets,
});

return code;
}

export default function(eleventyConfig) {
// copy the assets folder to the output directory
eleventyConfig.addPassthroughCopy('src/assets');
// Reloading on css changes
eleventyConfig.addWatchTarget('src/styles/*.css');
// make functions available globally in templates
eleventyConfig.addJavaScriptFunction('renderSvg', renderSvg);
eleventyConfig.addJavaScriptFunction('findCollectionItem', findCollectionItem);
// support eleventy-image https://www.11ty.dev/docs/plugins/image
eleventyConfig.addPlugin(eleventyImagePlugin, {
formats: ['webp'],
widths: [800, 1600],
urlPath: '/assets/images/',
defaultAttributes: {
sizes: '100vw',
loading: 'lazy',
},
});
// load all components added to the src/components directory
eleventyConfig.addPlugin(webc, {
components: [
'src/components/**/*.webc',
'npm:@11ty/eleventy-img/*.webc',
],
bundlePluginOptions: {
transforms: [transformCSS],
},
});
// Support markdown templates in webc using <template webc:type="11ty" 11ty:type="md">
eleventyConfig.setLibrary('md', markdownIt({
html: true,
breaks: true,
linkify: true,
}));
// add syntax highlighting to code blocks
eleventyConfig.addPlugin(syntaxHighlight);

return {
dir: {
layouts: 'layouts',
includes: 'components',
data: 'data',
input: 'src',
output: 'dist'
}
}
};
9 changes: 9 additions & 0 deletions lib/findCollectionItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Find an item within a collection by it’s url
* @param {Array} collection the collection to search
* @param {String} url the url of the item to search for
* @returns A collection item or undefined
*/
export default function findCollectionItem(collection = [], url = '') {
return collection.find(post => post.url === url);
}
40 changes: 40 additions & 0 deletions lib/renderSvg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Image from '@11ty/eleventy-img';
import { optimize } from 'svgo';

function addAttributes(svgString, attributes) {
const attributesString = attributes
.map(({ name, value }) => `${name}="${value}"`)
.join(' ');

return svgString.replace('<svg', `<svg ${attributesString}`);
}

/**
* Get an SVG string from a file using @11ty/eleventy-img and compress it with svgo
*
* @param {String} path svg file to load, relative to the root directory
* @param {Array<{ name, value }>} attributes additional attributes to add to the SVG tag
*/
export default async function renderSvg(path, attributes = []) {
const metadata = await Image(path, {
formats: ['svg'],
dryRun: true, // Don’t write to the file system
});

const svgString = addAttributes(metadata.svg[0].buffer.toString(), attributes);

const result = optimize(svgString, {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
],
});

return result.data;
}
1 change: 1 addition & 0 deletions lint-staged.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { '*.css': 'stylelint --fix' };
Loading

0 comments on commit f4df641

Please sign in to comment.