diff options
| author | (quasar) nebula <qznebula@protonmail.com> | 2025-12-13 11:50:25 -0400 |
|---|---|---|
| committer | (quasar) nebula <qznebula@protonmail.com> | 2025-12-13 11:50:25 -0400 |
| commit | 9bffc4291c73c598bbad23b379ba268a23ca2660 (patch) | |
| tree | 72d97969636f8a2c4f0fb5981138e05cc66f3d6a /src/content/dependencies/generatePageTitleText.js | |
| parent | 0f45b260201f98b05dae1a18428b1a5619384c26 (diff) | |
client, content: sidebar-search: show where you started preview
Diffstat (limited to 'src/content/dependencies/generatePageTitleText.js')
| -rw-r--r-- | src/content/dependencies/generatePageTitleText.js | 67 |
1 files changed, 67 insertions, 0 deletions
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 + // &'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 |