added featured articles option with distinct style

This commit is contained in:
Gabriele Musco 2021-04-13 23:30:34 +02:00
parent 4239ea5347
commit 13bb88e93a
No known key found for this signature in database
GPG Key ID: 8539FD3454380B83
5 changed files with 75 additions and 10 deletions

View File

@ -48,6 +48,8 @@ summaryLength = 70 # number of words for article summaries
searchbarEverywhere = true # if the searchbar should be shown in every page; requires enableSearch searchbarEverywhere = true # if the searchbar should be shown in every page; requires enableSearch
searchMenuLink = false # add a search link to the navigation menu; requires enableSearch searchMenuLink = false # add a search link to the navigation menu; requires enableSearch
enableFeatured = false # enable a particular view for articles marked as featured (featured: true in the article frontmatter)
# enable comments support with commento using the script from your server # enable comments support with commento using the script from your server
commento = "https://example.com/js/commento.js" commento = "https://example.com/js/commento.js"

View File

@ -244,7 +244,7 @@ h1, h2, h3, h4, h5, h6 {
padding-bottom: 25px; padding-bottom: 25px;
&.discrete { &.discrete {
background: $highlight_bg_color; background-color: $highlight_bg_color;
border-radius: 10px; border-radius: 10px;
padding: 20px; padding: 20px;
padding-top: 1px; padding-top: 1px;
@ -370,3 +370,31 @@ ul.list {
&, #searchbar {font-size: 1em;} &, #searchbar {font-size: 1em;}
} }
} }
.featuredCardLink {
border: none;
padding: 0;
.featuredCard {
@extend .card;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
position: relative;
height: 250px;
.contentArea {
position: absolute;
bottom: 0;
padding: 15px;
h2 {
margin: 0;
}
.date {
margin: 0;
}
}
&.discrete {
border-radius: 10px;
padding: 0;
}
}
}

View File

@ -2,7 +2,37 @@
{{/* get all the pages that are regular posts and not pages */}} {{/* get all the pages that are regular posts and not pages */}}
{{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }} {{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }}
{{ $postsList := where .Site.RegularPages "Section" "in" $postsDir }} {{ $allPostsList := where .Site.RegularPages "Section" "in" $postsDir }}
{{ $featuredPostsList := slice }}
{{ $postsList := $allPostsList }}
{{ if .Site.Params.enableFeatured | default false }}
{{ $featuredPostsList = where $allPostsList "Params.featured" true }}
{{ $postsList = union (where $allPostsList "Params.featured" false) (where $allPostsList "Params.featured" nil) }}
{{ end }}
<div class="featured postlist gridView">
{{ range $featuredPostsList }}
<a class="featuredCardLink" href="{{ .Permalink }}">
<article class="featuredCard {{ if .Site.Params.discreteCards }}discrete{{ end }}"
style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 59%, rgba(0, 0, 0, 0.7) 100%), url('{{ .Params.Image }}');">
<div class="contentArea">
<h2>{{ .Title }}</h2>
<p class="date">
<span title="Date"></span>
{{ .Date.Format "2006-01-02" }}
{{ if .Params.tags }}
<br />
<span title="Tags"></span>
{{ range .Params.tags }}
#{{ . }}
{{ end }}
{{ end }}
</p>
</div>
</article>
</a>
{{ end }}
</div>
{{/* pagination */}} {{/* pagination */}}
<div class="postlist {{ if .Site.Params.gridView }}gridView{{ end }}" id="postlist"> <div class="postlist {{ if .Site.Params.gridView }}gridView{{ end }}" id="postlist">

View File

@ -1,16 +1,17 @@
{{ define "main" }} {{ define "main" }}
{ {
{{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }} {{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }}
{{ $postsList := where .Site.RegularPages "Section" "in" $postsDir }} {{ $allPostsList := where .Site.RegularPages "Section" "in" $postsDir }}
"page": "{{ .Paginator.PageNumber }}", {{ $featuredPostsList := slice }}
"next": {{ if .Paginator.HasNext }} {{ $postsList := $allPostsList }}
{{ .Paginator.Next.URL | absURL | jsonify }} {{ if .Site.Params.enableFeatured | default false }}
{{ else }}""{{ end }}, {{ $featuredPostsList = where $allPostsList "Params.featured" true }}
{{ $postsList = union (where $allPostsList "Params.featured" false) (where $allPostsList "Params.featured" nil) }}
{{ end }}
{{ $mscratch := newScratch }} {{ $mscratch := newScratch }}
{{ $mscratch.Add "articles" slice }} {{ $mscratch.Add "articles" slice }}
{{ range (.Paginate $postsList).Pages }} {{ range (.Paginate $postsList).Pages }}
{{ $mscratch.Add "articles" (dict {{ $mscratch.Add "articles" (dict
"ignore" (not (in $postsDir .Section))
"title" .Title "title" .Title
"date" (.Date.Format "2006-01-02") "date" (.Date.Format "2006-01-02")
"tags" (or .Params.tags slice) "tags" (or .Params.tags slice)
@ -18,6 +19,11 @@
"link" .Permalink "link" .Permalink
"image" (or .Params.Image "")) }} "image" (or .Params.Image "")) }}
{{ end }} {{ end }}
"articles": {{ $mscratch.Get "articles" | jsonify }} "articles": {{ $mscratch.Get "articles" | jsonify }},
"test": "{{range $postsList}}{{.Title}} {{end}}",
"page": "{{ .Paginator.PageNumber }}",
"next": {{ if .Paginator.HasNext }}
{{ .Paginator.Next.URL | absURL | jsonify }}
{{ else }}""{{ end }}
} }
{{ end }} {{ end }}

View File

@ -13,7 +13,6 @@
return `<img src="${image}" />` return `<img src="${image}" />`
} }
function renderSingleArticle(article) { function renderSingleArticle(article) {
if (article.ignore) return '';
return ` return `
<article class="card postlistitem {{ if .Site.Params.discreteCards }}discrete{{ end }}"> <article class="card postlistitem {{ if .Site.Params.discreteCards }}discrete{{ end }}">
<div> <div>