From fc8688ff971b0b552312e04b2a55a7ee12df3e78 Mon Sep 17 00:00:00 2001 From: osmarks Date: Tue, 25 Aug 2020 22:52:23 +0100 Subject: [PATCH] add openring "webring" bit --- .gitignore | 4 ++- openring.html | 16 ++++++++++++ src/global.json | 11 +++++++- src/index.js | 63 ++++++++++++++++++++++++++++++--------------- style.sass | 27 ++++++++++++++++++- templates/index.pug | 6 ++++- 6 files changed, 102 insertions(+), 25 deletions(-) create mode 100644 openring.html diff --git a/.gitignore b/.gitignore index 07d2252..aeba173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules -out \ No newline at end of file +out +openring +draft \ No newline at end of file diff --git a/openring.html b/openring.html new file mode 100644 index 0000000..388f2fc --- /dev/null +++ b/openring.html @@ -0,0 +1,16 @@ +

From other blogs

+
+ {{range .Articles}} +
+

+ {{.Title}} +

+

{{.Summary}}

+ + via {{.SourceTitle}} + + {{.Date | datef "02/01/2006"}} +
+ {{end}} +
+

Generated by openring

\ No newline at end of file diff --git a/src/global.json b/src/global.json index a066507..13d18f0 100644 --- a/src/global.json +++ b/src/global.json @@ -1,5 +1,14 @@ { "name": "Oliver's Website", "domain": "osmarks.tk", - "siteDescription": "Whimsical uselessness available conveniently online." + "siteDescription": "Whimsical uselessness available conveniently online.", + "feeds": [ + "https://blogs.sciencemag.org/pipeline/feed", + "https://www.rtl-sdr.com/feed/", + "https://slatestarcodex.com/feed/", + "https://www.rifters.com/crawl/?feed=rss2", + "https://drewdevault.com/feed.xml", + "https://www.giantitp.com/comics/oots.rss", + "https://qntm.org/rss.php" + ] } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 1764c3c..090ab15 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,8 @@ const customParseFormat = require("dayjs/plugin/customParseFormat") const nanoid = require("nanoid") const htmlMinifier = require("html-minifier").minify const terser = require("terser") -const { minify } = require("html-minifier") +const util = require("util") +const childProcess = require("child_process") dayjs.extend(customParseFormat) @@ -140,29 +141,44 @@ const processAssets = async templates => { const outAssets = path.join(outDir, "assets") await fse.ensureDir(outAssets) - applyTemplate(templates.experiment, path.join(assetsDir, "offline.html"), () => path.join(outAssets, "offline.html"), {}) - // Write out the web manifest after templating it using somewhat misapplied frontend templating stuff - const manifest = mustache.render(await readFile(path.join(assetsDir, "manifest.webmanifest")), globalData) - await fsp.writeFile(path.join(outAssets, "manifest.webmanifest"), manifest) + const runManifest = async () => { + const m = mustache.render(await readFile(path.join(assetsDir, "manifest.webmanifest")), globalData) + fsp.writeFile(path.join(outAssets, "manifest.webmanifest"), m) + } + + const runJS = async () => { + const jsDir = path.join(assetsDir, "js") + const jsOutDir = path.join(outAssets, "js") + await Promise.all((await fsp.readdir(jsDir)).map(async file => { + const fullpath = path.join(jsDir, file) + await minifyJSFile(await readFile(fullpath), file, path.join(jsOutDir, file)) + })) + + const serviceWorker = mustache.render(await readFile(path.join(assetsDir, "sw.js")), globalData) + await minifyJSFile(serviceWorker, "sw.js", path.join(outDir, "sw.js")) + } const copyAsset = subpath => fse.copy(path.join(assetsDir, subpath), path.join(outAssets, subpath)) // Directly copy images, JS, CSS - await Promise.all([await copyAsset("images"), await copyAsset("css")]) - - const jsDir = path.join(assetsDir, "js") - const jsOutDir = path.join(outAssets, "js") - await Promise.all((await fsp.readdir(jsDir)).map(async file => { - const fullpath = path.join(jsDir, file) - await minifyJSFile(await readFile(fullpath), file, path.join(jsOutDir, file)) - })) - - const serviceWorker = mustache.render(await readFile(path.join(assetsDir, "sw.js")), globalData) - await minifyJSFile(serviceWorker, "sw.js", path.join(outDir, "sw.js")) + await Promise.all([ + copyAsset("images"), + copyAsset("css"), + runManifest, + runJS, + applyTemplate(templates.experiment, path.join(assetsDir, "offline.html"), () => path.join(outAssets, "offline.html"), {}) + ]) } globalData.renderDate = date => date.format("DD/MM/YYYY") +const runOpenring = async () => { + // wildly unsafe but only runs on input from me anyway + const out = await util.promisify(childProcess.exec)(`./openring -n6 ${globalData.feeds.map(x => "-s " + x).join(" ")} < openring.html`) + console.log(out.stderr) + return out.stdout +} + const run = async () => { const css = await sass.renderSync({ data: await readFile(path.join(root, "style.sass")), @@ -172,12 +188,17 @@ const run = async () => { globalData.css = css const templates = await loadDir(templateDir, async fullPath => pug.compile(await readFile(fullPath), { filename: fullPath })) - const experimentsList = R.sortBy(x => x.title, R.values(await processExperiments(templates))) - const blogList = R.sortBy(x => x.updated ? -x.updated.valueOf() : 0, R.values(await processBlog(templates))) - await processAssets(templates) - await processErrorPages(templates) + const [exp, blg, opr, ..._] = await Promise.all([ + processExperiments(templates), + processBlog(templates), + runOpenring(), + processAssets(templates), + processErrorPages(templates) + ]) + const experimentsList = R.sortBy(x => x.title, R.values(exp)) + const blogList = R.sortBy(x => x.updated ? -x.updated.valueOf() : 0, R.values(blg)) - const index = templates.index({ ...globalData, title: "Index", experiments: experimentsList, posts: blogList }) + const index = templates.index({ ...globalData, title: "Index", experiments: experimentsList, posts: blogList, openring: opr }) await fsp.writeFile(path.join(outDir, "index.html"), index) const rssFeed = templates.rss({ ...globalData, items: blogList, lastUpdate: new Date() }) diff --git a/style.sass b/style.sass index 0a8c270..3765f0e 100644 --- a/style.sass +++ b/style.sass @@ -68,4 +68,29 @@ ul .smallinfo font-size: 0.8em margin-top: 0.5em - margin-bottom: 0.5em \ No newline at end of file + margin-bottom: 0.5em + +.ring + .atl + display: flex + flex-wrap: wrap + margin: -0.5rem + + h4 + margin: 0 + + .art + flex: 1 1 0 + display: flex + flex-direction: column + margin: 0.5rem + padding: 0.5rem + background: #eee + min-width: 20em + .sum + font-size: 0.8rem + flex: 1 1 0 + .atr + text-align: right + font-size: 0.8rem + color: #555 diff --git a/templates/index.pug b/templates/index.pug index 193a026..b31bf9a 100644 --- a/templates/index.pug +++ b/templates/index.pug @@ -22,4 +22,8 @@ block content span= ` ` span.description!= experiment.description - p Get updates to the blog (not experiments) in your favourite RSS reader using the RSS feed. \ No newline at end of file + p Get updates to the blog (not experiments) in your favourite RSS reader using the RSS feed. + p View some of my projects (and whatever else) + a(href=`https://git.${domain}/`) my git hosting. + + .ring!= openring \ No newline at end of file