Clean up templates a whole bunch by making single page layout, a true single page layout

This commit is contained in:
Justin Nguyen 2020-12-23 00:44:50 -08:00
parent 50b7892a15
commit 5992889676
4 changed files with 93 additions and 143 deletions

View File

@ -1,7 +1,7 @@
baseurl = "https://example.com/"
languageCode = "en-us"
theme = "hugo-theme-terminal"
paginate = 5
paginate = 10
[params]
contentTypeName = "post"
@ -10,14 +10,10 @@ paginate = 5
fullWidthTheme = false
centerTheme = false
# singlePageSite moves pages from the main nav menu to sections on the homepage.
# These only menu items with a url set to "/#section-name" will be displayed.
# A collection is displayed for the menu identifier which matches contentTypeName.
# The collection items use the "post" archetypes.
# These only menu items with a url starting with "/#" will be displayed using the
# front matter defined in "homepage/". A collection is displayed for other menu items.
singlePageSite = true
# For singlePageSites the collection is paginated but it would not make sense to
# paginate in the middle of a section, so a link to see more can be specified below.
singlePageCollectionSeeMoreText = "Check out my projects!"
singlePageCollectionSeeMoreLink = "/portfolio"
homepagePaginateCount = 10 # If you want the homepage to paginate a different numebr of items
[params.twitter]
creator = "@justinnuwin"

View File

@ -1,5 +1,6 @@
{{ define "main" }}
{{ if .Content }}
<div class="index-content {{ if .Params.framed -}}framed{{- end -}}">
{{ .Content }}
@ -14,98 +15,50 @@
{{ if .IsHome }}
{{ $PageContext = .Site }}
{{ end }}
{{ $paginator := .Paginate (where $PageContext.RegularPages "Type" $contentTypeName) }}
{{ if $.Site.Params.singlePageSite }}
<div class="sections">
{{ range .Site.Menus.main }}
{{ if eq (first 2 .URL) "/#" }}
<section id="{{ .Identifier }}" class="posts section">
{{ if $.Site.Params.singlePageSite }}
{{ if eq (first 2 .URL) "/#" }}
<h1 class="section-header">{{ .Name }}<a href="#{{ .Identifier }}" class="hanchor" arialabel="Anchor"></a></h1>
{{ end }}
{{ if ne .Identifier $.Site.Params.contentTypeName }}
{{ if $.Site.Params.singlePageSite }}
<div class="post">
{{ $section := path.Join "homepage" .Identifier }}
{{ with $.Site.GetPage $section }}
{{ partial "section.html" . }}
{{ end }}
</div>
{{ end }}
{{ else }}
{{ range $paginator.Pages.ByDate.Reverse }}
<article class="post on-list">
<h1 class="post-title">
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</h1>
<div class="post-meta">
<span class="post-date">
{{ with .Params.daterange }}
{{ . }}
{{ else }}
{{ .Date.Format "01-02-2006" }}
<h1 class="section-header">{{ .Name }}<a href="{{ .URL }}" class="hanchor" arialabel="Anchor"></a></h1>
{{ $thisSectionsPages := where $PageContext.RegularPages "Type" .Identifier }}
{{ range first $.Site.Params.homepagePaginateCount $thisSectionsPages.ByDate.Reverse }}
{{ partial "collection.html" . }}
{{ end }}
</span>
{{ with .Params.Author }}
<span class="post-author">:: {{ . }}</span>
{{ end }}
</div>
{{ if .Params.tags }}
<span class="post-tags">
{{ range .Params.tags }}
#<a href="{{ (urlize (printf "tags/%s/" . )) | absLangURL }}">
{{- . -}}
</a>&nbsp;
{{ end }}
</span>
{{ end }}
{{ if .Params.Cover }}
<img src="{{ .Params.Cover | absURL }}" class="post-cover" alt="{{ .Title | plainify | default " " }}" />
{{ end }}
<div class="post-content">
{{ if .Params.showFullContent }}
{{ .Content | markdownify }}
{{ else if .Description }}
{{ .Description | markdownify }}
{{ else }}
{{ if .Truncated }}
{{ .Summary | markdownify }}
{{ end }}
{{ end }}
</div>
{{ if not .Params.showFullContent }}
<div>
<a class="read-more button"
href="{{.RelPermalink}}">{{ $.Site.Params.ReadMore }} →</a>
</div>
{{ end }}
</article>
{{ end }}
{{ if $.Site.Params.singlePageSite }}
<div class="pagination">
<div class="pagination__buttons">
<span class="button previous">
<a href="{{ $.Site.Params.singlePageCollectionSeeMoreLink }}">
<a href="{{ .URL }}">
<span class="button__icon"></span>
<span class="button__text">{{ $.Site.Params.singlePageCollectionSeeMoreText }}</span>
<span class="button__text">See more {{ .Name | pluralize }}</span>
</a>
</span>
</div>
</div>
{{ else }}
{{ partial "pagination.html" $ }} <!-- originally . instead of $ -->
{{ end }}
{{ end }}
</section>
{{ if $.Site.Params.singlePageSite }}
<hr class="section-separator">
{{ end }}
{{ end }}
{{ end }}
</div>
{{ else }}
<div class="posts">
{{ $paginator := .Paginate (where $PageContext.RegularPages "Type" $contentTypeName) }}
{{ range $paginator.Pages.ByDate.Reverse }}
{{ partial "collection.html" . }}
{{ end }}
{{ partial "pagination.html" . }}
</div>
{{ end }}
{{ end }}

View File

@ -6,56 +6,7 @@
{{ end }}
<div class="posts">
{{ range .Pages.ByDate.Reverse }}
<article class="post on-list">
<h1 class="post-title">
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</h1>
<div class="post-meta">
<span class="post-date">
{{ with .Params.daterange }}
{{ . }}
{{ else }}
{{ .Date.Format "01-02-2006" }}
{{ end }}
</span>
{{ with .Params.Author }}
<span class="post-author">:: {{ . }}</span>
{{ end }}
</div>
{{ if .Params.tags }}
<span class="post-tags">
{{ range .Params.tags }}
#<a href="{{ (urlize (printf "tags/%s/" . )) | absLangURL }}">
{{- . -}}
</a>&nbsp;
{{ end }}
</span>
{{ end }}
{{ if .Params.Cover }}
<img src="{{ .Params.Cover | absURL }}" class="post-cover" alt="{{ .Title | plainify | default " " }}" />
{{ end }}
<div class="post-content">
{{ if .Params.showFullContent }}
{{ .Content | markdownify }}
{{ else if .Description }}
{{ .Description | markdownify }}
{{ else }}
{{ if .Truncated }}
{{ .Summary | markdownify }}
{{ end }}
{{ end }}
</div>
{{ if not .Params.showFullContent }}
<div>
<a class="read-more button"
href="{{.RelPermalink}}">{{ $.Site.Params.ReadMore }} →</a>
</div>
{{ end }}
</article>
{{ partial "collection.html" . }}
{{ end }}
{{ partial "pagination.html" . }}
</div>

View File

@ -0,0 +1,50 @@
<article class="post on-list">
<h1 class="post-title">
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</h1>
<div class="post-meta">
<span class="post-date">
{{ with .Params.daterange }}
{{ . }}
{{ else }}
{{ .Date.Format "01-02-2006" }}
{{ end }}
</span>
{{ with .Params.Author }}
<span class="post-author">:: {{ . }}</span>
{{ end }}
</div>
{{ if .Params.tags }}
<span class="post-tags">
{{ range .Params.tags }}
#<a href="{{ (urlize (printf "tags/%s/" . )) | absLangURL }}">
{{- . -}}
</a>&nbsp;
{{ end }}
</span>
{{ end }}
{{ if .Params.Cover }}
<img src="{{ .Params.Cover | absURL }}" class="post-cover" alt="{{ .Title | plainify | default " " }}" />
{{ end }}
<div class="post-content">
{{ if .Params.showFullContent }}
{{ .Content | markdownify }}
{{ else if .Description }}
{{ .Description | markdownify }}
{{ else }}
{{ if .Truncated }}
{{ .Summary | markdownify }}
{{ end }}
{{ end }}
</div>
{{ if not .Params.showFullContent }}
<div>
<a class="read-more button"
href="{{.RelPermalink}}">{{ $.Site.Params.ReadMore }} →</a>
</div>
{{ end }}
</article>