Skip to content

Instantly share code, notes, and snippets.

@zachleat
zachleat / gist:f100f71a8ad2bad57d65511290717f1c
Created September 7, 2020 21:42
Eleventy Benchmark September 7, 2020 (Eleventy 1.0 Alpha Build)
---------------------------------------------------------
Eleventy Benchmark (Node v14.9.0, 1000 templates each)
---------------------------------------------------------
Eleventy 0.10.0
---------------------------------------------------------
liquid: ... 3 runs
* Median: 1.02 seconds
* Median per template: 1 ms
njk: ... 3 runs
html {
scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}
}
@zachleat
zachleat / gist:8cd9f1844c7144099c54533fff1b0a76
Created April 18, 2020 04:17
Eleventy Vue Responsive Images Plugin Sample Input/Output
<responsive-image
path="./src/images/home-store.jpg"
alt="The front entrance to a store"
:widths="[350, null]" />
<!-- BECOMES -->
<picture>
<source srcset="/v3/img/respimg/ef7c5bc4-350.webp 350w, /v3/img/respimg/ef7c5bc4.webp 589w" type="image/webp">
<source srcset="/v3/img/respimg/ef7c5bc4-350.jpeg 350w, /v3/img/respimg/ef7c5bc4.jpeg 589w" type="image/jpeg">
@zachleat
zachleat / .eleventy.js
Last active March 21, 2020 02:11
Eleventy + Vue Preview
const eleventyVue = require("@11ty/eleventy-plugin-vue");
module.exports = function(eleventyConfig) {
// Use Defaults
eleventyConfig.addPlugin(eleventyVue);
// OR, Use your own options
eleventyConfig.addPlugin(eleventyVue, {
// Directory for single file components (defaults to includes folder)
componentsDirectory: "",
@zachleat
zachleat / .eleventy.js
Last active December 10, 2019 22:34 — forked from crtr0/talk.njk
module.exports = function(eleventyConfig) {
// you’ll have to get a list of all the tags in your talks.json here which is not great but pretty easy
["Web Assembly"].forEach(function(tag) {
eleventyConfig.addCollection(tag, function(collection) {
return collection.getFilteredByTag("talks").filter(item => {
// note here the use of the pagination alias `talk`
return (item.data.talk.tags || []).indexOf(tag) > -1;
});
});
});
@zachleat
zachleat / img.njk
Created September 5, 2019 13:37
Experimenting with a Nunjucks shortcode for images in Eleventy
<!-- throws an error, missing [alt] attribute -->
{% img src="img/9a93578a.png", loading="lazy" %}
<!-- local img source, outputs a standard <img> tag -->
{% img src="img/9a93578a.png", alt="zachleat’s Avatar", loading="lazy" %}
<!-- remote img source -->
<!-- download using avatar-local-cache, outputs <picture> with webp and png fallback -->
{% img src="https://www.gravatar.com/avatar/e1899004c71c7043343196103e210be3?default=404", alt="zachleat’s Avatar", loading="lazy" %}
@zachleat
zachleat / .js
Created August 29, 2019 16:43
Using Eleventy Programmatically
const Eleventy = require("@11ty/eleventy");
(async function() {
let inst = new Eleventy();
await inst.init();
await inst.write();
})();
@zachleat
zachleat / gist:cda7af65f5d61666e7fa6037c3ede752
Created June 12, 2019 13:35
This webmention entry made it through sanitize-html
{
"type": "entry",
"author": {
"type": "card",
"name": "",
"photo": "",
"url": ""
},
"url": "https://remysharp.com/2019/06/11/ejecting-disqus",
"published": "2019-06-11T00:00:00",
@zachleat
zachleat / font-sizes.js
Last active January 11, 2019 09:47
Returns a unique sorted array of font-size values on a page.
(function() {
let fontSizes = new Set();
document.querySelectorAll("*").forEach(function(node) {
fontSizes.add(window.getComputedStyle(node).getPropertyValue("font-size"));
});
return Array.from(fontSizes).sort();
})();
@zachleat
zachleat / gist:27e61d1a7dc25e6cab40241e05e0239c
Created May 23, 2018 18:23
Testing lettering sample code
;(function ($) {
function Lettering() {}
Lettering.prototype.splitText = function() {};
Lettering.prototype.injector = function() {};
window.LetteringJS = Lettering;
})(jQuery);