Simpli/unification
This commit is contained in:
parent
34a26c8051
commit
4aee87d427
5 changed files with 69 additions and 79 deletions
|
@ -13,8 +13,8 @@ import ssr from "choo-ssr";
|
||||||
|
|
||||||
// V A R I A B L E S
|
// V A R I A B L E S
|
||||||
|
|
||||||
const head = local("app/components/head");
|
const head = local("app/components/head").default;
|
||||||
const wrapper = local("app/components/wrapper");
|
const wrapper = local("app/components/wrapper").default;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ let title = "";
|
||||||
|
|
||||||
// E X P O R T
|
// E X P O R T
|
||||||
|
|
||||||
module.exports = exports = (state, emit) => {
|
export default (state, emit) => {
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case (state.route !== "/" && state.params.wildcard):
|
case (state.route !== "/" && state.params.wildcard):
|
||||||
title = `${state.params.wildcard.capitalize()} ∙ LBRY ∙ ${config.meta.tagline}`;
|
title = `${state.params.wildcard.capitalize()} ∙ LBRY ∙ ${config.meta.tagline}`;
|
||||||
|
|
|
@ -5,79 +5,72 @@
|
||||||
// P A C K A G E S
|
// P A C K A G E S
|
||||||
|
|
||||||
import html from "choo/html";
|
import html from "choo/html";
|
||||||
import Nanocomponent from "nanocomponent";
|
|
||||||
import xtend from "xtend";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// E X P O R T
|
// E X P O R T
|
||||||
|
|
||||||
export default class Navigation extends Nanocomponent {
|
export default currentUrl => {
|
||||||
constructor() {
|
const links = [
|
||||||
super();
|
{
|
||||||
|
name: "LBRY.io",
|
||||||
this.state = {
|
title: "Escape the techno scene",
|
||||||
active: true,
|
url: "https://lbry.io"
|
||||||
links: [
|
},
|
||||||
{
|
{
|
||||||
name: "LBRY.io",
|
name: "Overview",
|
||||||
title: "Escape the techno scene",
|
title: "LBRY overview",
|
||||||
url: "https://lbry.io"
|
url: "/overview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Overview",
|
name: "Playground",
|
||||||
title: "LBRY overview",
|
title: "Experience LBRY",
|
||||||
url: "/overview"
|
url: "/playground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Playground",
|
name: "Resources",
|
||||||
title: "Experience LBRY",
|
title: "View LBRY resources",
|
||||||
url: "/playground"
|
url: "/resources"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Resources",
|
name: "Community",
|
||||||
title: "View LBRY resources",
|
title: "Interact with LBRY",
|
||||||
url: "/resources"
|
url: "/community"
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Community",
|
|
||||||
title: "Interact with LBRY",
|
|
||||||
url: "/community"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
this.renderLink = this.renderLink.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
createElement(props) {
|
|
||||||
this.state = xtend(this.state, props);
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<nav class="navigation">
|
|
||||||
<div class="inner-wrap">
|
|
||||||
<a class="navigation__item logo" href="/" title="LBRY homepage">Home</a>
|
|
||||||
${this.state.links.map(this.renderLink)}
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderLink(props, i, arr) { // eslint-disable-line
|
|
||||||
let activeClass;
|
|
||||||
|
|
||||||
if (this.state.href === "/" && props.url === "/") {
|
|
||||||
activeClass = true;
|
|
||||||
} else if (props.url !== "/" && this.state.href.indexOf(props.url) >= 0) {
|
|
||||||
activeClass = true;
|
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<a
|
<nav class="navigation">
|
||||||
class="navigation__item${activeClass ? " active" : ""}"
|
<div class="inner-wrap">
|
||||||
href="${props.url}"
|
<a class="navigation__item logo" href="/" title="LBRY homepage">Home</a>
|
||||||
title="${props.title}"
|
${links.map(link => renderLink(currentUrl, link))}
|
||||||
>${props.name}</a>
|
</div>
|
||||||
`;
|
</nav>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// H E L P E R
|
||||||
|
|
||||||
|
function renderLink(href, link) {
|
||||||
|
let activeClass;
|
||||||
|
|
||||||
|
switch(true) {
|
||||||
|
case (link.url !== "/" && href.indexOf(link.url) >= 0):
|
||||||
|
activeClass = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
activeClass = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<a
|
||||||
|
class="navigation__item${activeClass ? " active" : ""}"
|
||||||
|
href="${link.url}"
|
||||||
|
title="${link.title}"
|
||||||
|
>${link.name}</a>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,26 +5,25 @@
|
||||||
// P A C K A G E
|
// P A C K A G E
|
||||||
|
|
||||||
import asyncHtml from "choo-async/html";
|
import asyncHtml from "choo-async/html";
|
||||||
|
import { require as local } from "app-root-path";
|
||||||
|
|
||||||
// V A R I A B L E S
|
// V A R I A B L E S
|
||||||
|
|
||||||
import footer from "./footer";
|
const footer = local("app/components/footer").default;
|
||||||
import Navigation from "./navigation";
|
const navigation = local("app/components/navigation").default;
|
||||||
|
|
||||||
const navigation = new Navigation();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// E X P O R T
|
// E X P O R T
|
||||||
|
|
||||||
module.exports = exports = children => (state, emit) => asyncHtml`
|
export default children => (state, emit) => asyncHtml`
|
||||||
<main>
|
<main>
|
||||||
<noscript>
|
<noscript>
|
||||||
<p>LBRY is quite fancy and relies on a bit of JavaScript to do these fancy things.</p>
|
<p>LBRY is quite fancy and relies on a bit of JavaScript to do these fancy things.</p>
|
||||||
<p>Please enable it, if you can.</p>
|
<p>Please enable it, if you can.</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
|
|
||||||
${navigation.render({ href: state.href || "/" })}
|
${navigation(state.href)}
|
||||||
<aside class="flashes" id="flash-container"></aside>
|
<aside class="flashes" id="flash-container"></aside>
|
||||||
${children(state, emit)}
|
${children(state, emit)}
|
||||||
${footer(state, emit)}
|
${footer(state, emit)}
|
||||||
|
|
|
@ -32,15 +32,13 @@
|
||||||
"make-promises-safe": "^1.1.0",
|
"make-promises-safe": "^1.1.0",
|
||||||
"markdown-it": "^8.4.2",
|
"markdown-it": "^8.4.2",
|
||||||
"markdown-it-anchor": "^5.0.2",
|
"markdown-it-anchor": "^5.0.2",
|
||||||
"nanocomponent": "^6.5.2",
|
|
||||||
"prismjs": "^1.15.0",
|
"prismjs": "^1.15.0",
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"request-promise-native": "^1.0.5",
|
"request-promise-native": "^1.0.5",
|
||||||
"slack-node": "^0.1.8",
|
"slack-node": "^0.1.8",
|
||||||
"socket.io": "^2.1.1",
|
"socket.io": "^2.1.1",
|
||||||
"stringify-object": "^3.2.2",
|
"stringify-object": "^3.2.2"
|
||||||
"xtend": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"description": "Documentation for the LBRY protocol and associated projects",
|
"description": "Documentation for the LBRY protocol and associated projects",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in a new issue