From 9dcee48717eee56e289b7ce73f0b554a4734bd29 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 9 Aug 2021 13:45:54 +0100 Subject: [PATCH] Fix bugs, and extract media --- src/.eleventy.js | 24 ++++++++++--- src/_includes/main.njk | 19 +++++----- src/favicon.png | Bin 0 -> 13656 bytes src/images/github.svg | 6 ++++ src/index.11tydata.js | 79 ++++++++++++++++++++++++++--------------- src/index.html | 9 ++--- 6 files changed, 91 insertions(+), 46 deletions(-) create mode 100644 src/favicon.png create mode 100644 src/images/github.svg diff --git a/src/.eleventy.js b/src/.eleventy.js index 82e332d..8dd31f2 100644 --- a/src/.eleventy.js +++ b/src/.eleventy.js @@ -4,13 +4,13 @@ const path = require("path"); const striptags = require("striptags"); const htmlentities = require("html-entities"); -const { SHA3 } = require("sha3"); +const { SHAKE } = require("sha3"); const filetype = require("file-type"); const fetch = require("./lib/fetch.js"); function hash(str) { - const hash = new SHA3(128); + const hash = new SHAKE(128); hash.update(str); return hash.digest("base64") .replaceAll("/", "-") @@ -18,22 +18,36 @@ function hash(str) { } async function filter_asset(src) { - let target_dir = `./_site/img`; + process.stdout.write(`ASSET ${src} `); + let target_dir = `../_site/img`; if(!fs.existsSync(target_dir)) await fs.promises.mkdir(target_dir, { recursive: true }); let filename = path.basename(src); - if(src.search(/https?/)) { + if(src.search(/^https?:(?:\/\/)?/) > -1) { + console.log(`URL`); let content = await fetch(src, "none"); + + // Determine the file type extension let type = await filetype.fromBuffer(content); + if(typeof type === "undefined") { + // Failed, try to extract from the URL + let match = src.match(/(?<=\.)[a-zA-Z0-9-_]$/); + // Failed, just go with no file type extension at all + if(match === null) match = [ null, "" ]; + type = { ext: match[1] } + } + if(type.ext.length > 0) type.ext = `.${type.ext}`; + // It's a URL - download it - filename = `${hash(src)}.${type.ext}`; + filename = `${hash(src)}${type.ext}`; await fs.promises.writeFile( path.join(target_dir, filename), content ); } else { + console.log(`LOCAL`); // Generally speaking we optimise PNGs *very* well with oxipng/Zopfli, // and the Image plugin doesn't respect this await fs.promises.copyFile(src, path.join(target_dir, filename)); diff --git a/src/_includes/main.njk b/src/_includes/main.njk index a1b2ee3..d21d11e 100644 --- a/src/_includes/main.njk +++ b/src/_includes/main.njk @@ -1,7 +1,8 @@ --- site_name: Hull Blogs root_url: https://hullblogs.com -description: "Description of hullblogs.com website here" +tagline: "Aggregated posts from University of Hull students" +description: "Hull Blogs provides aggregated content from University of Hull students and alumni irrespective of department. Read how our students and alumni are changing the world in their own words." --- @@ -11,8 +12,7 @@ description: "Description of hullblogs.com website here" - - + @@ -20,7 +20,7 @@ description: "Description of hullblogs.com website here" - + @@ -28,19 +28,22 @@ description: "Description of hullblogs.com website here" - + -