diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-01-01 17:43:35 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-01-01 17:43:35 -0400 |
commit | a312b897e99251ff9d53014dbb86c7a3b7b6609c (patch) | |
tree | 46aa97345bd6d4905988d052c0d3271abc65b39a | |
parent | 2fb4acd20a5b311e5f3f8581eb58687ed9cc2d1f (diff) |
specify homepage navbar links & order in data
...rather than just making a guess off the order files are listed by directory access, and using out-of-place 'Show in Navigation Bar'
-rw-r--r-- | src/data/things/homepage-layout.js | 6 | ||||
-rw-r--r-- | src/data/things/static-page.js | 1 | ||||
-rw-r--r-- | src/data/yaml.js | 5 | ||||
-rw-r--r-- | src/page/homepage.js | 31 | ||||
-rw-r--r-- | src/util/link.js | 6 |
5 files changed, 29 insertions, 20 deletions
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js index 344716cb..c18e8110 100644 --- a/src/data/things/homepage-layout.js +++ b/src/data/things/homepage-layout.js @@ -7,6 +7,7 @@ export class HomepageLayout extends Thing { HomepageLayoutRow, validators: { + isStringNonEmpty, validateArrayItems, validateInstanceOf, }, @@ -15,6 +16,11 @@ export class HomepageLayout extends Thing { sidebarContent: Thing.common.simpleString(), + navbarLinks: { + flags: {update: true, expose: true}, + update: {validate: validateArrayItems(isStringNonEmpty)}, + }, + rows: { flags: {update: true, expose: true}, diff --git a/src/data/things/static-page.js b/src/data/things/static-page.js index 226e0b61..3d8d474c 100644 --- a/src/data/things/static-page.js +++ b/src/data/things/static-page.js @@ -25,6 +25,5 @@ export class StaticPage extends Thing { directory: Thing.common.directory(), content: Thing.common.simpleString(), stylesheet: Thing.common.simpleString(), - showInNavigationBar: Thing.common.flag(true), }); } diff --git a/src/data/yaml.js b/src/data/yaml.js index 6ddd3a13..02e56d64 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -377,8 +377,6 @@ export const processStaticPageDocument = makeProcessDocument(T.StaticPage, { content: 'Content', stylesheet: 'Style', - - showInNavigationBar: 'Show in Navigation Bar', }, }); @@ -403,6 +401,7 @@ export const processWikiInfoDocument = makeProcessDocument(T.WikiInfo, { export const processHomepageLayoutDocument = makeProcessDocument(T.HomepageLayout, { propertyFieldMapping: { sidebarContent: 'Sidebar Content', + navbarLinks: 'Navbar Links', }, ignoredFields: ['Homepage'], @@ -896,6 +895,8 @@ export const dataSteps = [ processDocument: processStaticPageDocument, save(staticPageData) { + sortAlphabetically(staticPageData); + return {staticPageData}; }, }, diff --git a/src/page/homepage.js b/src/page/homepage.js index d34f117b..882daf72 100644 --- a/src/page/homepage.js +++ b/src/page/homepage.js @@ -1,6 +1,10 @@ // Homepage specification. -import {empty} from '../util/sugar.js'; +import { + bindOpts, + empty, + withEntries, +} from '../util/sugar.js'; import { getNewAdditions, @@ -193,21 +197,16 @@ export function writeTargetless({wikiData}) { links: [ link.home('', {text: wikiInfo.nameShort, class: 'current', to}), - wikiInfo.enableListings && - link.listingIndex('', { - text: language.$('listingIndex.title'), - to, - }), - - wikiInfo.enableNews && - link.newsIndex('', {text: language.$('newsIndex.title'), to}), - - wikiInfo.enableFlashesAndGames && - link.flashIndex('', {text: language.$('flashIndex.title'), to}), - - ...staticPageData - .filter((page) => page.showInNavigationBar) - .map((page) => link.staticPage(page, {text: page.nameShort})), + ...html.fragment( + homepageLayout.navbarLinks?.map(text => + transformInline(text, { + link: + withEntries(link, entries => + entries.map(([key, fn]) => + [key, bindOpts(fn, { + preferShortName: true, + })])), + }))), ] .filter(Boolean) .map((html) => ({html})), diff --git a/src/util/link.js b/src/util/link.js index 7d53edc3..e692255a 100644 --- a/src/util/link.js +++ b/src/util/link.js @@ -38,6 +38,7 @@ const linkHelper = class: className = '', color: color2 = true, hash = '', + preferShortName = false, }) => { let href = hrefFn(thing, {to}); @@ -65,7 +66,10 @@ const linkHelper = : '', class: className, }, - text || thing.name + (text || + (preferShortName + ? thing.nameShort ?? thing.name + : thing.name)) ); }; |