Add option to show posts on Homepage (#31)

* Add recent posts to Homepage

* Add different content posts

* Update html and css

* Add basic doc in README

* Update README

* Use partial

* Update page content
This commit is contained in:
Yash Mehrotra
2021-07-19 20:30:35 +05:30
committed by GitHub
parent 81ee72eb46
commit 5a1959c930
15 changed files with 1454 additions and 100 deletions

View File

@@ -1,20 +1,14 @@
{{ define "main" }}
<!-- TODO: @yash Paginate this if items more than n -->
<div class="container list-posts">
<h2 class="list-title">{{ .Name }}</h2>
{{ $posts := where .Data.Pages "Params.type" "post" }}
{{ range $posts.GroupByDate "2006" }}
{{ range (where .Site.Pages "Params.type" "post" ).GroupByDate "2006" }}
<h2 class="posts-year">{{ .Key }}</h2>
{{- range .Pages -}}
<article class="post-title">
<a href="{{ .RelPermalink }}" class="post-link">{{ .Title }}</a>
<span class="post-date">{{ dateFormat "January 2, 2006" .Date }}</span>
</article>
{{- partial "list-posts.html" . -}}
{{ end }}
{{ end }}

View File

@@ -8,4 +8,25 @@
<h1>{{ .Site.Title }}</h1>
<h3>{{ .Site.Params.Description }}</h3>
</section>
{{ if isset .Site.Params "showpostsonhomepage" }}
<div class="home-posts list-posts">
<h2>{{ .Site.Params.ShowPostsOnHomePage | humanize }} Posts</h2>
{{ $posts := where .Site.Pages "Params.type" "post" }}
{{ if eq .Site.Params.ShowPostsOnHomePage "popular" }}
{{ range $posts.ByWeight | first 4 }}
{{- partial "list-posts.html" . -}}
{{ end }}
{{ else if eq .Site.Params.ShowPostsOnHomePage "recent" }}
{{ range $posts.ByDate.Reverse | first 4 }}
{{- partial "list-posts.html" . -}}
{{ end }}
{{ end }}
</div>
{{ end }}
{{ end }}

View File

@@ -3,7 +3,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Jost&family=Nunito&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Jost&family=Arvo&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w=="

View File

@@ -0,0 +1,4 @@
<article class="post-title">
<a href="{{ .RelPermalink }}" class="post-link">{{ .Title }}</a>
<span class="post-date">{{ dateFormat "January 2, 2006" .Date }}</span>
</article>

View File

@@ -256,6 +256,10 @@ table td {
width: 15rem;
}
.home-posts {
padding-top: 20px;
}
/* SINGLE */
main#content .post {
font-size: 1.2rem;