From 05865706da36f4f3f7c2d03df4065ffdd9911a69 Mon Sep 17 00:00:00 2001 From: cel Date: Mon, 28 Jan 2019 19:31:32 -1000 Subject: Make nav links configurable --- README.md | 18 ++++++++++++++++++ lib/app.js | 17 +++++++++++++++++ lib/serve.js | 31 ++++++++++--------------------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 335ee58..23a40d5 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,23 @@ To make config options persistent, set them in `~/.ssb/config`, e.g.: "showPrivates": true, "previewVotes": true, "ooo": true, + "nav": [ + "new", + "public", + "private", + "mentions", + "peers", + "status", + "channels", + "tags", + "friends", + "search" + "live", + "compose", + "emojis", + "self", + "searchbox" + ] } } ``` @@ -105,6 +122,7 @@ To make config options persistent, set them in `~/.ssb/config`, e.g.: - `previewContacts`: Whether to preview creating contact/(un)follow/block messages (`true`) or publish them immediately (`false`). default: `false` - `ooo`: if true, use `ssb-ooo` to try to fetch missing messages in threads. also can set per-request with query string `?ooo=1`. default: `false` `codeInTextareas`: if `true`, render markdown code blocks in textareas. if `false`, render them in `pre` tags. default: `false` +- `nav`: array of nav links. Each item may be a string, object or special value. Special values are `"searchbox"` and `"self"`, which are the search field box, and link to the current feed id's page, respectively. Any other string is interpretted to be a link to the page of that name prefixed with a forward slash. An object may have properties `name` and `url`, and that will be interpretted as a link with given name and URL (with `toUrl` conversions applied). default is the list in the readme above. ## TODO diff --git a/lib/app.js b/lib/app.js index 73b313d..e0b4417 100644 --- a/lib/app.js +++ b/lib/app.js @@ -79,6 +79,23 @@ function App(sbot, config) { this.serveSsbNpmRegistry = SsbNpmRegistry.respond(this.sbot, this.config) this.monitorBlobWants() + this.navLinks = conf.nav || [ + 'new', + 'public', + 'private', + 'mentions', + 'peers', + this.sbot.status && 'status', + 'channels', + 'tags', + 'friends', + 'search', + 'live', + 'compose', + 'emojis', + 'self', + 'searchbox' + ] } App.prototype.go = function () { diff --git a/lib/serve.js b/lib/serve.js index e4f2c9e..e3901a0 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1666,27 +1666,16 @@ Serve.prototype.wrapPage = function (title, searchQ) { ), h('body', h('nav.nav-bar', h('form', {action: render.toUrl('/search'), method: 'get'}, - h('a', {href: render.toUrl('/new')}, 'new') , ' ', - h('a', {href: render.toUrl('/public')}, 'public'), ' ', - h('a', {href: render.toUrl('/private')}, 'private') , ' ', - h('a', {href: render.toUrl('/mentions')}, 'mentions') , ' ', - h('a', {href: render.toUrl('/peers')}, 'peers') , ' ', - self.app.sbot.status ? - [h('a', {href: render.toUrl('/status')}, 'status'), ' '] : '', - h('a', {href: render.toUrl('/channels')}, 'channels') , ' ', - h('a', {href: render.toUrl('/tags')}, 'tags') , ' ', - h('a', {href: render.toUrl('/friends')}, 'friends'), ' ', - h('a', {href: render.toUrl('/advsearch')}, 'search'), ' ', - h('a', {href: render.toUrl('/live')}, 'live'), ' ', - h('a', {href: render.toUrl('/compose')}, 'compose'), ' ', - // h('a', {href: render.toUrl('/votes')}, 'votes'), ' ', - h('a', {href: render.toUrl('/emojis')}, 'emojis'), ' ', - render.idLink(self.app.sbot.id, done()), ' ', - h('input.search-input', {name: 'q', value: searchQ, - placeholder: 'search'}) - // h('a', {href: '/convos'}, 'convos'), ' ', - // h('a', {href: '/friends'}, 'friends'), ' ', - // h('a', {href: '/git'}, 'git') + self.app.navLinks.map(function (link, i) { + return [i == 0 ? '' : ' ', + link === 'self' ? render.idLink(self.app.sbot.id, done()) : + link === 'searchbox' ? h('input.search-input', + {name: 'q', value: searchQ, placeholder: 'search'}) : + link === 'search' ? h('a', {href: render.toUrl('/advsearch')}, 'search') : + typeof link === 'string' ? h('a', {href: render.toUrl('/' + link)}, link) : + link ? h('a', {href: render.toUrl(link.url)}, link.name) : '' + ] + }) )), self.publishedMsg ? h('div', 'published ', -- cgit v1.2.3