diff options
author | key-amb <yasutake.kiyoshi@gmail.com> | 2017-01-10 18:34:47 +0300 |
---|---|---|
committer | key-amb <yasutake.kiyoshi@gmail.com> | 2017-01-10 18:34:47 +0300 |
commit | ead12ff1a807110344563df111ee76f6d6e1ad75 (patch) | |
tree | 9c54f10aee0f5ae8d9ba5a34256f4137f8eef38b | |
parent | 67c7103921d74a8e2b4788e28f043524236526c8 (diff) |
Refactor using {{ with X }} instead of {{ if X }} in templates
-rw-r--r-- | layouts/index.html | 7 | ||||
-rw-r--r-- | layouts/partials/header.html | 14 |
2 files changed, 11 insertions, 10 deletions
diff --git a/layouts/index.html b/layouts/index.html index d02cee9..fd88c0d 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -7,7 +7,7 @@ <!-- Main jumbotron for a primary marketing message or call to action --> <div class="jumbotron"> <h1>{{ .Site.Title }}</h1> - <p>{{ if .Site.Params.description }}{{ .Site.Params.description }}{{ else }}You can customize this text by params "description" in your <code>config.toml</code>.{{ end }}</p> + <p>{{ with .Site.Params.description }}{{ . }}{{ else }}You can customize this text by params "description" in your <code>config.toml</code>.{{ end }}</p> </div> </div> @@ -41,11 +41,12 @@ </div> </div> -{{ if .Site.Params.withSitePosts }} +{{ $title := .Site.Title }} +{{ with .Site.Params.withSitePosts }} <hr /> <div class="row doc-main text-center"> - <a href="{{ $baseUrl }}/post">See posts for {{ .Site.Title }}</a> + <a href="{{ $baseUrl }}/post">See posts for {{ $title }}</a> </div> {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 6b3e609..f101804 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -9,7 +9,7 @@ <link rel="icon" href="{{ $baseUrl }}/favicon.ico"> <title>{{ .Title }}{{ if eq $isHomePage false }} - {{ .Site.Title }}{{ end }}</title> <!--<link href="http://fonts.googleapis.com/css?family=PT+Sans:400,700" rel="stylesheet" type="text/css">--> - <link rel="stylesheet" href="{{ $baseUrl }}/css/highlight/{{ if .Site.Params.highlightStyle }}{{ .Site.Params.highlightStyle }}{{ else }}default{{ end }}.css"> + <link rel="stylesheet" href="{{ $baseUrl }}/css/highlight/{{ with .Site.Params.highlightStyle }}{{ . }}{{ else }}default{{ end }}.css"> <link rel="stylesheet" href="{{ $baseUrl }}/css/bootstrap.min.css"> <link rel="stylesheet" href="{{ $baseUrl }}/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="{{ $baseUrl }}/css/theme.css"> @@ -33,14 +33,14 @@ <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li {{ if eq $isHomePage true }}class="active"{{ end }}><a href="{{ $baseUrl }}/">Home</a></li> - {{ if .Site.Params.mainMenu }} - {{ $url := .Permalink }} - {{ range $menu := .Site.Params.mainMenu }} + {{ $url := .Permalink }} + {{ with .Site.Params.mainMenu }} + {{ range $menu := . }} {{ $itemUrl := printf "%s/%s/" $baseUrl $menu.link }} <li {{ if eq $url $itemUrl }}class="active"{{ end }}><a href="{{ $baseUrl }}/{{ $menu.link }}">{{ $menu.name }}</a></li> {{ end }} {{ end }} - {{ if .Site.Params.noCategoryLink }}{{ else }} + {{ if not .Site.Params.noCategoryLink }} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Categories<span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> @@ -51,10 +51,10 @@ </li> {{ end }} </ul> - {{ if .Site.Params.searchDomain }} + {{ with .Site.Params.searchDomain }} <form class="navbar-form navbar-left" role="search" action="https://www.google.co.jp/search" method="get"> <div class="input-group doc-search-form"> - <input type="hidden" name="as_sitesearch" value="{{ .Site.Params.searchDomain }}"> + <input type="hidden" name="as_sitesearch" value="{{ . }}"> <input type="text" name="as_q" class="search-query doc-search-input-text" placeholder="Search Site"> <span class="input-group-addon input-group-btn doc-search-input-btn"> <button class="btn" type="submit"><span class="glyphicon glyphicon-search"></span></button> |