From 0e7b292bb150f2e1403e0c985cc743abaff19eec Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 6 Jul 2022 01:41:27 +0100 Subject: [PATCH] docs: serve GitHub avatars locally --- .docs/.eleventy.js | 13 +++++--- .docs/_includes/theme.njk | 4 +-- .docs/lib/FileFetcher.js | 65 +++++++++++++++++++++++++++++++++++++++ .docs/lib/HTMLPicture.js | 2 +- 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 .docs/lib/FileFetcher.js diff --git a/.docs/.eleventy.js b/.docs/.eleventy.js index 078b027..ae743a6 100644 --- a/.docs/.eleventy.js +++ b/.docs/.eleventy.js @@ -11,8 +11,12 @@ const CleanCSS = require("clean-css"); const { minify: minify_html } = require("html-minifier-terser"); const HTMLPicture = require("./lib/HTMLPicture.js"); +const FileFetcher = require("./lib/FileFetcher.js"); + +const file_fetcher = new FileFetcher(); const is_production = typeof process.env.NODE_ENV === "string" && process.env.NODE_ENV === "production"; + var nextid = 0; const image_filename_format = (_id, src, width, format, _options) => { @@ -63,10 +67,6 @@ async function shortcode_gallerybox(content, src, idthis, idprev, idnext) { } async function fetch(url) { - const pkg_obj = JSON.parse(await fs.promises.readFile( - path.join(__dirname, "package.json"), "utf8" - )); - return (await phin({ url, headers: { @@ -77,6 +77,10 @@ async function fetch(url) { })).body; } +function fetch_file(url) { + return file_fetcher.fetch_file(url); +} + function do_minifycss(source, output_path) { if(!output_path.endsWith(".css") || !is_production) return source; @@ -122,6 +126,7 @@ module.exports = function(eleventyConfig) { eleventyConfig.addPassthroughCopy("img2brush/img2brush.js"); eleventyConfig.addAsyncShortcode("fetch", fetch); + eleventyConfig.addFilter("fetch_file", fetch_file); // eleventyConfig.addPassthroughCopy("images"); // eleventyConfig.addPassthroughCopy("css"); diff --git a/.docs/_includes/theme.njk b/.docs/_includes/theme.njk index bb55385..b387d0a 100644 --- a/.docs/_includes/theme.njk +++ b/.docs/_includes/theme.njk @@ -45,11 +45,11 @@ {{ content | safe }}