diff options
author | Tanner Smith <tannersmithtn95@gmail.com> | 2019-10-02 20:58:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-02 20:58:09 +0300 |
commit | 4d0f2a1fbecb7cf2aab6befe4d07629728934a21 (patch) | |
tree | 539d4e2d18f8b2abb89fa3533f2e9f63dd1d4bed /layouts | |
parent | 805f71623bee0b07f9764f2eed03b1c8fec0d813 (diff) | |
parent | ed82213fe11961b66e72b49263eaebbe9f4a1ab6 (diff) |
Merge pull request #19 from theNewDynamic/improve-hugo-logic
Improve hugo logic
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/article/article_authors.html | 117 | ||||
-rw-r--r-- | layouts/partials/article/article_hero.html | 2 | ||||
-rw-r--r-- | layouts/partials/article/article_next.html | 75 | ||||
-rw-r--r-- | layouts/partials/articles/articles_list.html | 23 | ||||
-rw-r--r-- | layouts/partials/author/author_articles_list.html | 71 | ||||
-rw-r--r-- | layouts/partials/func/GetArticleAuthors.html | 39 | ||||
-rw-r--r-- | layouts/partials/func/GetArticles.html | 5 | ||||
-rw-r--r-- | layouts/partials/func/GetAuthorArticles.html | 4 |
8 files changed, 163 insertions, 173 deletions
diff --git a/layouts/partials/article/article_authors.html b/layouts/partials/article/article_authors.html index 915eda5..66c39b1 100644 --- a/layouts/partials/article/article_authors.html +++ b/layouts/partials/article/article_authors.html @@ -1,106 +1,59 @@ -{{ $scratch := newScratch }} -{{ $scratch.Set "numAuthors" 0 }} - -{{ $authors := .Params.authors }} - -{{ $scratch.Set "numAuthors" (len $authors) }} -{{ $scratch.Set "authors" $authors }} - -{{ if eq ($scratch.Get "numAuthors") 1 }} - - {{ range $author := where .Site.RegularPages "Type" "author" }} - {{ $authorPath := index ($scratch.Get "authors") 0 }} - {{ $firstAuthor := .Site.GetPage $authorPath }} - {{ if eq $author.Params.name $firstAuthor.Params.name }} - <a href="{{ $author.Permalink }}" class="article-author-link"> - {{ if $author.Params.avatar }} +{{ $authors := partialCached "func/GetArticleAuthors" . .File.UniqueID }} +{{ if eq (len $authors) 1 }} + {{ with $author := index $authors 0 }} + <a href="{{ .URL }}" class="article-author-link"> + {{ with .avatar }} <div class="article-author-avatar"> - <img src="{{ $author.Params.avatar }}" /> + <img src="{{ . }}" /> </div> {{ end }} - <strong>{{ $author.Params.name }}</strong> + {{ with .name }} + <strong>{{ . }}</strong> + {{ end }} <span class="hide-on-mobile">, </span> - </a> - {{ end }} + </a> {{ end }} - -{{ else if gt ($scratch.Get "numAuthors") 1 }} +{{ else }} <div class="article-coauthors-container"> - {{ $avatarsWidth:= mul ($scratch.Get "numAuthors") 15 }} + {{ $avatarsWidth:= mul (len $authors) 15 }} <span id="collapsedCoauthors" class="article-coauthors-collapsed"> - <div class="article-coauthors-list" style="width: {{ $avatarsWidth }}px;"> - - {{ $scratch := newScratch }} - {{ $scratch.Set "matches" false }} - {{ $scratch.Set "authors" .Params.authors }} - {{ range $index, $author := where .Site.RegularPages "Type" "author" }} - {{ $scratch.Set "nameHold" $author.Params.name }} - {{ range $authorPath := $scratch.Get "authors" }} - {{ $authorCompare := $.Site.GetPage $authorPath }} - {{ if eq $authorCompare.Params.name ($scratch.Get "nameHold") }} - {{ $scratch.Set "matches" true }} - {{ end }} - {{ end }} - {{ if eq ($scratch.Get "matches") true }} - {{ if $author.Params.avatar }} + <div class="article-coauthors-list" style="width: {{ $avatarsWidth }}px;"> + {{ range $index, $author := $authors }} + {{ with .avatar }} <div class="article-coauthors-avatar" style="left: {{ mul $index 15 }}px;"> - <img src="{{ $author.Params.avatar }}" /> + <img src="{{ . }}" /> </div> {{ end }} {{ end }} - {{ end }} - </div> - <strong class="article-coauthors-name-container"> - {{ $scratch.Set "matches" false }} - {{ $scratch.Set "authors" .Params.authors }} - {{ range $index, $author := where .Site.RegularPages "Type" "author" }} - {{ $scratch.Set "nameHold" $author.Params.name }} - {{ range $authorPath := $scratch.Get "authors" }} - {{ $authorCompare := $.Site.GetPage $authorPath }} - {{ if eq $authorCompare.Params.name ($scratch.Get "nameHold") }} - {{ $scratch.Set "matches" true }} - {{ end }} - {{ end }} - {{ if eq ($scratch.Get "matches") true }} - {{ $author.Params.name }}{{ if ne (add $index 1) (len ($scratch.Get "authors")) }},{{ end }} + </div> + <strong class="article-coauthors-name-container"> + {{ range $index, $author := $authors }} + {{ .firstname }}{{ if ne (add $index 1) (len $authors) }},{{ end }} {{ end }} - {{ end }} - </strong> - <div class="article-coauthors-icon-container"> - {{ partial "icons/ui/toggle-open.html" . }} - </div> + </strong> + <div class="article-coauthors-icon-container"> + {{ partial "icons/ui/toggle-open.html" . }} + </div> </span> <ul id="uncollapsedCoauthors" class="article-coauthors-list-open hidden"> <div id="uncollapsedAction" class="article-icon-open-container"> {{ partial "icons/ui/toggle-closed.html" . }} </div> - {{ $scratch.Set "matches" false }} - {{ $scratch.Set "authors" .Params.authors }} - {{ range $index, $author := where .Site.RegularPages "Type" "author" }} - {{ $scratch.Set "nameHold" $author.Params.name }} - {{ range $authorPath := $scratch.Get "authors" }} - {{ $authorCompare := $.Site.GetPage $authorPath }} - {{ if eq $authorCompare.Params.name ($scratch.Get "nameHold") }} - {{ $scratch.Set "matches" true }} - {{ end }} - {{ end }} - {{ if eq ($scratch.Get "matches") true }} - <li class="article-coauthors-list-item-open"> - <a href="{{ $author.Permalink }}" class="article-author-link"> - {{ if $author.Params.avatar }} - <div class="article-coauthor-avatar-open"> - <img src="{{ $author.Params.avatar }}" /> - </div> - {{ end }} - <strong class="article-author-name-open">{{ $author.Params.name }}</strong> - </a> - </li> - {{ end }} + {{ range $index, $author := $authors }} + <li class="article-coauthors-list-item-open"> + <a href="{{ .URL }}" class="article-author-link"> + {{ with $author.avatar }} + <div class="article-coauthor-avatar-open"> + <img src="{{ . }}" /> + </div> + {{ end }} + <strong class="article-author-name-open">{{ .name }}</strong> + </a> + </li> {{ end }} </ul> - </div> {{ end }} diff --git a/layouts/partials/article/article_hero.html b/layouts/partials/article/article_hero.html index d393288..ae85203 100644 --- a/layouts/partials/article/article_hero.html +++ b/layouts/partials/article/article_hero.html @@ -6,7 +6,7 @@ <div class="article-meta"> {{ partial "article/article_authors.html" . }} {{ .Page.Date.Format "January 2, 2006" }} - {{ if .Page.Params.timetoread }} • {{ .Page.Params.timetoread }} min read{{ end }} + {{ with .Page.Params.timetoread }} • {{ . }} min read{{ end }} </div> </div> </header> diff --git a/layouts/partials/article/article_next.html b/layouts/partials/article/article_next.html index f55ef0b..f12f340 100644 --- a/layouts/partials/article/article_next.html +++ b/layouts/partials/article/article_next.html @@ -1,40 +1,57 @@ +{{/* + Prints the next 2 articles in the same section or, if less or 2 found, the first (and potentially second) of the section. + + @author @regisphilibert @mountainbug95 + + @context Type Page (.) + + @access public + +*/}} + +{{/* declaring next empty slice */}} +{{ $next := slice }} +{{/* Checking if current article has a PrevInSection (Prev as we are ordering dsc here.) */}} +{{ with .PrevInSection }} + {{ $next = $next | append . }} + {{/* Checking for that "next" article own "next" to fill the "second next" */}} + {{ with .PrevInSection }} + {{ $next = $next | append . }} + {{ end }} +{{ end }} +{{/* If the number of found "next article" is less than two we need to find the first and potentially second article +of the whole section and append them to our $next slice. */}} +{{ $diff := sub 2 (len $next) }} +{{ if $diff }} + {{/* We use that diff number (if > 0) to grab the first x number of articles */}} + {{ $articles := partialCached "func/GetArticles" . "articles"}} + {{ $next = $next | append (first $diff $articles) }} +{{ end }} <section class="section nartrow"> <h3 class="footer-next-heading">More articles from {{ .Site.Title }}</h3> <div class="footer-spacer"></div> <div class="next-articles-grid" numberOfArticles={numberOfArticles}> <div class="post-row"> - {{ $scratch := newScratch }} - {{ $scratch.Set "counter" 0 }} - {{ $pageTitle := .Params.title }} - {{ $scratch.Set "pt" $pageTitle }} - {{ range $index, $article := where .Site.RegularPages "Type" "post" }} - {{ if or (eq ($scratch.Get "counter") 1) (eq ($scratch.Get "counter") 2) }} - <a href="{{ $article.Permalink }}" class="article-link" - {{ if eq ($scratch.Get "counter") 1 }} id="article-link-bigger"{{ end }}> + {{ range $index, $article := $next }} + <a href="{{ $article.Permalink }}" class="article-link" + {{ if not $index}} id="article-link-bigger"{{ end }}> + <div> + <div class="image-container"> + <img src="{{ $article.Params.hero }}" class="article-image" /> + </div> <div> - <div class="image-container"> - <img src="{{ $article.Params.hero }}" class="article-image" /> - </div> - <div> - <h2 class="article-title"> - {{ $article.Params.title }} - </h2> - <p class="article-excerpt"> - {{ $article.Params.excerpt }} - </p> - <div class="article-metadata"> - {{ $article.Date | dateFormat "January 1, 2019" }}{{ with $article.Params.timeToRead }} · {{ $article.Params.timeToRead }} min read{{ end }} - </div> + <h2 class="article-title"> + {{ $article.Params.title }} + </h2> + <p class="article-excerpt"> + {{ $article.Params.excerpt }} + </p> + <div class="article-metadata"> + {{ $article.Date | dateFormat "January 1, 2006" }}{{ with $article.Params.timeToRead }} · {{ $article.Params.timeToRead }} min read{{ end }} </div> </div> - </a> - {{ $scratch.Set "counter" (add ($scratch.Get "counter") 1) }} - {{ end }} - {{ if eq .Params.title ($scratch.Get "pt") }} - {{ if .Params.title }} - {{ $scratch.Set "counter" 1 }} - {{ end }} - {{ end }} + </div> + </a> {{ end }} </div> </div> diff --git a/layouts/partials/articles/articles_list.html b/layouts/partials/articles/articles_list.html index 9d6d8b4..1109650 100644 --- a/layouts/partials/articles/articles_list.html +++ b/layouts/partials/articles/articles_list.html @@ -1,24 +1,23 @@ <section class="section nartrow"> <div id="articlesList" class="articles-list-container show-details"> {{ $paginator := .Paginate (where .Site.RegularPages "Type" "post") }} - {{ $scratch :=newScratch }} - {{ $scratch.Set "biggerFirst" true }} - {{ $scratch.Set "biggerPlaced" false }} + {{ $biggerFirst := true }} + {{ $biggerPlaced := false }} {{ range $index, $article := $paginator.Pages }} {{ $counter := mod $index 2 }} - {{ if eq $counter 0 }} + {{ if not $counter }} <div class="post-row"> {{ end }} <a href="{{ $article.Permalink }}" class="article-link" - {{ if and (eq ($scratch.Get "biggerFirst") true) (eq ($scratch.Get "biggerPlaced") false) }} + {{ if and (eq ($biggerFirst) true) (eq ($biggerPlaced) false) }} {{ if eq $counter 0 }} id="article-link-bigger" - {{ $scratch.Set "biggerPlaced" true }} + {{ $biggerPlaced = true }} {{ end }} - {{ else if and (eq ($scratch.Get "biggerFirst") false) (eq ($scratch.Get "biggerPlaced") false) }} + {{ else if and (not $biggerFirst) (not $biggerPlaced) }} {{ if ne $counter 0 }} id="article-link-bigger" - {{ $scratch.Set "biggerPlaced" true }} + {{ $biggerPlaced = true }} {{ end }} {{ end }}> <div class="article-data-outer"> @@ -42,11 +41,11 @@ {{ $len := (where .Pages "Type" "posts") }} {{ if or (eq $counter 0) (eq (add $index 1) $len) }} </div> - {{ $scratch.Set "biggerPlaced" false }} - {{ if eq ($scratch.Get "biggerFirst") true }} - {{ $scratch.Set "biggerFirst" false }} + {{ $biggerPlaced = false }} + {{ if $biggerFirst }} + {{ $biggerFirst = false }} {{ else }} - {{ $scratch.Set "biggerFirst" true }} + {{ $biggerFirst = true }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/author/author_articles_list.html b/layouts/partials/author/author_articles_list.html index c1c08bb..b3b74ca 100644 --- a/layouts/partials/author/author_articles_list.html +++ b/layouts/partials/author/author_articles_list.html @@ -1,57 +1,30 @@ <section class="section nartrow author-alc-section"> <div id="articlesList" class="articles-list-container show-details author-alc"> - {{ $scratch :=newScratch }} - {{ $scratch.Set "authorName" .Page.Params.name }} - {{ $scratch.Set "biggerFirst" true }} - {{ $scratch.Set "biggerPlaced" false }} + {{ $articles := partial "func/GetAuthorArticles" . }} <div class="post-row-alt"> - {{ range $index, $article := where .Site.RegularPages "Type" "post" }} - - {{ $scratch.Set "authorMatch" false }} - {{ range $author := $article.Params.authors }} - {{ $authorPage := $.Site.GetPage $author }} - - {{ if eq $authorPage.Params.name ($scratch.Get "authorName") }} - {{ $scratch.Set "authorMatch" true }} - {{ end }} - {{ end }} - - {{ $counter := mod $index 2 }} - {{ if eq ($scratch.Get "authorMatch") true }} - <a href="{{ $article.Permalink }}" class="article-link"> - <div class="article-data-outer"> - <div class="image-container"> - <img src="{{ $article.Params.hero }}" class="article-image" /> - </div> - <div class="article-data"> - <h2 class="article-title"> - {{ $article.Params.title }} - </h2> - <p class="article-excerpt"> - {{ $article.Params.excerpt }} - </p> - <div class="article-metadata"> - {{ $article.Date.Format "January 2, 2006" }}{{ if $article.Params.timetoread }} • {{ $article.Params.timetoread }} min read{{ end }} - </div> - </div> - </div> - </a> - {{ $counter := mod (add $index 1) 2 }} - {{ $len := (where .Pages "Type" "posts") }} - {{ end }} - {{ end }} + {{ range $index, $article := $articles }} + {{ $counter := mod $index 2 }} + <a href="{{ $article.Permalink }}" class="article-link"> + <div class="article-data-outer"> + <div class="image-container"> + <img src="{{ $article.Params.hero }}" class="article-image" /> + </div> + <div class="article-data"> + <h2 class="article-title"> + {{ $article.Params.title }} + </h2> + <p class="article-excerpt"> + {{ $article.Params.excerpt }} + </p> + <div class="article-metadata"> + {{ $article.Date.Format "January 2, 2006" }}{{ if $article.Params.timetoread }} • {{ $article.Params.timetoread }} min read{{ end }} + </div> + </div> + </div> + </a> + {{ end }} </div> </div> - - <nav aria-label="Page navigation"> - <ul class="pagination"> - <li class="page-item active"><a href="/" class="page-link">1</a></li> - <li class="page-item"><a href="/page/2/" class="page-link">2</a></li> - <li class="page-item"><a href="/page/3/" class="page-link">3</a></li> - <li class="page-item"><a href="/page/2/" rel="next" class="page-link page-next">Next</a></li> - </ul> - </nav> - </section> {{ $script := resources.Get "js/toggleBorder.js" }} diff --git a/layouts/partials/func/GetArticleAuthors.html b/layouts/partials/func/GetArticleAuthors.html new file mode 100644 index 0000000..c6041e4 --- /dev/null +++ b/layouts/partials/func/GetArticleAuthors.html @@ -0,0 +1,39 @@ +{{/* + GetArticle Authors + Retrieve the authors assigned to a given article + + @author @regisphilibert + + @context Page (.) The article in quest + + @access public + + @return Slice + - String (.name) + - String (.URL) + - String (.name) + - String (.firstname) + + @example - Go Template + {{ $authors := partialCached "func/GetArticleAuthors" . .File.UniqueID }} +*/}} +{{ $authors := slice }} +{{ with .Params.authors }} + {{ range . }} + {{ with site.GetPage . }} + {{ $firstname := "" }} + {{ $name := "" }} + {{ $avatar := false }} + {{ with .Params.name }} + {{ $name = . }} + {{ $firstname = index (split . " ") 0 }} + {{ end }} + {{ with .Params.avatar }} + {{ $avatar = . }} + {{ end }} + {{ $authors = $authors | append (dict "URL" .RelPermalink "name" $name "firstname" $firstname "avatar" $avatar) }} + {{ end }} + {{ end }} +{{ end }} + +{{ return $authors }}
\ No newline at end of file diff --git a/layouts/partials/func/GetArticles.html b/layouts/partials/func/GetArticles.html new file mode 100644 index 0000000..ac996bc --- /dev/null +++ b/layouts/partials/func/GetArticles.html @@ -0,0 +1,5 @@ +{{ $articles := slice }} +{{ with where site.RegularPages "Type" "post" }} + {{ $articles = . }} +{{ end }} +{{ return $articles }}
\ No newline at end of file diff --git a/layouts/partials/func/GetAuthorArticles.html b/layouts/partials/func/GetAuthorArticles.html new file mode 100644 index 0000000..318dfe6 --- /dev/null +++ b/layouts/partials/func/GetAuthorArticles.html @@ -0,0 +1,4 @@ +{{ $articles := slice }} +{{ $articles = where .Site.RegularPages "Type" "post" }} +{{ $articles = where $articles "Params.authors" "intersect" (slice .File.Path) }} +{{ return $articles }}
\ No newline at end of file |