From 3cd6f9edc58171e33ed6af565db84113e2488f25 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 9 Oct 2023 14:58:14 -0300 Subject: data: language: allow passing multiple key parts directly --- src/data/things/language.js | 66 ++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src/data') diff --git a/src/data/things/language.js b/src/data/things/language.js index fe74f7bf..646eb6d1 100644 --- a/src/data/things/language.js +++ b/src/data/things/language.js @@ -101,6 +101,7 @@ export class Language extends Thing { }, }, + // TODO: This currently isn't used. Is it still needed? strings_htmlEscaped: { flags: {expose: true}, expose: { @@ -130,8 +131,8 @@ export class Language extends Thing { }; } - $(key, args = {}) { - return this.formatString(key, args); + $(...args) { + return this.formatString(...args); } assertIntlAvailable(property) { @@ -145,8 +146,20 @@ export class Language extends Thing { return this.intl_pluralCardinal.select(value); } - formatString(key, args = {}) { - const strings = this.strings_htmlEscaped; + formatString(...args) { + const hasOptions = + typeof args.at(-1) === 'object' && + args.at(-1) !== null; + + const key = + (hasOptions ? args.slice(0, -1) : args) + .filter(Boolean) + .join('.'); + + const options = + (hasOptions + ? args.at(-1) + : null); if (!this.strings) { throw new Error(`Strings unavailable`); @@ -158,27 +171,36 @@ export class Language extends Thing { const template = this.strings[key]; - // Convert the keys on the args dict from camelCase to CONSTANT_CASE. - // (This isn't an OUTRAGEOUSLY versatile algorithm for doing that, 8ut - // like, who cares, dude?) Also, this is an array, 8ecause it's handy - // for the iterating we're a8out to do. Also strip HTML from arguments - // that are literal strings - real HTML content should always be proper - // HTML objects (see html.js). - const processedArgs = - Object.entries(args).map(([k, v]) => [ - k.replace(/[A-Z]/g, '_$&').toUpperCase(), - this.#sanitizeStringArg(v), - ]); - - // Replacement time! Woot. Reduce comes in handy here! - const output = - processedArgs.reduce( - (x, [k, v]) => x.replaceAll(`{${k}}`, v), - template); + let output; + + if (hasOptions) { + // Convert the keys on the options dict from camelCase to CONSTANT_CASE. + // (This isn't an OUTRAGEOUSLY versatile algorithm for doing that, 8ut + // like, who cares, dude?) Also, this is an array, 8ecause it's handy + // for the iterating we're a8out to do. Also strip HTML from arguments + // that are literal strings - real HTML content should always be proper + // HTML objects (see html.js). + const processedOptions = + Object.entries(options).map(([k, v]) => [ + k.replace(/[A-Z]/g, '_$&').toUpperCase(), + this.#sanitizeStringArg(v), + ]); + + // Replacement time! Woot. Reduce comes in handy here! + output = + processedOptions.reduce( + (x, [k, v]) => x.replaceAll(`{${k}}`, v), + template); + } else { + // Without any options provided, just use the template as-is. This will + // still error if the template expected arguments, and otherwise will be + // the right value. + output = template; + } // Post-processing: if any expected arguments *weren't* replaced, that // is almost definitely an error. - if (output.match(/\{[A-Z_]+\}/)) { + if (output.match(/\{[A-Z][A-Z0-9_]*\}/)) { throw new Error(`Args in ${key} were missing - output: ${output}`); } -- cgit 1.3.0-6-gf8a5 From 3a871cf43a11b87392d26320c736b516925da684 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Oct 2023 14:32:28 -0300 Subject: implement flash act pages, rework flash sidebar layout --- src/data/things/flash.js | 6 +++++- src/data/yaml.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/data') diff --git a/src/data/things/flash.js b/src/data/things/flash.js index 8fb1edfa..52e30f88 100644 --- a/src/data/things/flash.js +++ b/src/data/things/flash.js @@ -12,6 +12,7 @@ import { import { color, contributionList, + directory, fileExtension, name, referenceList, @@ -117,12 +118,15 @@ export class Flash extends Thing { } export class FlashAct extends Thing { + static [Thing.referenceType] = 'flash-act'; + static [Thing.getPropertyDescriptors] = () => ({ // Update & expose name: name('Unnamed Flash Act'), + directory: directory(), color: color(), - anchor: simpleString(), + jump: simpleString(), jumpColor: { diff --git a/src/data/yaml.js b/src/data/yaml.js index c799be5f..0ecc1f1e 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -434,8 +434,10 @@ export const processFlashDocument = makeProcessDocument(T.Flash, { export const processFlashActDocument = makeProcessDocument(T.FlashAct, { propertyFieldMapping: { name: 'Act', + directory: 'Directory', + color: 'Color', - anchor: 'Anchor', + jump: 'Jump', jumpColor: 'Jump Color', }, -- cgit 1.3.0-6-gf8a5 From e842ce93e6405334b6ef475ec1db41e051cfd2b5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Oct 2023 14:49:43 -0300 Subject: data: use flash act directory for better determinism --- src/data/yaml.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/data') diff --git a/src/data/yaml.js b/src/data/yaml.js index 0ecc1f1e..a2811d43 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -1391,6 +1391,7 @@ export function filterDuplicateDirectories(wikiData) { 'albumData', 'artTagData', 'flashData', + 'flashActData', 'groupData', 'newsData', 'trackData', -- cgit 1.3.0-6-gf8a5