From 592acc152dc68e0f24300c090c9eabb9f21cef6b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:32:22 -0400 Subject: remove output-specific getPagePaths util --- src/write/build-modes/static-build.js | 53 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 90fc38ae..bbf97085 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -27,7 +27,6 @@ import { import { getPagePathname, - getPagePaths, getPageSubdirectoryPrefix, getURLsFrom, getURLsFromRoot, @@ -267,6 +266,7 @@ export async function go({ ...pageWrites.map(page => () => { const pageSubKey = page.path[0]; const urlArgs = page.path.slice(1); + const fullKey = 'localized.' + pageSubKey; const localizedPathnames = withEntries(languages, entries => entries .filter(([key, language]) => key !== 'default' && !language.hidden) @@ -277,19 +277,17 @@ export async function go({ (language === defaultLanguage ? '' : language.code), - fullKey: 'localized.' + pageSubKey, + fullKey, urlArgs, urls, }), ])); - const paths = getPagePaths({ - outputPath, - urls, - + const pathname = getPagePathname({ baseDirectory, - fullKey: 'localized.' + pageSubKey, + fullKey, urlArgs, + urls, }); const to = getURLsFrom({ @@ -328,7 +326,7 @@ export async function go({ wikiData.wikiInfo.canonicalBase + urls .from('shared.root') - .to('shared.path', paths.pathname + 'oembed.json'); + .to('shared.path', pathname + 'oembed.json'); const pageHTML = generateDocumentHTML(pageInfo, { cachebust, @@ -340,7 +338,7 @@ export async function go({ localizedPathnames, oEmbedJSONHref, pageSubKey, - pathname: paths.pathname, + pathname, to, transformMultiline: bound.transformMultiline, urlArgs, @@ -350,7 +348,13 @@ export async function go({ return writePage({ html: pageHTML, oEmbedJSON, - paths, + outputDirectory: path.join(outputPath, getPagePathname({ + baseDirectory, + device: true, + fullKey, + urlArgs, + urls, + })), }); }), ...redirectWrites.map(({fromPath, toPath, title: titleFn}) => () => { @@ -358,15 +362,6 @@ export async function go({ language, }); - const from = getPagePaths({ - outputPath, - urls, - - baseDirectory, - fullKey: 'localized.' + fromPath[0], - urlArgs: fromPath.slice(1), - }); - const to = getURLsFrom({ urls, baseDirectory, @@ -378,7 +373,17 @@ export async function go({ const target = to('localized.' + toPath[0], ...toPath.slice(1)); const html = generateRedirectHTML(title, target, {language}); - return writePage({html, paths: from}); + + return writePage({ + html, + outputDirectory: path.join(outputPath, getPagePathname({ + baseDirectory, + device: true, + fullKey: 'localized.' + fromPath[0], + urlArgs: fromPath.slice(1), + urls, + })), + }); }), ], queueSize)); }; @@ -424,15 +429,15 @@ import { async function writePage({ html, oEmbedJSON = '', - paths, + outputDirectory, }) { - await mkdir(paths.output.directory, {recursive: true}); + await mkdir(outputDirectory, {recursive: true}); await Promise.all([ - writeFile(paths.output.documentHTML, html), + writeFile(path.join(outputDirectory, 'index.html'), html), oEmbedJSON && - writeFile(paths.output.oEmbedJSON, oEmbedJSON), + writeFile(path.join(outputDirectory, 'oembed.json'), oEmbedJSON), ].filter(Boolean)); } -- cgit 1.3.0-6-gf8a5 From e06292fe8e7d789d38ac43fd9eee6816e39e18fe Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:45:13 -0400 Subject: extract fn for localizedPathnames --- src/write/build-modes/live-dev-server.js | 23 ++++++++--------------- src/write/build-modes/static-build.js | 24 +++++++++--------------- 2 files changed, 17 insertions(+), 30 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index b6bf662b..a5d9da97 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -11,10 +11,10 @@ import {serializeThings} from '../../data/serialize.js'; import * as pageSpecs from '../../page/index.js'; import {logInfo, logWarn, progressCallAll} from '../../util/cli.js'; -import {withEntries} from '../../util/sugar.js'; import { getPagePathname, + getPagePathnameAcrossLanguages, getPageSubdirectoryPrefix, getURLsFrom, getURLsFromRoot, @@ -280,20 +280,13 @@ export async function go({ response.writeHead(200, contentTypeHTML); - const localizedPathnames = withEntries(languages, entries => entries - .filter(([key, language]) => key !== 'default' && !language.hidden) - .map(([_key, language]) => [ - language.code, - getPagePathname({ - baseDirectory: - (language === defaultLanguage - ? '' - : language.code), - fullKey: 'localized.' + pageSubKey, - urlArgs, - urls, - }), - ])); + const localizedPathnames = getPagePathnameAcrossLanguages({ + defaultLanguage, + languages, + pageSubKey, + urlArgs, + urls, + }); const bound = bindUtilities({ absoluteTo, diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index bbf97085..0e8c4b07 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -15,7 +15,7 @@ import {serializeThings} from '../../data/serialize.js'; import * as pageSpecs from '../../page/index.js'; import link from '../../util/link.js'; -import {empty, queue, withEntries} from '../../util/sugar.js'; +import {empty, queue} from '../../util/sugar.js'; import { logError, @@ -27,6 +27,7 @@ import { import { getPagePathname, + getPagePathnameAcrossLanguages, getPageSubdirectoryPrefix, getURLsFrom, getURLsFromRoot, @@ -268,20 +269,13 @@ export async function go({ const urlArgs = page.path.slice(1); const fullKey = 'localized.' + pageSubKey; - const localizedPathnames = withEntries(languages, entries => entries - .filter(([key, language]) => key !== 'default' && !language.hidden) - .map(([_key, language]) => [ - language.code, - getPagePathname({ - baseDirectory: - (language === defaultLanguage - ? '' - : language.code), - fullKey, - urlArgs, - urls, - }), - ])); + const localizedPathnames = getPagePathnameAcrossLanguages({ + defaultLanguage, + languages, + pageSubKey, + urlArgs, + urls, + }); const pathname = getPagePathname({ baseDirectory, -- cgit 1.3.0-6-gf8a5 From fd59ddd05bdfebf2f9a55a0fa5915485929e7de6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 19:54:10 -0400 Subject: don't pass around fullKey where unneeded --- src/write/build-modes/live-dev-server.js | 7 ++----- src/write/build-modes/static-build.js | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index a5d9da97..bdd4561e 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -83,17 +83,14 @@ export async function go({ else if (page.type === 'redirect') servePath = page.fromPath; - const fullKey = 'localized.' + servePath[0]; - const urlArgs = servePath.slice(1); - return Object.values(languages).map(language => { const baseDirectory = language === defaultLanguage ? '' : language.code; const pathname = getPagePathname({ baseDirectory, - fullKey, - urlArgs, + pageSubKey: servePath[0], + urlArgs: servePath.slice(1), urls, }); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 0e8c4b07..edfb02c2 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -267,7 +267,6 @@ export async function go({ ...pageWrites.map(page => () => { const pageSubKey = page.path[0]; const urlArgs = page.path.slice(1); - const fullKey = 'localized.' + pageSubKey; const localizedPathnames = getPagePathnameAcrossLanguages({ defaultLanguage, @@ -279,7 +278,7 @@ export async function go({ const pathname = getPagePathname({ baseDirectory, - fullKey, + pageSubKey, urlArgs, urls, }); @@ -345,7 +344,7 @@ export async function go({ outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, - fullKey, + pageSubKey, urlArgs, urls, })), @@ -373,7 +372,7 @@ export async function go({ outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, - fullKey: 'localized.' + fromPath[0], + pageSubKey: fromPath[0], urlArgs: fromPath.slice(1), urls, })), -- cgit 1.3.0-6-gf8a5 From 54ad9946e3fa32ae8388d54ec8b3baad78a29417 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:20:18 -0400 Subject: prefer passing around pagePath --- src/write/build-modes/live-dev-server.js | 16 +++++----------- src/write/build-modes/static-build.js | 26 ++++++++++---------------- src/write/page-template.js | 11 ++++------- 3 files changed, 19 insertions(+), 34 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index bdd4561e..ec9689bd 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -89,8 +89,7 @@ export async function go({ const pathname = getPagePathname({ baseDirectory, - pageSubKey: servePath[0], - urlArgs: servePath.slice(1), + pagePath: servePath, urls, }); @@ -248,9 +247,9 @@ export async function go({ const to = getURLsFrom({ urls, baseDirectory, - pageSubKey: servePath[0], + pagePath: servePath, subdirectoryPrefix: getPageSubdirectoryPrefix({ - urlArgs: servePath.slice(1), + pagePath: servePath, }), }); @@ -260,9 +259,6 @@ export async function go({ }); try { - const pageSubKey = servePath[0]; - const urlArgs = servePath.slice(1); - if (page.type === 'redirect') { response.writeHead(301, contentTypeHTML); @@ -280,8 +276,7 @@ export async function go({ const localizedPathnames = getPagePathnameAcrossLanguages({ defaultLanguage, languages, - pageSubKey, - urlArgs, + pagePath: servePath, urls, }); @@ -305,9 +300,8 @@ export async function go({ languages, localizedPathnames, oEmbedJSONHref: null, // No oEmbed support for live dev server - pageSubKey, + pagePath: servePath, pathname, - urlArgs, to, transformMultiline: bound.transformMultiline, wikiData, diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index edfb02c2..5141891c 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -265,30 +265,27 @@ export async function go({ await progressPromiseAll(`Writing ${language.code}`, queue([ ...pageWrites.map(page => () => { - const pageSubKey = page.path[0]; - const urlArgs = page.path.slice(1); + const pagePath = page.path; const localizedPathnames = getPagePathnameAcrossLanguages({ defaultLanguage, languages, - pageSubKey, - urlArgs, + pagePath, urls, }); const pathname = getPagePathname({ baseDirectory, - pageSubKey, - urlArgs, + pagePath, urls, }); const to = getURLsFrom({ urls, baseDirectory, - pageSubKey, + pagePath, subdirectoryPrefix: getPageSubdirectoryPrefix({ - urlArgs: page.path.slice(1), + pagePath, }), }); @@ -330,11 +327,10 @@ export async function go({ languages, localizedPathnames, oEmbedJSONHref, - pageSubKey, + pagePath, pathname, to, transformMultiline: bound.transformMultiline, - urlArgs, wikiData, }); @@ -344,8 +340,7 @@ export async function go({ outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, - pageSubKey, - urlArgs, + pagePath, urls, })), }); @@ -358,9 +353,9 @@ export async function go({ const to = getURLsFrom({ urls, baseDirectory, - pageSubKey: fromPath[0], + pagePath: fromPath, subdirectoryPrefix: getPageSubdirectoryPrefix({ - urlArgs: fromPath.slice(1), + pagePath: fromPath, }), }); @@ -372,8 +367,7 @@ export async function go({ outputDirectory: path.join(outputPath, getPagePathname({ baseDirectory, device: true, - pageSubKey: fromPath[0], - urlArgs: fromPath.slice(1), + pagePath: fromPath, urls, })), }); diff --git a/src/write/page-template.js b/src/write/page-template.js index 88d81c23..7c2f0c66 100644 --- a/src/write/page-template.js +++ b/src/write/page-template.js @@ -55,11 +55,10 @@ export function generateDocumentHTML(pageInfo, { languages, localizedPathnames, oEmbedJSONHref, - pageSubKey, + pagePath, pathname, to, transformMultiline, - urlArgs, wikiData, }) { const {wikiInfo} = wikiData; @@ -169,9 +168,8 @@ export function generateDocumentHTML(pageInfo, { html, language, languages, - pageSubKey, + pagePath, to, - urlArgs, }), ]); @@ -450,10 +448,9 @@ export function generateDocumentHTML(pageInfo, { { lang: language.intlCode, 'data-language-code': language.code, - 'data-url-key': 'localized.' + pageSubKey, + 'data-url-key': 'localized.' + pagePath[0], ...Object.fromEntries( - urlArgs.map((v, i) => [['data-url-value' + i], v]) - ), + pagePath.slice(1).map((v, i) => [['data-url-value' + i], v])), 'data-rebase-localized': to('localized.root'), 'data-rebase-shared': to('shared.root'), 'data-rebase-media': to('media.root'), -- cgit 1.3.0-6-gf8a5 From ba8a441f95481e294d414a0c89e2513f82f45a7a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:28:22 -0400 Subject: compute subdirectoryPrefix internally --- src/write/build-modes/live-dev-server.js | 6 +----- src/write/build-modes/static-build.js | 11 ++--------- 2 files changed, 3 insertions(+), 14 deletions(-) (limited to 'src/write') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index ec9689bd..a4c4c871 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -15,7 +15,6 @@ import {logInfo, logWarn, progressCallAll} from '../../util/cli.js'; import { getPagePathname, getPagePathnameAcrossLanguages, - getPageSubdirectoryPrefix, getURLsFrom, getURLsFromRoot, } from '../../util/urls.js'; @@ -245,12 +244,9 @@ export async function go({ } = urlToPageMap[pathnameKey]; const to = getURLsFrom({ - urls, baseDirectory, pagePath: servePath, - subdirectoryPrefix: getPageSubdirectoryPrefix({ - pagePath: servePath, - }), + urls, }); const absoluteTo = getURLsFromRoot({ diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 5141891c..23c6470a 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -28,7 +28,6 @@ import { import { getPagePathname, getPagePathnameAcrossLanguages, - getPageSubdirectoryPrefix, getURLsFrom, getURLsFromRoot, } from '../../util/urls.js'; @@ -281,12 +280,9 @@ export async function go({ }); const to = getURLsFrom({ - urls, baseDirectory, pagePath, - subdirectoryPrefix: getPageSubdirectoryPrefix({ - pagePath, - }), + urls, }); const absoluteTo = getURLsFromRoot({ @@ -351,12 +347,9 @@ export async function go({ }); const to = getURLsFrom({ - urls, baseDirectory, pagePath: fromPath, - subdirectoryPrefix: getPageSubdirectoryPrefix({ - pagePath: fromPath, - }), + urls, }); const target = to('localized.' + toPath[0], ...toPath.slice(1)); -- cgit 1.3.0-6-gf8a5 From c09e733544f8f47850532aecee4d14887ffd83db Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:39:21 -0400 Subject: remove unused arg from getFooterLocalizationLinks eslint didn't warn about this ???????????? --- src/write/page-template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/write') diff --git a/src/write/page-template.js b/src/write/page-template.js index 7c2f0c66..0bf0a98e 100644 --- a/src/write/page-template.js +++ b/src/write/page-template.js @@ -163,7 +163,7 @@ export function generateDocumentHTML(pageInfo, { }, footer.content), - getFooterLocalizationLinks(pathname, { + getFooterLocalizationLinks({ defaultLanguage, html, language, -- cgit 1.3.0-6-gf8a5 From d0abc02e2cf6e5648d1e0c2833bb109fd4976e0e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:41:19 -0400 Subject: remove legacy navbar {href} handler this references pathname so it totally makes sense to include with other url/path-related changes --- src/write/page-template.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/write') diff --git a/src/write/page-template.js b/src/write/page-template.js index 0bf0a98e..6ed9fcf5 100644 --- a/src/write/page-template.js +++ b/src/write/page-template.js @@ -1,7 +1,6 @@ import chroma from 'chroma-js'; import * as html from '../util/html.js'; -import {logWarn} from '../util/cli.js'; import {getColors} from '../util/colors.js'; import { @@ -263,11 +262,6 @@ export function generateDocumentHTML(pageInfo, { ? to('localized.home') : cur.path ? to(...cur.path) - : cur.href - ? (() => { - logWarn`Using legacy href format nav link in ${pathname}`; - return cur.href; - })() : null, }; if (attributes.href === null) { -- cgit 1.3.0-6-gf8a5 From 7bca1c6b41f7df9a20dd73872c7b1e9653776485 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:43:57 -0400 Subject: indentation opinion --- src/write/build-modes/static-build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/write') diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 23c6470a..691ce579 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -309,7 +309,7 @@ export async function go({ const oEmbedJSONHref = oEmbedJSON && wikiData.wikiInfo.canonicalBase && - wikiData.wikiInfo.canonicalBase + + wikiData.wikiInfo.canonicalBase + urls .from('shared.root') .to('shared.path', pathname + 'oembed.json'); -- cgit 1.3.0-6-gf8a5 From 7f6d21d480e22765f438d5a80227f89c416b770b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 20:47:38 -0400 Subject: bind more language vars, pass to generateDocumentHTML --- src/write/bind-utilities.js | 4 ++++ src/write/build-modes/live-dev-server.js | 10 +++------- src/write/build-modes/static-build.js | 10 +++------- 3 files changed, 10 insertions(+), 14 deletions(-) (limited to 'src/write') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index 4b037a91..6212b824 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -52,8 +52,10 @@ import { export function bindUtilities({ absoluteTo, + defaultLanguage, getSizeOfAdditionalFile, language, + languages, to, urls, wikiData, @@ -65,9 +67,11 @@ export function bindUtilities({ Object.assign(bound, { absoluteTo, + defaultLanguage, getSizeOfAdditionalFile, html, language, + languages, to, urls, wikiData, diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index a4c4c871..0e2b6160 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -278,8 +278,10 @@ export async function go({ const bound = bindUtilities({ absoluteTo, + defaultLanguage, getSizeOfAdditionalFile, language, + languages, to, urls, wikiData, @@ -288,19 +290,13 @@ export async function go({ const pageInfo = page.page(bound); const pageHTML = generateDocumentHTML(pageInfo, { + ...bound, cachebust, - defaultLanguage, developersComment, - getThemeString: bound.getThemeString, - language, - languages, localizedPathnames, oEmbedJSONHref: null, // No oEmbed support for live dev server pagePath: servePath, pathname, - to, - transformMultiline: bound.transformMultiline, - wikiData, }); console.log(`${requestHead} [200] ${pathname}`); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 691ce579..220e51f4 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -292,8 +292,10 @@ export async function go({ const bound = bindUtilities({ absoluteTo, + defaultLanguage, getSizeOfAdditionalFile, language, + languages, to, urls, wikiData, @@ -315,19 +317,13 @@ export async function go({ .to('shared.path', pathname + 'oembed.json'); const pageHTML = generateDocumentHTML(pageInfo, { + ...bound, cachebust, - defaultLanguage, developersComment, - getThemeString: bound.getThemeString, - language, - languages, localizedPathnames, oEmbedJSONHref, pagePath, pathname, - to, - transformMultiline: bound.transformMultiline, - wikiData, }); return writePage({ -- cgit 1.3.0-6-gf8a5