From 8a7cb1edff25ba3e612d7c24b07cc776ff8738d6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 8 Jan 2021 00:15:37 -0400 Subject: okay so like, hear me out here this commit isnt QUITE done but its in a working state, and i just had the scariest vision of accidentally discarding all my work via git mishap, yknow? even though im not doing anything funky with git! so yall get this commit early and its goin on line but im not pushing it to the site til its done. no spoilering yourself (even though ive already posted most of the cool things in the discord) <3 --- upd8.js | 946 ++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 714 insertions(+), 232 deletions(-) (limited to 'upd8.js') diff --git a/upd8.js b/upd8.js index 86aeb53..64a311c 100644 --- a/upd8.js +++ b/upd8.js @@ -51,6 +51,14 @@ // // Use these wisely, which is to say all the time and instead of whatever // terri8le new pseudo structure you're trying to invent!!!!!!!! +// +// Upd8 2021-01-03: Soooooooo we didn't actually really end up using these, +// lol? Well there's still only one anyway. Kinda ended up doing a 8ig refactor +// of all the o8ject structures today. It's not *especially* relevant 8ut feels +// worth mentioning? I'd get rid of this comment 8lock 8ut I like it too much! +// Even though I haven't actually reread it, lol. 8ut yeah, hopefully in the +// spirit of this "make things more consistent" attitude I 8rought up 8ack in +// August, stuff's lookin' 8etter than ever now. W00t! 'use strict'; @@ -94,8 +102,11 @@ const unlink = util.promisify(fs.unlink); const { cacheOneArg, + curry, decorateTime, joinNoOxford, + mapInPlace, + parseOptions, progressPromiseAll, queue, s, @@ -110,9 +121,6 @@ const SITE_TITLE = 'Homestuck Music Wiki'; const SITE_SHORT_TITLE = 'HSMusic'; const SITE_DESCRIPTION = `Expansive resource for anyone interested in fan-made and official Homestuck music alike; an archive for all things related.`; -const SITE_VERSION = 'launch of hsmusic.wiki'; -const SITE_RELEASE = '12 December 2020'; - const SITE_DONATE_LINK = 'https://liberapay.com/nebula'; function readDataFile(file) { @@ -133,6 +141,7 @@ const ARTIST_DATA_FILE = 'artists.txt'; const FLASH_DATA_FILE = 'flashes.txt'; const NEWS_DATA_FILE = 'news.txt'; const TAG_DATA_FILE = 'tags.txt'; +const GROUP_DATA_FILE = 'groups.txt'; const CSS_FILE = 'site.css'; @@ -143,10 +152,11 @@ const CSS_FILE = 'site.css'; // Upd8: Okay yeah these aren't actually any different. Still cleaner than // passing around a data object containing all this, though. let albumData; -let allTracks; +let trackData; let flashData; let newsData; let tagData; +let groupData; let artistNames; let artistData; @@ -155,6 +165,9 @@ let officialAlbumData; let fandomAlbumData; let justEverythingMan; // tracks, albums, flashes -- don't forget to upd8 getHrefOfAnythingMan! let justEverythingSortedByArtDateMan; +let contributionData; + +let queueSize; // Note there isn't a 'find track data files' function. I plan on including the // data for all tracks within an al8um collected in the single metadata file @@ -312,7 +325,7 @@ function transformInline(text) { return ref; } } else if (category === 'tag:') { - const tag = tagData.find(tag => tag.directory === ref); + const tag = getLinkedTag(ref); if (tag) { return fixWS` ${tag.name} @@ -481,7 +494,8 @@ async function processAlbumDataFile(file) { album.trackCoverArtists = getContributionField(albumSection, 'Track Art'); album.artTags = getListField(albumSection, 'Art Tags') || []; album.commentary = getCommentaryField(albumSection); - album.urls = (getListField(albumSection, 'URLs') || []).filter(Boolean); + album.urls = getListField(albumSection, 'URLs') || []; + album.groups = getListField(albumSection, 'Groups') || []; album.directory = getBasicField(albumSection, 'Directory'); const canon = getBasicField(albumSection, 'Canon'); @@ -490,6 +504,8 @@ async function processAlbumDataFile(file) { album.isOfficial = album.isCanon || album.isBeyond; album.isFanon = canon === 'Fanon'; + album.isMajorRelease = getBasicField(albumSection, 'Major Release') === 'yes'; + if (album.artists && album.artists.error) { return {error: `${album.artists.error} (in ${album.name})`}; } @@ -580,7 +596,7 @@ async function processAlbumDataFile(file) { track.aka = getBasicField(section, 'AKA'); if (!track.name) { - return {error: 'A track section is missing the "Track" (name) field (in ${album.name)}.'}; + return {error: `A track section is missing the "Track" (name) field (in ${album.name}, previous: ${album.tracks[album.tracks.length - 1]?.name}).`}; } let durationString = getBasicField(section, 'Duration') || '0:00'; @@ -676,12 +692,21 @@ async function processArtistDataFile(file) { const urls = (getListField(section, 'URLs') || []).filter(Boolean); const alias = getBasicField(section, 'Alias'); const note = getMultilineField(section, 'Note'); + let directory = getBasicField(section, 'Directory'); if (!name) { return {error: 'Expected "Artist" (name) field!'}; } - return {name, urls, alias, note}; + if (!directory) { + directory = C.getArtistDirectory(name); + } + + if (alias) { + return {name, directory, alias}; + } else { + return {name, directory, urls, note}; + } }); } @@ -837,6 +862,51 @@ async function processTagDataFile(file) { }); } +async function processGroupDataFile(file) { + let contents; + try { + contents = await readFile(file, 'utf-8'); + } catch (error) { + return {error: `Could not read ${file} (${error.code}).`}; + } + + const contentLines = contents.split('\n'); + const sections = Array.from(getSections(contentLines)); + + return sections.map(section => { + const name = getBasicField(section, 'Group'); + if (!name) { + return {error: 'Expected "Group" field!'}; + } + + let directory = getBasicField(section, 'Directory'); + if (!directory) { + directory = C.getKebabCase(name); + } + + let description = getMultilineField(section, 'Description'); + if (!description) { + return {error: 'Expected "Description" field!'}; + } + + let descriptionShort = description.split('
')[0]; + + description = transformMultiline(description); + descriptionShort = transformMultiline(descriptionShort); + + const urls = (getListField(section, 'URLs') || []).filter(Boolean); + + return { + name, + directory, + description, + descriptionShort, + urls, + color: '#00ffff' + }; + }); +} + function getDateString({ date }) { /* const pad = val => val.toString().padStart(2, '0'); @@ -885,28 +955,81 @@ function getTotalDuration(tracks) { const stringifyIndent = 0; +const toRefs = (label, array) => array.filter(Boolean).map(x => `${label}:${x.directory}`); + +function stringifyRefs(key, value) { + switch (key) { + case 'albums': return toRefs('album', value); + case 'tracks': + case 'references': + case 'referencedBy': + if (!Array.isArray(value)) console.log(Object.keys(value)); + return toRefs('track', value); + case 'artists': + case 'contributors': + case 'coverArtists': + case 'trackCoverArtists': + return value && value.map(({ who, what }) => ({who: `artist:${who.directory}`, what})); + case 'flashes': return toRefs('flash', value); + case 'groups': return toRefs('group', value); + case 'artTags': return toRefs('tag', value); + case 'aka': return value && `track:${value.directory}`; + default: + return value; + } +} + function stringifyAlbumData() { return JSON.stringify(albumData, (key, value) => { - if (['album', 'commentary'].includes(key)) { - return undefined; + switch (key) { + case 'commentary': + return ''; + default: + return stringifyRefs(key, value); } + }, stringifyIndent); +} - return value; +function stringifyTrackData() { + return JSON.stringify(trackData, (key, value) => { + switch (key) { + case 'album': + case 'commentary': + case 'otherReleases': + return undefined; + default: + return stringifyRefs(key, value); + } }, stringifyIndent); } function stringifyFlashData() { return JSON.stringify(flashData, (key, value) => { - if (['act', 'commentary'].includes(key)) { - return undefined; + switch (key) { + case 'act': + case 'commentary': + return undefined; + default: + return stringifyRefs(key, value); } - - return value; }, stringifyIndent); } function stringifyArtistData() { - return JSON.stringify(artistData, null, stringifyIndent); + return JSON.stringify(artistData, (key, value) => { + switch (key) { + case 'tracks': // skip stringifyRefs handling 'tracks' key as an array + return value; + case 'asAny': + return; + case 'asArtist': + case 'asContributor': + case 'asCoverArtist': + return toRefs('track', value); + default: + return stringifyRefs(key, value); + } + }, stringifyIndent); } function escapeAttributeValue(value) { @@ -996,11 +1119,16 @@ async function writePage(directoryParts, { main = { classes: [], + collapseSidebars: true, content: '' }, sidebar = { - collapse: true, + classes: [], + content: '' + }, + + sidebarRight = { classes: [], content: '' }, @@ -1021,26 +1149,51 @@ async function writePage(directoryParts, { } const canonical = SITE_CANONICAL_BASE + targetPath; + const { + collapseSidebars = true + } = main; + const mainHTML = main.content && fixWS`
${main.content}
`; - const { - collapse = true, + const generateSidebarHTML = (id, { + content, + multiple, + classes: sidebarClasses = [], wide = false - } = sidebar; - - const sidebarHTML = sidebar.content && fixWS` -