diff options
author | guangmean <angularcorp@outlook.com> | 2019-04-08 12:37:55 +0300 |
---|---|---|
committer | guangmean <angularcorp@outlook.com> | 2019-04-08 12:37:55 +0300 |
commit | 8b6eda593cf5f70ab267e748953d53cb528c85f8 (patch) | |
tree | 6ab94260a92eeb4ae8123f5b267c6e8f6c255c11 | |
parent | c73fe02f648c11a55a649cc6536b0e9618392c2f (diff) |
Support custom navigation menu1.0
Sort menu by weight asc from left to right
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | layouts/index.html | 4 | ||||
-rw-r--r-- | layouts/partials/nav.html | 17 | ||||
-rw-r--r-- | layouts/post/single.html | 5 |
4 files changed, 31 insertions, 7 deletions
@@ -44,6 +44,18 @@ description = "" copyright = "© 2019 by guangmean. All Rights Reserved." google_ad_client = "ca-pub-******" ga = "UA-******" + +[menu] + [[menu.niello]] + name = "Home" + url = "/" + weight = 1 + + [[menu.niello]] + name = "Contact" + url = "/post/contact/" + weight = 2 + ``` # Google Adsense & Google Analytics diff --git a/layouts/index.html b/layouts/index.html index c9eaf77..4d7f321 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -15,9 +15,7 @@ <div class="logo"> <h1><a href="/">{{.Title}}</a></h1> </div> - <div class="navigation"> - <a href="/" class="current">HOME</a> - </div> + {{ partial "nav.html" . }} <div> {{ range (.Paginate ( first 100 .Pages.ByPublishDate.Reverse )).Pages }} <article> diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html new file mode 100644 index 0000000..d9fd151 --- /dev/null +++ b/layouts/partials/nav.html @@ -0,0 +1,17 @@ +<div class="navigation"> + {{ if .Site.Menus.niello }} + {{ $inNav := 0 }} + {{ $currentPage := .RelPermalink }} + {{ range sort .Site.Menus.niello "Weight" "asc" }} + <a href="{{ .URL }}" class="{{ if eq $currentPage .URL }} {{ $inNav = 1 }}current{{ end}}">{{ .Name }}</a> + {{ end }} + {{ if eq $inNav 0 }} + <a href="javascript:void(0);" class="current">ARTICLE</a> + {{ end }} + {{ else if eq .IsHome true }} + <a href="/" class="current">HOME</a> + {{ else }} + <a href="/" class="">HOME</a> + <a href="javascript:void(0);" class="current">ARTICLE</a> + {{ end }} +</div> diff --git a/layouts/post/single.html b/layouts/post/single.html index 608830a..4d2dd17 100644 --- a/layouts/post/single.html +++ b/layouts/post/single.html @@ -15,10 +15,7 @@ <div class="logo"> <h1><a href="/">{{.Site.Title}}</a></h1> </div> - <div class="navigation"> - <a href="/">HOME</a> - <a href="/" class="current">ARTICLE</a> - </div> + {{ partial "nav.html" . }} <div> <article> <h3>{{ .Title }}</h3> |