« get me outta code hell

Merge branch 'preview' into news-tweaks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAbsoluteDatetimestamp.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-03 17:55:58 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-03 17:55:58 -0400
commit11493b1a70c26d9aa11b98acf93b4d09d89f88bf (patch)
treefe062bc0b32698c3af6c41f4c7043dc1afb09b92 /src/content/dependencies/generateAbsoluteDatetimestamp.js
parent213bddbd9851ee01f256835b1bca0c4bc0cf5fc6 (diff)
parent7039d7fa471318df40c1905cd5ac52688dc6adcf (diff)
Merge branch 'preview' into news-tweaks
Diffstat (limited to 'src/content/dependencies/generateAbsoluteDatetimestamp.js')
-rw-r--r--src/content/dependencies/generateAbsoluteDatetimestamp.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/content/dependencies/generateAbsoluteDatetimestamp.js b/src/content/dependencies/generateAbsoluteDatetimestamp.js
new file mode 100644
index 00000000..63acecf2
--- /dev/null
+++ b/src/content/dependencies/generateAbsoluteDatetimestamp.js
@@ -0,0 +1,41 @@
+export default {
+  contentDependencies: ['generateDatetimestampTemplate'],
+  extraDependencies: ['html', 'language'],
+
+  data: (date) =>
+    ({date}),
+
+  relations: (relation) =>
+    ({template: relation('generateDatetimestampTemplate')}),
+
+  slots: {
+    style: {
+      validate: v => v.is('full', 'year'),
+      default: 'full',
+    },
+
+    // Only has an effect for 'year' style.
+    tooltip: {
+      type: 'boolean',
+      default: false,
+    },
+  },
+
+  generate: (data, relations, slots, {language}) =>
+    relations.template.slots({
+      mainContent:
+        (slots.style === 'full'
+          ? language.formatDate(data.date)
+       : slots.style === 'year'
+          ? data.date.getFullYear().toString()
+          : null),
+
+      tooltipContent:
+        slots.tooltip &&
+        slots.style === 'year' &&
+          language.formatDate(data.date),
+
+      datetime:
+        data.date.toISOString(),
+    }),
+};