From 6592c70fd5143808b1c238a8ace9038baae599ef Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 6 Jun 2020 14:11:11 -0300 Subject: generate relative links & some alt codes no more element means this works in browsers like lynx! --- upd8.js | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/upd8.js b/upd8.js index 88539887..26e1314d 100644 --- a/upd8.js +++ b/upd8.js @@ -692,7 +692,7 @@ async function writePage(directoryParts, titleOrHead, body) { // for now. TM. (Ahem. Still. Soon...may8e. TM. -- Should 8e easier now // that we'll have a proper function for writing any page - just appending // a C.ROOT_DIRECTORY should work. Um... okay, fine, I'll do that.) - await writeFile(path.join(directory, 'index.html'), fixWS` + await writeFile(path.join(directory, 'index.html'), rebaseURLs(directory, fixWS` @@ -700,9 +700,9 @@ async function writePage(directoryParts, titleOrHead, body) { ``, ``, (titleOrHead.split('\n').length && !titleOrHead.includes('')) ? `<title>${titleOrHead}` : titleOrHead, - directory !== C.SITE_DIRECTORY && - directory !== '.' && - ``, + // directory !== C.SITE_DIRECTORY && + // directory !== '.' && + // ``, ``, // Apply JavaScript directly to the HTML . // (This is unfortun8, 8ut necessary, 8ecause the entire @@ -718,7 +718,7 @@ async function writePage(directoryParts, titleOrHead, body) { ${body} - `); + `)); } function writeMiscellaneousPages() { @@ -743,7 +743,7 @@ function writeMiscellaneousPages() {
${albumData.filter(album => album.isBeyond).reverse().map(album => fixWS` - + cover art ${album.name} `).join('\n')} @@ -753,7 +753,7 @@ function writeMiscellaneousPages() {
${albumData.filter(album => album.isFanon).reverse().map(album => fixWS` - + cover art ${album.name} `).join('\n')} @@ -764,7 +764,7 @@ function writeMiscellaneousPages() {
${albumData.filter(album => album.isCanon).reverse().map(album => fixWS` - + cover art ${album.name} `).join('\n')} @@ -794,7 +794,7 @@ function writeMiscellaneousPages() {

${flash.act}

` : fixWS` - + cover art ${flash.name} `).join('\n')} @@ -861,7 +861,7 @@ async function writeAlbumPage(album) { ${generateSidebarForAlbum(album)}
- + cover art

${album.name}

${album.artists && `By ${getArtistString(album.artists)}.
`} @@ -910,7 +910,7 @@ async function writeTrackPage(track) { ${generateSidebarForAlbum(track.album, track)}

- + cover art

${track.name}

By ${getArtistString(track.artists)}.
@@ -1037,7 +1037,7 @@ async function writeArtistPage(artistName) {

${ENABLE_ARTIST_AVATARS && await access(path.join(C.ARTIST_AVATAR_DIRECTORY, kebab + '.jpg')).then(() => true, () => false) && fixWS` - + Artist avatar `}

${artistName}

${urls.length && `

Visit on ${joinNoOxford(urls.map(fancifyURL), 'or')}.

`} @@ -1231,7 +1231,7 @@ async function writeFlashPage(flash) {

${flash.name}

- + cover art

Released ${getDateString(flash)}.

${flash.page && `

Play on Homestuck (${isNaN(Number(flash.page)) ? 'secret page' : `page ${flash.page}`}).

`} ${flash.contributors.length && fixWS` @@ -1842,6 +1842,22 @@ function getFlashLinkHTML(flash) { return `${flash.name}`; } +function rebaseURLs(directory, html) { + if (directory === '') { + return html; + } + return html.replace(/(href|src)="(.*?)"/g, (match, attr, url) => { + try { + new URL(url); + // no error: it's a full url + } catch (error) { + // caught an error: it's a component! + url = path.relative(directory, url); + } + return `${attr}="${url}"`; + }); +} + async function main() { // 8ut wait, you might say, how do we know which al8um these data files // correspond to???????? You wouldn't dare suggest we parse the actual -- cgit 1.3.0-6-gf8a5