Skip to content

Commit

Permalink
init feat Prev Next post links on single post page (adityatelange#180)
Browse files Browse the repository at this point in the history
usage =>
in site config add 
Params:
   ShowPostNavLinks: true
  • Loading branch information
adityatelange authored Jan 27, 2021
1 parent 3c3888f commit 778ee39
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
44 changes: 42 additions & 2 deletions assets/css/post-single.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@
}

.post-tags a,
.share-buttons {
.share-buttons,
.paginav {
border-radius: var(--radius);
background: var(--code-bg);
border: 1px solid var(--border)
Expand All @@ -310,7 +311,8 @@
background: var(--code-bg)
}

.post-tags a:hover {
.post-tags a:hover,
.paginav a:hover {
background: var(--border)
}

Expand Down Expand Up @@ -374,3 +376,41 @@ h6:hover .anchor {
.post-content table::-webkit-scrollbar-thumb {
border-width: 2px;
}

.paginav {
margin: 10px 0;
display: flex;
line-height: 30px;
border-radius: var(--radius);
}

.paginav a {
padding-inline-start: 14px;
padding-inline-end: 14px;
border-radius: var(--radius);
}

.paginav .title {
letter-spacing: 1px;
text-transform: uppercase;
font-size: small;
color: var(--secondary);
}

.paginav .prev,
.paginav .next {
width: 50%;
}

.paginav span:hover:not(.title) {
box-shadow: 0 1px 0;
}

.paginav .next {
margin-inline-start: auto;
text-align: right;
}

[dir="rtl"] .paginav .next {
text-align: left;
}
21 changes: 21 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ <h1 class="post-title">
{{- end }}
</ul>
{{- end }}
{{- if .Site.Params.ShowPostNavLinks }}
{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
{{- if and (gt (len $pages) 1) (in $pages . ) }}
<nav class="paginav">
{{- with $pages.Next . }}
<a class="prev" href="{{.Permalink}}">
<span class="title">« {{ i18n "prev_page" }}</span>
<br>
<span>{{- .Name -}}</span>
</a>
{{- end}}
{{- with $pages.Prev . }}
<a class="next" href="{{.Permalink}}">
<span class="title">{{ i18n "next_page" }} »</span>
<br>
<span>{{- .Name -}}</span>
</a>
{{- end}}
</nav>
{{- end }}
{{- end }}
{{- if (and .Site.Params.ShowShareButtons (ne .Params.disableShare true) ) }}
{{- partial "share_icons.html" . }}
{{- end }}
Expand Down

0 comments on commit 778ee39

Please sign in to comment.