From ca4e9b3fd53f91e1cd95c8aa20496177ec39d669 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 26 Jan 2026 13:11:03 -0400 Subject: infra: rename singleton-export thing modules --- src/data/things/NewsEntry.js | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/data/things/NewsEntry.js (limited to 'src/data/things/NewsEntry.js') diff --git a/src/data/things/NewsEntry.js b/src/data/things/NewsEntry.js new file mode 100644 index 00000000..65fd125b --- /dev/null +++ b/src/data/things/NewsEntry.js @@ -0,0 +1,76 @@ +const NEWS_DATA_FILE = 'news.yaml'; + +import {V} from '#composite'; +import {sortChronologically} from '#sort'; +import Thing from '#thing'; +import {parseDate} from '#yaml'; + +import {exposeConstant} from '#composite/control-flow'; +import {contentString, directory, name, simpleDate} + from '#composite/wiki-properties'; + +export class NewsEntry extends Thing { + static [Thing.referenceType] = 'news-entry'; + static [Thing.friendlyName] = `News Entry`; + static [Thing.wikiData] = 'newsData'; + + static [Thing.getPropertyDescriptors] = () => ({ + // Update & expose + + name: name(V('Unnamed News Entry')), + directory: directory(), + date: simpleDate(), + + content: contentString(), + + // Expose only + + isNewsEntry: exposeConstant(V(true)), + + contentShort: { + flags: {expose: true}, + + expose: { + dependencies: ['content'], + + compute: ({content}) => content.split('
')[0], + }, + }, + }); + + static [Thing.findSpecs] = { + newsEntry: { + referenceTypes: ['news-entry'], + bindTo: 'newsData', + }, + }; + + static [Thing.yamlDocumentSpec] = { + fields: { + 'Name': {property: 'name'}, + 'Directory': {property: 'directory'}, + + 'Date': { + property: 'date', + transform: parseDate, + }, + + 'Content': {property: 'content'}, + }, + }; + + static [Thing.getYamlLoadingSpec] = ({ + documentModes: {allInOne}, + thingConstructors: {NewsEntry}, + }) => ({ + title: `Process news data file`, + file: NEWS_DATA_FILE, + + documentMode: allInOne, + documentThing: NewsEntry, + + sort({newsData}) { + sortChronologically(newsData, {latestFirst: true}); + }, + }); +} -- cgit 1.3.0-6-gf8a5