Make all full-page templates inherit from a block template
Use block templates [1] for all of the full-page templates such as index.html, _default/list.html, etc. This reduces code duplicated between them. Also, move the code in partials/page.html and partials/post.html to page/single.html and post/single.html respectively. With block templates the contents of the partials is almost exactly the same as the contents of the single page templates, and having dedicated single-page templates for the content types means that we can get rid of the if/then/else logic in _default/single.html. This also gets rid of an excess container div; the duplication of the divs was being obscured by the way _default/single.html was interacting with the partials. (This is the same duplicated div as in pull request #51 found by @1138-4EB.) [1] https://gohugo.io/templates/blocks/
This commit is contained in:
parent
7d9cf1adce
commit
a5113e5008
@ -1,12 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
|
||||
{{ partial "head.html" . }}
|
||||
|
||||
<body>
|
||||
|
||||
{{ partial "nav.html" . }}
|
||||
|
||||
{{ define "header" }}<!-- No header on 404 pages -->{{ end }}
|
||||
{{ define "main" }}
|
||||
<div role="main" class="container main-content">
|
||||
<div class="text-center">
|
||||
<h1>{{ i18n "pageNotFound" }}</h1>
|
||||
@ -14,8 +7,5 @@
|
||||
<img src="{{ .Site.BaseURL }}/img/404-southpark.jpg" />
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ partial "footer.html" . }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
11
layouts/_default/baseof.html
Normal file
11
layouts/_default/baseof.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
{{ partial "head.html" . }}
|
||||
<body>
|
||||
{{ partial "nav.html" . }}
|
||||
{{ block "header" . }}{{ partial "header.html" . }}{{ end }}
|
||||
{{ block "main" . }}{{ end }}
|
||||
{{ partial "footer.html" . }}
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,12 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
|
||||
{{ partial "head.html" . }}
|
||||
|
||||
<body>
|
||||
|
||||
{{ partial "nav.html" . }}
|
||||
|
||||
{{ define "header" }}
|
||||
<header class="header-section ">
|
||||
<div class="intro-header no-img">
|
||||
<div class="container">
|
||||
@ -20,7 +12,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{{ end }}
|
||||
{{ define "main" }}
|
||||
<div class="container" role="main">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
@ -64,7 +57,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ partial "footer.html" . }}
|
||||
{{ end }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,25 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
|
||||
{{ partial "head.html" . }}
|
||||
|
||||
<body>
|
||||
|
||||
{{ partial "nav.html" . }}
|
||||
{{ partial "header.html" . }}
|
||||
|
||||
{{ define "main" }}
|
||||
<div class="container" role="main">
|
||||
{{ if eq .Type "post" }}
|
||||
{{ partial "post.html" . }}
|
||||
{{ else if eq .Type "page" }}
|
||||
{{ partial "page.html" . }}
|
||||
{{ else }}
|
||||
NO MATCHING PARTIAL
|
||||
{{.Content}}
|
||||
{{ end }}
|
||||
{{.Content}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ partial "footer.html" . }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,13 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
|
||||
{{ partial "head.html" . }}
|
||||
|
||||
<body>
|
||||
|
||||
{{ partial "nav.html" . }}
|
||||
{{ partial "header.html" . }}
|
||||
|
||||
{{ define "main" }}
|
||||
{{ $data := .Data }}
|
||||
|
||||
<div class="container" role="main">
|
||||
@ -20,8 +11,5 @@
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ partial "footer.html" . }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,13 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Lang }}">
|
||||
|
||||
{{ partial "head.html" . }}
|
||||
|
||||
<body>
|
||||
|
||||
{{ partial "nav.html" . }}
|
||||
{{ partial "header.html" . }}
|
||||
|
||||
{{ define "main" }}
|
||||
<div role="main" class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
@ -69,8 +60,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ partial "footer.html" . }}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
17
layouts/page/single.html
Normal file
17
layouts/page/single.html
Normal file
@ -0,0 +1,17 @@
|
||||
{{ define "main" }}
|
||||
<div class="container" role="main">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
{{ .Content }}
|
||||
{{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
|
||||
{{ if .Site.DisqusShortname }}
|
||||
<div class="disqus-comments">
|
||||
{{ template "_internal/disqus.html" . }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
@ -1,12 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
{{ .Content }}
|
||||
{{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
|
||||
{{ if .Site.DisqusShortname }}
|
||||
<div class="disqus-comments">
|
||||
{{ template "_internal/disqus.html" . }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
@ -1,3 +1,5 @@
|
||||
{{ define "main" }}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||
<article role="main" class="blog-post">
|
||||
@ -27,3 +29,6 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
Loading…
Reference in New Issue
Block a user