From f8e4c8e3ffc6da224699db15d13a02ed8b4e49e5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 3 Feb 2022 21:27:21 -0400 Subject: static page data --- src/thing/static-page.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/upd8.js | 45 +++++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 src/thing/static-page.js diff --git a/src/thing/static-page.js b/src/thing/static-page.js new file mode 100644 index 0000000..18e9d14 --- /dev/null +++ b/src/thing/static-page.js @@ -0,0 +1,52 @@ +import Thing from './thing.js'; + +import { + isBoolean, + isDirectory, + isName, + isString, +} from './validators.js'; + +export default class StaticPage extends Thing { + static [Thing.referenceType] = 'static'; + + static propertyDescriptors = { + // Update & expose + + name: { + flags: {update: true, expose: true}, + update: {validate: isName} + }, + + nameShort: { + flags: {update: true, expose: true}, + update: {validate: isName}, + + expose: { + dependencies: ['name'], + transform: (value, { name }) => value ?? name + } + }, + + directory: { + flags: {update: true, expose: true}, + update: {validate: isDirectory}, + expose: Thing.directoryExpose + }, + + content: { + flags: {update: true, expose: true}, + update: {validate: isString} + }, + + stylesheet: { + flags: {update: true, expose: true}, + update: {validate: isString} + }, + + showInNavigationBar: { + flags: {update: true, expose: true}, + update: {validate: isBoolean, default: true} + }, + }; +} diff --git a/src/upd8.js b/src/upd8.js index 0ea998a..e9c582c 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -100,6 +100,7 @@ import HomepageLayout, { HomepageLayoutAlbumsRow, } from './thing/homepage-layout.js'; import NewsEntry from './thing/news-entry.js'; +import StaticPage from './thing/static-page.js'; import Thing from './thing/thing.js'; import Track from './thing/track.js'; @@ -209,7 +210,7 @@ const FLASH_DATA_FILE = 'flashes.yaml'; const NEWS_DATA_FILE = 'news.yaml'; const ART_TAG_DATA_FILE = 'tags.yaml'; const GROUP_DATA_FILE = 'groups.yaml'; -const STATIC_PAGE_DATA_FILE = 'static-pages.txt'; +const STATIC_PAGE_DATA_FILE = 'static-pages.yaml'; const DEFAULT_STRINGS_FILE = 'strings-default.json'; // Code that's common 8etween the 8uild code (i.e. upd8.js) and gener8ted @@ -1188,6 +1189,19 @@ async function processGroupDataFile(file) { }); } +const processStaticPageDocument = makeProcessDocument(StaticPage, { + propertyFieldMapping: { + name: 'Name', + nameShort: 'Short Name', + directory: 'Directory', + + content: 'Content', + stylesheet: 'Style', + + showInNavigationBar: 'Show in Navigation Bar' + } +}); + async function processStaticPageDataFile(file) { let contents; try { @@ -2566,6 +2580,18 @@ async function main() { wikiData.tagData = results; } }, + + { + title: `Process static pages file`, + files: [path.join(dataPath, STATIC_PAGE_DATA_FILE)], + + documentMode: documentModes.allInOne, + processDocument: processStaticPageDocument, + + save(results) { + wikiData.staticPageData = results; + } + }, ]; const processDataAggregate = openAggregate({message: `Errors processing data files`}); @@ -2713,6 +2739,7 @@ async function main() { logInfo` - ${wikiData.tagData.length} art tags`; if (wikiData.newsData) logInfo` - ${wikiData.newsData.length} news entries`; + logInfo` - ${wikiData.staticPageData.length} static pages`; if (wikiData.homepageLayout) logInfo` - ${1} homepage layout (${wikiData.homepageLayout.rows.length} rows)`; } catch (error) { @@ -2739,22 +2766,6 @@ async function main() { process.exit(); - WD.staticPageData = await processStaticPageDataFile(path.join(dataPath, STATIC_PAGE_DATA_FILE)); - if (WD.staticPageData.error) { - console.log(`\x1b[31;1m${WD.staticPageData.error}\x1b[0m`); - return; - } - - { - const errors = WD.staticPageData.filter(obj => obj.error); - if (errors.length) { - for (const error of errors) { - console.log(`\x1b[31;1m${error.error}\x1b[0m`); - } - return; - } - } - { const tagNames = new Set([...WD.trackData, ...WD.albumData].flatMap(thing => thing.artTags)); -- cgit 1.3.0-6-gf8a5