浏览代码

Rewrite code for menu

Track3 6 年之前
父节点
当前提交
aafc33b013
共有 3 个文件被更改,包括 23 次插入18 次删除
  1. 16 12
      config.toml
  2. 2 2
      layouts/index.html
  3. 5 4
      layouts/partials/header.html

+ 16 - 12
config.toml

@@ -10,7 +10,7 @@ pygmentsUseClasses  = true
 hasCJKLanguage = true
 
 [blackfriday]
-hrefTargetBlank = true
+  hrefTargetBlank = true
 
 [author]
   name = "Track3"
@@ -20,21 +20,25 @@ hrefTargetBlank = true
   category = ""
 
 [params]
-  author = "Track3"
-
+  author         = "Track3"
   dateform       = "Jan 02, 2006"
   dateformFull   = "2006-01-02 15:04"
   dateformList   = "Jan 2"
   dateformSingle = "Mon, Jan 2"
 
-[[params.mainMenu]]
-  link = "/posts/"
-  text = "Posts"
+[menu]
+
+  [[menu.main]]
+    name = "Posts"
+    url = "/posts/"
+    weight = 10
 
-[[params.mainMenu]]
-  link = "/friends/"
-  text = "Friends"
+  [[menu.main]]
+    name = "Friends"
+    url = "/friends/"
+    weight = 20
 
-[[params.mainMenu]]
-  link = "/about/"
-  text = "About"
+  [[menu.main]]
+    name = "About"
+    url = "/about/"
+    weight = 30

+ 2 - 2
layouts/index.html

@@ -7,8 +7,8 @@
 			<a href="https://github.com/Track3" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-github"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path></svg></a>
 		</div>
 		<nav id="home-nav" class="site-nav animated bounceIn">
-			{{- range .Site.Params.mainMenu }}
-			<a href="{{ .link }}">{{ .text }}</a>
+			{{- range .Site.Menus.main }}
+			<a href="{{ .URL }}">{{ .Name }}</a>
 			{{- end }}
 		</nav>
 	</div>

+ 5 - 4
layouts/partials/header.html

@@ -5,8 +5,9 @@
 					<a href="{{.Site.BaseURL}}">{{ .Site.Title }}</a>
 				</div>
 				<nav class="site-nav hide-in-mobile">
-					{{- range .Site.Params.mainMenu }}
-					<a href="{{ .link }}">{{ .text }}</a>
+					{{- $currentPage := . }}
+					{{- range .Site.Menus.main }}
+					<a href="{{ .URL }}">{{ .Name }}</a>
 					{{- end }}
 				</nav>
 			</div>
@@ -27,8 +28,8 @@
 	</header>
 	<div id="mobile-menu" class="animated bounceInRight" style="display: none;">
 		<ul >
-			{{- range .Site.Params.mainMenu }}
-			<li><a href="{{ .link }}">{{ .text }}</a></li>
+			{{- range .Site.Menus.main }}
+			<li><a href="{{ .URL }}">{{ .Name }}</a></li>
 			{{- end }}
 		</ul>
 	</div>