« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generatePageLayout.js53
-rw-r--r--src/content/dependencies/generatePageTitleText.js67
-rw-r--r--src/content/dependencies/generateSearchSidebarBox.js5
3 files changed, 86 insertions, 39 deletions
diff --git a/src/content/dependencies/generatePageLayout.js b/src/content/dependencies/generatePageLayout.js
index 23d5932d..fec3bd78 100644
--- a/src/content/dependencies/generatePageLayout.js
+++ b/src/content/dependencies/generatePageLayout.js
@@ -1,5 +1,3 @@
-import striptags from 'striptags';
-
 import {openAggregate} from '#aggregate';
 import {atOffset, empty, repeat} from '#sugar';
 
@@ -27,6 +25,9 @@ export default {
     relations.stickyHeadingContainer =
       relation('generateStickyHeadingContainer');
 
+    relations.titleText =
+      relation('generatePageTitleText');
+
     relations.sidebar =
       relation('generatePageSidebar');
 
@@ -629,6 +630,12 @@ export default {
       footerHTML,
     ];
 
+    relations.titleText.setSlots({
+      title: slots.title,
+      showWikiNameInTitle: slots.showWikiNameInTitle,
+      subtitle: slots.subtitle,
+    });
+
     const pageHTML = html.tags([
       `<!DOCTYPE html>`,
       html.tag('html',
@@ -653,44 +660,12 @@ export default {
 
           html.tag('head', [
             html.tag('title',
-              language.encapsulate('misc.pageTitle', workingCapsule => {
-                const workingOptions = {};
-
-                // Slightly jank: The output of striptags is, of course, a string,
-                // and as far as language.formatString() is concerned, that means
-                // it needs to be sanitized - including turning ampersands into
-                // &amp;'s. But the title is already HTML that has implicitly been
-                // sanitized, however it got here, and includes HTML entities that
-                // are properly escaped. Those need to get included as they are,
-                // so we wrap the title in a tag and pass it off as good to go.
-                workingOptions.title =
-                  html.tags([
-                    striptags(slots.title.toString()),
-                  ]);
-
-                if (!html.isBlank(slots.subtitle)) {
-                  // Same shenanigans here, as far as wrapping striptags goes.
-                  workingCapsule += '.withSubtitle';
-                  workingOptions.subtitle =
-                    html.tags([
-                      striptags(slots.subtitle.toString()),
-                    ]);
-                }
+              {'data-without-wiki-name':
+                relations.titleText.clone()
+                  .slot('showWikiNameInTitle', false)
+                  .toString()},
 
-                const showWikiName =
-                  (slots.showWikiNameInTitle === true
-                    ? true
-                 : slots.showWikiNameInTitle === 'auto'
-                    ? html.isBlank(slots.subtitle)
-                    : false);
-
-                if (showWikiName) {
-                  workingCapsule += '.withWikiName';
-                  workingOptions.wikiName = data.wikiName;
-                }
-
-                return language.$(workingCapsule, workingOptions);
-              })),
+              relations.titleText),
 
             html.tag('meta', {charset: 'utf-8'}),
             html.tag('meta', {
diff --git a/src/content/dependencies/generatePageTitleText.js b/src/content/dependencies/generatePageTitleText.js
new file mode 100644
index 00000000..5482ca91
--- /dev/null
+++ b/src/content/dependencies/generatePageTitleText.js
@@ -0,0 +1,67 @@
+import striptags from 'striptags';
+
+export default {
+  sprawl: ({wikiInfo}) => ({wikiInfo}),
+
+  data: (sprawl) => ({
+    wikiName:
+      sprawl.wikiInfo.nameShort,
+  }),
+
+  slots: {
+    title: {
+      type: 'html',
+      mutable: false,
+    },
+
+    showWikiNameInTitle: {
+      validate: v => v.is(true, false, 'auto'),
+      default: 'auto',
+    },
+
+    subtitle: {
+      type: 'html',
+      mutable: false,
+    },
+  },
+
+  generate: (data, slots, {html, language}) =>
+    language.encapsulate('misc.pageTitle', workingCapsule => {
+      const workingOptions = {};
+
+      // Slightly jank: The output of striptags is, of course, a string,
+      // and as far as language.formatString() is concerned, that means
+      // it needs to be sanitized - including turning ampersands into
+      // &amp;'s. But the title is already HTML that has implicitly been
+      // sanitized, however it got here, and includes HTML entities that
+      // are properly escaped. Those need to get included as they are,
+      // so we wrap the title in a tag and pass it off as good to go.
+      workingOptions.title =
+        html.tags([
+striptags(slots.title.toString()),
+        ]);
+
+      if (!html.isBlank(slots.subtitle)) {
+        // Same shenanigans here, as far as wrapping striptags goes.
+        workingCapsule += '.withSubtitle';
+        workingOptions.subtitle =
+          html.tags([
+            striptags(slots.subtitle.toString()),
+          ]);
+      }
+
+      const showWikiName =
+        (slots.showWikiNameInTitle === true
+? true
+       : slots.showWikiNameInTitle === 'auto'
+? html.isBlank(slots.subtitle)
+: false);
+
+      if (showWikiName) {
+        workingCapsule += '.withWikiName';
+        workingOptions.wikiName = data.wikiName;
+      }
+
+      return language.$(workingCapsule, workingOptions);
+    }),
+};
\ No newline at end of file
diff --git a/src/content/dependencies/generateSearchSidebarBox.js b/src/content/dependencies/generateSearchSidebarBox.js
index 701a01ac..0d760773 100644
--- a/src/content/dependencies/generateSearchSidebarBox.js
+++ b/src/content/dependencies/generateSearchSidebarBox.js
@@ -35,6 +35,11 @@ export default {
           html.tag('template', {class: 'wiki-search-no-results-string'},
             language.$(capsule, 'noResults')),
 
+          html.tag('template', {class: 'wiki-search-back-string'},
+            language.$(capsule, 'back', {
+              page: html.tag('slot', {name: 'page'}),
+            })),
+
           html.tag('template', {class: 'wiki-search-current-result-string'},
             language.$(capsule, 'currentResult')),