From c75b029160248b6935e5c0f5156cc7a870311e82 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 26 Jun 2022 18:02:27 -0300 Subject: real pragma, and some eslint fixes --- src/upd8.js | 992 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 494 insertions(+), 498 deletions(-) (limited to 'src/upd8.js') diff --git a/src/upd8.js b/src/upd8.js index cff4313..8a5a287 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -1,6 +1,5 @@ #!/usr/bin/env node - -// @format +/** @format */ // HEY N8RDS! // @@ -33,18 +32,18 @@ // Oh yeah, like. Just run this through some relatively recent version of // node.js and you'll 8e fine. ...Within the project root. O8viously. -import * as path from "path"; -import { promisify } from "util"; -import { fileURLToPath } from "url"; +import * as path from 'path'; +import {promisify} from 'util'; +import {fileURLToPath} from 'url'; // I made this dependency myself! A long, long time ago. It is pro8a8ly my // most useful li8rary ever. I'm not sure 8esides me actually uses it, though. -import fixWS from "fix-whitespace"; +import fixWS from 'fix-whitespace'; // Wait nevermind, I forgot a8out why-do-kids-love-the-taste-of-cinnamon-toast- // crunch. THAT is my 8est li8rary. // It stands for "HTML Entities", apparently. Cursed. -import he from "he"; +import he from 'he'; import { copyFile, @@ -54,25 +53,25 @@ import { symlink, writeFile, unlink, -} from "fs/promises"; +} from 'fs/promises'; -import { inspect as nodeInspect } from "util"; +import {inspect as nodeInspect} from 'util'; -import genThumbs from "./gen-thumbs.js"; -import { listingSpec, listingTargetSpec } from "./listing-spec.js"; -import urlSpec from "./url-spec.js"; -import * as pageSpecs from "./page/index.js"; +import genThumbs from './gen-thumbs.js'; +import {listingSpec, listingTargetSpec} from './listing-spec.js'; +import urlSpec from './url-spec.js'; +import * as pageSpecs from './page/index.js'; -import find, { bindFind } from "./util/find.js"; -import * as html from "./util/html.js"; -import unbound_link, { getLinkThemeString } from "./util/link.js"; -import { findFiles } from "./util/io.js"; +import find, {bindFind} from './util/find.js'; +import * as html from './util/html.js'; +import unbound_link, {getLinkThemeString} from './util/link.js'; +import {findFiles} from './util/io.js'; -import CacheableObject from "./data/cacheable-object.js"; +import CacheableObject from './data/cacheable-object.js'; -import { serializeThings } from "./data/serialize.js"; +import {serializeThings} from './data/serialize.js'; -import { Language } from "./data/things.js"; +import {Language} from './data/things.js'; import { filterDuplicateDirectories, @@ -81,7 +80,7 @@ import { loadAndProcessDataDocuments, sortWikiDataArrays, WIKI_INFO_FILE, -} from "./data/yaml.js"; +} from './data/yaml.js'; import { fancifyFlashURL, @@ -103,7 +102,7 @@ import { getRevealStringFromWarnings, getThemeString, iconifyURL, -} from "./misc-templates.js"; +} from './misc-templates.js'; import { color, @@ -114,9 +113,9 @@ import { parseOptions, progressPromiseAll, ENABLE_COLOR, -} from "./util/cli.js"; +} from './util/cli.js'; -import { validateReplacerSpec, transformInline } from "./util/replacer.js"; +import {validateReplacerSpec, transformInline} from './util/replacer.js'; import { chunkByConditions, @@ -130,7 +129,7 @@ import { getKebabCase, getTotalDuration, getTrackCover, -} from "./util/wiki-data.js"; +} from './util/wiki-data.js'; import { serializeContribs, @@ -139,7 +138,7 @@ import { serializeGroupsForTrack, serializeImagePaths, serializeLink, -} from "./util/serialize.js"; +} from './util/serialize.js'; import { bindOpts, @@ -155,23 +154,23 @@ import { unique, withAggregate, withEntries, -} from "./util/sugar.js"; +} from './util/sugar.js'; -import { generateURLs, thumb } from "./util/urls.js"; +import {generateURLs, thumb} from './util/urls.js'; // Pensive emoji! import { FANDOM_GROUP_DIRECTORY, OFFICIAL_GROUP_DIRECTORY, -} from "./util/magic-constants.js"; +} from './util/magic-constants.js'; -import FileSizePreloader from "./file-size-preloader.js"; +import FileSizePreloader from './file-size-preloader.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const CACHEBUST = 10; -const DEFAULT_STRINGS_FILE = "strings-default.json"; +const DEFAULT_STRINGS_FILE = 'strings-default.json'; // Code that's common 8etween the 8uild code (i.e. upd8.js) and gener8ted // site code should 8e put here. Which, uh, ~~only really means this one @@ -180,20 +179,20 @@ const DEFAULT_STRINGS_FILE = "strings-default.json"; // Rather than hard code it, anything in this directory can 8e shared across // 8oth ends of the code8ase. // (This gets symlinked into the --data-path directory.) -const UTILITY_DIRECTORY = "util"; +const UTILITY_DIRECTORY = 'util'; // Code that's used only in the static site! CSS, cilent JS, etc. // (This gets symlinked into the --data-path directory.) -const STATIC_DIRECTORY = "static"; +const STATIC_DIRECTORY = 'static'; // This exists adjacent to index.html for any page with oEmbed metadata. -const OEMBED_JSON_FILE = "oembed.json"; +const OEMBED_JSON_FILE = 'oembed.json'; // Automatically copied (if present) from media directory to site root. -const FAVICON_FILE = "favicon.ico"; +const FAVICON_FILE = 'favicon.ico'; function inspect(value) { - return nodeInspect(value, { colors: ENABLE_COLOR }); + return nodeInspect(value, {colors: ENABLE_COLOR}); } // Shared varia8les! These are more efficient to access than a shared varia8le @@ -222,38 +221,38 @@ function splitLines(text) { const replacerSpec = { album: { - find: "album", - link: "album", + find: 'album', + link: 'album', }, - "album-commentary": { - find: "album", - link: "albumCommentary", + 'album-commentary': { + find: 'album', + link: 'albumCommentary', }, artist: { - find: "artist", - link: "artist", + find: 'artist', + link: 'artist', }, - "artist-gallery": { - find: "artist", - link: "artistGallery", + 'artist-gallery': { + find: 'artist', + link: 'artistGallery', }, - "commentary-index": { + 'commentary-index': { find: null, - link: "commentaryIndex", + link: 'commentaryIndex', }, date: { find: null, value: (ref) => new Date(ref), - html: (date, { language }) => + html: (date, {language}) => ``, }, flash: { - find: "flash", - link: "flash", + find: 'flash', + link: 'flash', transformName(name, node, input) { const nextCharacter = input[node.iEnd]; const lastCharacter = name[name.length - 1]; - if (![" ", "\n", "<"].includes(nextCharacter) && lastCharacter === ".") { + if (![' ', '\n', '<'].includes(nextCharacter) && lastCharacter === '.') { return name.slice(0, -1); } else { return name; @@ -261,69 +260,69 @@ const replacerSpec = { }, }, group: { - find: "group", - link: "groupInfo", + find: 'group', + link: 'groupInfo', }, - "group-gallery": { - find: "group", - link: "groupGallery", + 'group-gallery': { + find: 'group', + link: 'groupGallery', }, home: { find: null, - link: "home", + link: 'home', }, - "listing-index": { + 'listing-index': { find: null, - link: "listingIndex", + link: 'listingIndex', }, listing: { - find: "listing", - link: "listing", + find: 'listing', + link: 'listing', }, media: { find: null, - link: "media", + link: 'media', }, - "news-index": { + 'news-index': { find: null, - link: "newsIndex", + link: 'newsIndex', }, - "news-entry": { - find: "newsEntry", - link: "newsEntry", + 'news-entry': { + find: 'newsEntry', + link: 'newsEntry', }, root: { find: null, - link: "root", + link: 'root', }, site: { find: null, - link: "site", + link: 'site', }, static: { - find: "staticPage", - link: "staticPage", + find: 'staticPage', + link: 'staticPage', }, string: { find: null, value: (ref) => ref, - html: (ref, { language, args }) => language.$(ref, args), + html: (ref, {language, args}) => language.$(ref, args), }, tag: { - find: "artTag", - link: "tag", + find: 'artTag', + link: 'tag', }, track: { - find: "track", - link: "track", + find: 'track', + link: 'track', }, }; -if (!validateReplacerSpec(replacerSpec, { find, link: unbound_link })) { +if (!validateReplacerSpec(replacerSpec, {find, link: unbound_link})) { process.exit(); } -function parseAttributes(string, { to }) { +function parseAttributes(string, {to}) { const attributes = Object.create(null); const skipWhitespace = (i) => { const ws = /\s/; @@ -345,7 +344,7 @@ function parseAttributes(string, { to }) { const aEnd = i + string.slice(i).match(/[\s=]|$/).index; const attribute = string.slice(aStart, aEnd); i = skipWhitespace(aEnd); - if (string[i] === "=") { + if (string[i] === '=') { i = skipWhitespace(i + 1); let end, endOffset; if (string[i] === '"' || string[i] === "'") { @@ -353,15 +352,15 @@ function parseAttributes(string, { to }) { endOffset = 1; i++; } else { - end = "\\s"; + end = '\\s'; endOffset = 0; } const vStart = i; const vEnd = i + string.slice(i).match(new RegExp(`${end}|$`)).index; const value = string.slice(vStart, vEnd); i = vEnd + endOffset; - if (attribute === "src" && value.startsWith("media/")) { - attributes[attribute] = to("media.path", value.slice("media/".length)); + if (attribute === 'src' && value.startsWith('media/')) { + attributes[attribute] = to('media.path', value.slice('media/'.length)); } else { attributes[attribute] = value; } @@ -372,9 +371,9 @@ function parseAttributes(string, { to }) { return Object.fromEntries( Object.entries(attributes).map(([key, val]) => [ key, - val === "true" + val === 'true' ? true - : val === "false" + : val === 'false' ? false : val === key ? true @@ -386,13 +385,13 @@ function parseAttributes(string, { to }) { function joinLineBreaks(sourceLines) { const outLines = []; - let lineSoFar = ""; + let lineSoFar = ''; for (let i = 0; i < sourceLines.length; i++) { const line = sourceLines[i]; lineSoFar += line; - if (!line.endsWith("
")) { + if (!line.endsWith('
')) { outLines.push(lineSoFar); - lineSoFar = ""; + lineSoFar = ''; } } @@ -403,14 +402,14 @@ function joinLineBreaks(sourceLines) { return outLines; } -function transformMultiline(text, { parseAttributes, transformInline }) { +function transformMultiline(text, {parseAttributes, transformInline}) { // Heck yes, HTML magics. text = transformInline(text.trim()); const outLines = []; - const indentString = " ".repeat(4); + const indentString = ' '.repeat(4); let levelIndents = []; const openLevel = (indent) => { @@ -418,13 +417,13 @@ function transformMultiline(text, { parseAttributes, transformInline }) { // correct, we have to append the