« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generatePreviousNextLinks.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generatePreviousNextLinks.js')
-rw-r--r--src/content/dependencies/generatePreviousNextLinks.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/content/dependencies/generatePreviousNextLinks.js b/src/content/dependencies/generatePreviousNextLinks.js
new file mode 100644
index 0000000..9771de3
--- /dev/null
+++ b/src/content/dependencies/generatePreviousNextLinks.js
@@ -0,0 +1,50 @@
+export default {
+  // Returns an array with the slotted previous and next links, prepared
+  // for inclusion in a page's navigation bar. Include with other links
+  // in the nav bar and then join them all as a unit list, for example.
+
+  extraDependencies: ['html', 'language'],
+
+  slots: {
+    previousLink: {
+      type: 'html',
+      mutable: true,
+    },
+
+    nextLink: {
+      type: 'html',
+      mutable: true,
+    },
+
+    id: {
+      type: 'boolean',
+      default: true,
+    },
+  },
+
+  generate(slots, {html, language}) {
+    const previousNext = [];
+
+    if (!html.isBlank(slots.previousLink)) {
+      previousNext.push(
+        slots.previousLink.slots({
+          tooltipStyle: 'browser',
+          color: false,
+          attributes: {id: slots.id && 'previous-button'},
+          content: language.$('misc.nav.previous'),
+        }));
+    }
+
+    if (!html.isBlank(slots.nextLink)) {
+      previousNext.push(
+        slots.nextLink.slots({
+          tooltipStyle: 'browser',
+          color: false,
+          attributes: {id: slots.id && 'next-button'},
+          content: language.$('misc.nav.next'),
+        }));
+    }
+
+    return previousNext;
+  },
+};