Base site updates

Long finished but languishing due to breakdown. Should improve performance, images are now properly sized, serving the fonts directly rather than going via Google. Mostly commiting so I can attempt upgrade to 11ty 3.0 alpha
This commit is contained in:
Robert McGovern 2024-01-29 01:48:13 +00:00
parent e8915df1cc
commit 70ad2cec50
128 changed files with 1711 additions and 234 deletions

View File

@ -1,4 +1,6 @@
const { EleventyRenderPlugin } = require("@11ty/eleventy"); const { EleventyRenderPlugin } = require("@11ty/eleventy");
const Image = require("@11ty/eleventy-img");
const CleanCSS = require("clean-css");
module.exports = function (eleventyConfig) { module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("./src/css"); eleventyConfig.addPassthroughCopy("./src/css");
@ -27,9 +29,20 @@ module.exports = function (eleventyConfig) {
// "./src/assets/images": "img", // "./src/assets/images": "img",
//}); //});
// FILTERS
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
// PLUGINS // PLUGINS
eleventyConfig.addPlugin(EleventyRenderPlugin); eleventyConfig.addPlugin(EleventyRenderPlugin);
// SHORTCODES
// eleventyConfig.addShortcode("image", imageShortcode);
eleventyConfig.addAsyncShortcode("imageGen", officialImageShortcode);
eleventyConfig.addNunjucksShortcode("imageGenSync", imageShortcodeSync);
// eleventyConfig.addShortcode("imageGenSync", imageShortcodeSync);
// WATCH Targets // WATCH Targets
eleventyConfig.addWatchTarget("./src/css/"); eleventyConfig.addWatchTarget("./src/css/");
eleventyConfig.addWatchTarget("./src/js/"); eleventyConfig.addWatchTarget("./src/js/");
@ -51,3 +64,148 @@ module.exports = function (eleventyConfig) {
}, },
}; };
}; };
const imageShortcode = async (
src,
alt,
className = undefined,
widths = [400, 800, 1280],
formats = ["webp", "jpeg"],
sizes = "100vw"
) => {
const imageMetadata = await Image(src, {
widths: [...widths, null],
formats: [...formats, null],
outputDir: "_site/assets/images",
urlPath: "/assets/images",
});
const sourceHtmlString = Object.values(imageMetadata)
// Map each format to the source HTML markup
.map((images) => {
// The first entry is representative of all the others
// since they each have the same shape
const { sourceType } = images[0];
// Use our util from earlier to make our lives easier
const sourceAttributes = stringifyAttributes({
type: sourceType,
// srcset needs to be a comma-separated attribute
srcset: images.map((image) => image.srcset).join(", "),
sizes,
});
// Return one <source> per format
return `<source ${sourceAttributes}>`;
})
.join("\n");
const getLargestImage = (format) => {
const images = imageMetadata[format];
return images[images.length - 1];
};
const largestUnoptimizedImg = getLargestImage(formats[0]);
const imgAttributes = stringifyAttributes({
src: largestUnoptimizedImg.url,
width: largestUnoptimizedImg.width,
height: largestUnoptimizedImg.height,
alt,
loading: "lazy",
decoding: "async",
});
const imgHtmlString = `<img ${imgAttributes}>`;
const pictureAttributes = stringifyAttributes({
class: className,
});
const picture = `<picture ${pictureAttributes}>
${sourceHtmlString}
${imgHtmlString}
</picture>`;
return outdent`${picture}`;
};
async function officialImageShortcode(src, alt, sizes = "100vw") {
if (alt === undefined) {
// You bet we throw an error on missing alt (alt="" works okay)
throw new Error(`Missing \`alt\` on responsiveimage from: ${src}`);
}
if (src.startsWith("/screenshots")) {
src = "./src/" + src;
} else {
src = "./projects/" + src;
}
console.log("officalImage: " + src + " " + alt);
let metadata = await Image(src, {
widths: [300, 600],
formats: ["webp", "jpeg"],
outputDir: "www/assets/images",
urlPath: "/assets/images",
});
console.log(metadata);
let lowsrc = metadata.jpeg[0];
let highsrc = metadata.jpeg[metadata.jpeg.length - 1];
return `<picture>
${Object.values(metadata)
.map((imageFormat) => {
return ` <source type="${
imageFormat[0].sourceType
}" srcset="${imageFormat
.map((entry) => entry.srcset)
.join(", ")}" sizes="${sizes}">`;
})
.join("\n")}
<img
src="${lowsrc.url}"
width="${highsrc.width}"
height="${highsrc.height}"
alt="${alt}"
class="card__img"
loading="lazy"
decoding="async">
</picture>`;
}
function imageShortcodeSync(
src,
alt,
sizes = "100vw",
widths = [300, 600],
cls = "card__img"
) {
let options = {
widths: widths,
formats: ["webp", "jpeg"],
outputDir: "www/assets/images",
urlPath: "/assets/images",
};
if (src.startsWith("/screenshots")) {
src = "./src/" + src;
} else {
src = "./projects/" + src;
}
// console.log("Sync: " + src + " " + alt);
// generate images, while this is async we dont wait
Image(src, options);
let imageAttributes = {
class: cls,
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// get metadata even if the images are not fully generated yet
let metadata = Image.statsSync(src, options);
return Image.generateHTML(metadata, imageAttributes);
}

View File

@ -4,7 +4,7 @@
"path": "." "path": "."
}, },
{ {
"path": "projects/FrontendMentor/junior/advice-generator-app" "path": "projects/FrontendMentor/junior/github-user-search-app"
} }
], ],
"settings": {} "settings": {}

BIN
img/-GDlNpYJsa-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
img/-GDlNpYJsa-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
img/-GDlNpYJsa-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
img/-GDlNpYJsa-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
img/0L9tXGDkvS-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
img/0L9tXGDkvS-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
img/0L9tXGDkvS-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
img/0L9tXGDkvS-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
img/18bBNQYM0a-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
img/18bBNQYM0a-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
img/3mGaKudfsw-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
img/3mGaKudfsw-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
img/3mGaKudfsw-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
img/3mGaKudfsw-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
img/9XyMq4wHhK-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
img/9XyMq4wHhK-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
img/9XyMq4wHhK-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
img/9XyMq4wHhK-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
img/CN2rONAFGd-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
img/CN2rONAFGd-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

BIN
img/CN2rONAFGd-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
img/CN2rONAFGd-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
img/CSk6kdPY0L-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
img/CSk6kdPY0L-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
img/CSk6kdPY0L-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
img/CSk6kdPY0L-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
img/EFFiPHarKI-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

BIN
img/EFFiPHarKI-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
img/EFFiPHarKI-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
img/EFFiPHarKI-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
img/FTlvq5XQq1-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
img/FTlvq5XQq1-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
img/FTlvq5XQq1-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/FTlvq5XQq1-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
img/FoyNi6n-SR-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

BIN
img/FoyNi6n-SR-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
img/FoyNi6n-SR-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
img/FoyNi6n-SR-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
img/J8rXKPqjPJ-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
img/J8rXKPqjPJ-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
img/J8rXKPqjPJ-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
img/J8rXKPqjPJ-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
img/TYZo-9aMi_-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
img/TYZo-9aMi_-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

BIN
img/TYZo-9aMi_-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
img/TYZo-9aMi_-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
img/TriYrdNdmt-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

BIN
img/TriYrdNdmt-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
img/TriYrdNdmt-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
img/TriYrdNdmt-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
img/Vt4nnRg26J-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
img/Vt4nnRg26J-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
img/Vt4nnRg26J-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
img/Vt4nnRg26J-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
img/YPeEHuhRyc-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/YPeEHuhRyc-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
img/YPeEHuhRyc-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

BIN
img/YPeEHuhRyc-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
img/_1zC5lgFEf-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
img/_1zC5lgFEf-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
img/_1zC5lgFEf-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
img/_1zC5lgFEf-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
img/_h_p4_FxkY-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
img/_h_p4_FxkY-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
img/_h_p4_FxkY-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
img/_h_p4_FxkY-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
img/bppR0Qo4dI-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
img/bppR0Qo4dI-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
img/bppR0Qo4dI-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
img/bppR0Qo4dI-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
img/c0IpQyrzrR-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
img/c0IpQyrzrR-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
img/c0IpQyrzrR-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
img/c0IpQyrzrR-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
img/eoK82m3aZj-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
img/eoK82m3aZj-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
img/eoK82m3aZj-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
img/eoK82m3aZj-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
img/fmALBZEvTI-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
img/fmALBZEvTI-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
img/fmALBZEvTI-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
img/fmALBZEvTI-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
img/giHRtCkFsQ-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
img/giHRtCkFsQ-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
img/giHRtCkFsQ-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
img/giHRtCkFsQ-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
img/l136akLARZ-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/l136akLARZ-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
img/l136akLARZ-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
img/l136akLARZ-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
img/o5E-35AO-3-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
img/o5E-35AO-3-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
img/o5E-35AO-3-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/o5E-35AO-3-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
img/pQs4tP6-Bb-300.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
img/pQs4tP6-Bb-300.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
img/pQs4tP6-Bb-600.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
img/pQs4tP6-Bb-600.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Some files were not shown because too many files have changed in this diff Show More