Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally display post images as a gallery #123

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ weight = 4

Projects section will not be shown if no data file is detected. See [Projects list](#projects-list) below.

### Posts

You can display the images in the page bundle as a gallery at the top of your post:

```yaml
show_gallery: true
```

### Projects list

Create your projects data file `data/projects.yaml|toml|json`. Hugo support yaml, toml and json formats.
Expand Down
19 changes: 11 additions & 8 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
{{ $.Scratch.Set "year" $pageYear }}
<h2>{{ $pageYear }}</h2>
{{ end }}
<li class="post-item">
<div class="meta">
<time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format (.Site.Params.dateFormat | default "2006-01-02") }}</time>
</div>
<span>
<a class="" href="{{ .Permalink }}">{{ if .Title }} {{ .Title }} {{ else }} Untitled {{ end }}</a>
</span>
</li>
{{ if isset .Params "hidden" }}
{{ else }}
<li class="post-item">
<div class="meta">
<time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format (.Site.Params.dateFormat | default "2006-01-02") }}</time>
</div>
<span>
<a class="" href="{{ .Permalink }}">{{ if .Title }} {{ .Title }} {{ else }} Untitled {{ end }}</a>
</span>
</li>
{{ end }}
{{ end }}
</ul>
{{ if eq .Site.Params.showAllPostsArchive false }}
Expand Down
23 changes: 14 additions & 9 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
{{ $length := (len .Site.Params.social) }}
{{ range $index, $elem := .Site.Params.social}}
{{ if eq $elem.name "email" }}
<a class="icon" target="_blank" rel="noopener" href="mailto:{{ $elem.link }}" aria-label="Email">
<i class="fas fa-envelope" aria-hidden="true"></i>
</a>
send me an
<a target="_blank" rel="noopener" href="mailto:{{ $elem.link }}" aria-label="Email">e-mail</a>.
{{ else if eq $elem.name "rss" }}
<a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="RSS">
<i class="fas fa-rss" aria-hidden="true"></i>
Expand All @@ -19,6 +18,9 @@
<a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="Google Scholar">
<i class="fas fa-graduation-cap" aria-hidden="true"></i>
</a>
{{ else if eq $elem.name "twitter" }}
<a target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="Google Scholar">
Twitter</a>
{{ else }}
<a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="{{ $elem.name }}">
<i class="fab fa-{{ lower $elem.name }}" aria-hidden="true"></i>
Expand All @@ -27,9 +29,9 @@
{{ if (lt (add $index 2) $length) }}
{{- print " , " -}}
{{ else if (lt (add $index 1) $length) }}
{{- print " and " -}}
{{- print " or " -}}
{{ else }}
{{- print "." -}}
{{/* {{- print "." -}} */}}
{{ end }}
{{ end }}
</p>
Expand Down Expand Up @@ -61,10 +63,13 @@
{{ if $showAllPostsOnHomePage }}
<ul class="post-list">
{{ range (.Paginate $mainPosts).Pages }}
<li class="post-item">
<div class="meta"><time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format $dataFormat }}</time></div>
<span><a href="{{ .Permalink }}">{{ if .Title }} {{- .Title -}} {{ else }} {{- print "Untitled" -}}{{ end }}</a></span>
</li>
{{ if isset .Params "hidden" }}
{{ else }}
<li class="post-item">
<div class="meta"><time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format $dataFormat }}</time></div>
<span><a href="{{ .Permalink }}">{{ if .Title }} {{- .Title -}} {{ else }} {{- print "Untitled" -}}{{ end }}</a></span>
</li>
{{ end }}
{{ end }}
</ul>

Expand Down
7 changes: 0 additions & 7 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
Copyright &copy; {{ now.Format "2006" }} {{ if .Site.Copyright }} {{ print .Site.Copyright | markdownify }} {{ else }} {{ print .Site.Title }} {{ end }}
</div>
<div class="footer-right">
<nav>
<ul>
{{ range .Site.Menus.main }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
</nav>
</div>
</footer>
4 changes: 1 addition & 3 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-regular-400.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-solid-900.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<script type="text/javascript" src="https://latest.cactus.chat/cactus.js"></script>
<link rel="stylesheet" href="https://latest.cactus.chat/style.css" type="text/css">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ if .IsPage }} {{ .Title }} | {{ end }}{{ .Site.Title }}</title>
Expand All @@ -23,7 +21,7 @@

{{- $options := (dict "targetPath" "css/styles.css" "outputStyle" "compressed" "enableSourceMap" "true") -}}
{{- $styles := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "scss/style.scss" . | resources.ToCSS $options | resources.Fingerprint "sha512" }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}">
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="" crossorigin="anonymous">

<!-- Custom CSS -->
{{ range .Site.Params.css }} <link rel="stylesheet" href="{{ . | absURL }}"> {{ end }}
Expand Down
21 changes: 11 additions & 10 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ <h1 class="posttitle" itemprop="name headline">
{{ end }}
</div>
</header>

{{ with .Resources.ByType "image" }}
<div class="article-gallery">
{{ range $index, $value := . }}
<a class="gallery-item" href="{{ .RelPermalink }}" rel="gallery_{{ $index }}">
<img src="{{ .RelPermalink }}" itemprop="image" />
</a>
{{ end }}
</div>
{{ end }}
{{ if isset .Params "show_gallery" }}
{{ with .Resources.ByType "image" }}
<div class="article-gallery">
{{ range $index, $value := . }}
<a class="gallery-item" href="{{ .RelPermalink }}" rel="gallery_{{ $index }}">
<img src="{{ .RelPermalink }}" itemprop="image" />
</a>
{{ end }}
</div>
{{ end }}
{{ end }}
{{ if .Site.Params.tocInline }}
<div id="toc">
{{ .TableOfContents }}
Expand Down