diff options
author | Alan Pearce | 2017-07-02 16:22:35 +0200 |
---|---|---|
committer | Alan Pearce | 2017-07-02 16:22:35 +0200 |
commit | a67e38d1a82c95db5bd24183e81b31438f60dd2c (patch) | |
tree | 1773ff844074db76b82b31723b31d6c5006a7f01 | |
parent | 550562ec8b147439689bb3d4abdc406ace54a7db (diff) | |
download | homestead-a67e38d1a82c95db5bd24183e81b31438f60dd2c.tar.lz homestead-a67e38d1a82c95db5bd24183e81b31438f60dd2c.tar.zst homestead-a67e38d1a82c95db5bd24183e81b31438f60dd2c.zip |
feat: add configurable navigation
-rw-r--r-- | config/default.toml | 4 | ||||
-rw-r--r-- | src/responders.js | 6 | ||||
-rw-r--r-- | src/templates/layout.html | 5 | ||||
-rw-r--r-- | test/app.test.js | 2 | ||||
-rw-r--r-- | test/testsite/config.toml | 6 |
5 files changed, 22 insertions, 1 deletions
diff --git a/config/default.toml b/config/default.toml index 8683981..3b6ceb6 100644 --- a/config/default.toml +++ b/config/default.toml @@ -7,6 +7,10 @@ port = 3000 name = "John Doe" photo = "/static/johndoe.jpg" +[[site.nav]] +text = "Home" +url = "/" + [posts] folder = "./posts" diff --git a/src/responders.js b/src/responders.js index 867310a..48d1949 100644 --- a/src/responders.js +++ b/src/responders.js @@ -70,6 +70,12 @@ function layout(config, pageTitle, pageElement) { alt: config.site.author.name, src: config.site.author.photo }, + "header nav li": config.site.nav.map(l => ({ + a: { + href: l.url, + _text: l.text + } + })), "body > main": pageElement.outerHTML }).outerHTML.trim(); } diff --git a/src/templates/layout.html b/src/templates/layout.html index 6e32bb4..65fdede 100644 --- a/src/templates/layout.html +++ b/src/templates/layout.html @@ -10,6 +10,11 @@ <img class="u-photo" alt="" src="" /> <h1 class="p-name">hello world</h1> </a> + <nav> + <ul> + <li><a href="/">test link</a></li> + </ul> + </nav> </header> <main></main> </body> diff --git a/test/app.test.js b/test/app.test.js index dfba9f8..2445493 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -43,6 +43,8 @@ test("homepage", async function(t) { t.is($("head > title").text(), "John Doe", "head title is site author"); t.is($("main").length, 1, "only one <main> tag"); + t.is($("nav a").first().text(), "Home", "nav link has text"); + t.is($("nav a").first().attr("href"), "/", "nav links to homepage"); const options = toMicroformatsOptions($); const count = await mf.countAsync(options); diff --git a/test/testsite/config.toml b/test/testsite/config.toml index 1fbbb82..8f82937 100644 --- a/test/testsite/config.toml +++ b/test/testsite/config.toml @@ -1,2 +1,6 @@ [posts] -folder = "./posts" \ No newline at end of file +folder = "./posts" + +[[site.nav]] +text = "Home" +url = "/" \ No newline at end of file |