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

Add carousel option to the posts #32

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4ad535
Add layout changes for including the carousel after the post
Letme Jan 23, 2021
acb29d4
Add examples for the carousel changes
Letme Jan 23, 2021
4333e8a
Add carousel also to post single
Letme Jan 24, 2021
3da8b4f
Add arrows images
Letme Jan 24, 2021
fabf93a
Change the form of the carousel declaration in FrontMatter
Letme Jan 25, 2021
c1e6f71
Use data/assets.toml to define external scripts
Letme Jan 25, 2021
c89b1fd
Drop images in favor of the font arrow
Letme Jan 25, 2021
177f161
Update to usage of get-image from utils
Letme Jan 26, 2021
3a07d8f
Use get-image
Letme Jan 26, 2021
39b7b9c
Refactor the images and positions
Letme Jan 26, 2021
c18eed8
Set carousel position
Letme Jan 26, 2021
3bc5853
Non working commit: Trying to replace carousel with featuredImage
Letme Jan 26, 2021
9f2cc00
Revert "Set carousel position"
Letme Jan 27, 2021
58424c7
Replace carousel with a featured image
Letme Jan 28, 2021
4b4ec52
Merge branch 'master' of https://github.com/wangchucheng/hugo-eureka …
Letme Jan 28, 2021
6d1b6bf
Merge branch 'master' of https://github.com/wangchucheng/hugo-eureka …
Letme Feb 5, 2021
073aac5
Merge branch 'master' of https://github.com/wangchucheng/hugo-eureka …
Letme Feb 5, 2021
4f0ffba
Split the if
Letme Feb 5, 2021
2ad4640
Merge branch 'master' of https://github.com/wangchucheng/hugo-eureka …
Letme Mar 14, 2021
d648de6
Fix the non-working featured image in `/posts/`
Letme Mar 14, 2021
aaf64ec
Dropping the added pixles on the side of the image
Letme Mar 14, 2021
f83b573
Enable controls (arrows) in the tiny-slider
Letme Mar 14, 2021
036bed5
First carousel image can be a featured image
Letme Mar 18, 2021
dc1856e
Merge branch 'master' of https://github.com/wangchucheng/hugo-eureka …
Letme May 21, 2021
3fd5bfb
Merge branch 'main' into add_carousel
Letme Jul 29, 2022
6027e2b
Adjust featured to the new print of img style
Letme Aug 9, 2022
ebd7053
Remove the duplicate featured image
Letme Aug 10, 2022
4e7bee4
Add the carousel to post-article as it is residing there nowdays
Letme Aug 10, 2022
816a197
Carousel and featured image should not be decided in post-article
Letme Aug 10, 2022
c2fd84c
Move carousel to the single layout
Letme Aug 10, 2022
71a3bca
Align doc layout for carousel
Letme Aug 10, 2022
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
34 changes: 34 additions & 0 deletions assets/css/carousel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.thumbnails {
margin: 20px 0;
text-align: center;
}
.thumbnails li {
display: inline-block;
cursor: pointer;
border: 5px solid #fff;
}
.thumbnails .tns-nav-active {
background: none;
border-color: #000;
}
.thumbnails li { width: 50px; }
.thumbnails img { vertical-align: bottom; height: auto; max-height: 50px; }
.controls { text-align: center; }
.controls li {
display: block;
position: relative;
height: 60px;
width: 32px;
line-height: 60px;
/* margin-top: calc(-60% - 50px); */
margin-top: -70px;
padding: 0px 0px;
cursor: pointer;
transition: background 0.3s;
}
.controls li img { display: inline-block; vertical-align: middle; }
.controls .prev { left: 0; }
.controls .next { float: right;
margin-top: -63px;}
.controls li:hover { background: #f2f2f2; }

12 changes: 11 additions & 1 deletion data/assets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@

[katex.autoRender]
url = "https://cdn.jsdelivr.net/npm/katex@%s/dist/contrib/auto-render.min.js"
sri = "sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa"
sri = "sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa"

[tinyslider]
version = "2.9.3"

[tinyslider.css]
url = "https://cdn.jsdelivr.net/npm/tiny-slider@%s/dist/tiny-slider.css"

[tinyslider.js]
url = "https://cdn.jsdelivr.net/npm/tiny-slider@%s/dist/tiny-slider.min.js"

42 changes: 42 additions & 0 deletions exampleSite/content/posts/carousel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
+++
title = "Carousel with image description"
description = "Post with carousel which has image description, but can also omit it "
summary = ""
toc = true
authors = ["Example Author"]
tags = ["image"]
categories = ["themes"]
series = ["Themes Guide"]
date = "2020-05-26"
lastmod = "2020-05-26"
draft = false

carousel = [
{ image = "../carousel1.png", description = "Caption of the first image." },
{ image = "../carousel2.png", description = "Caption of the second image." },
{ image = "../carousel3.png", description = "The next image does not have a caption." },
{ image = "../carousel4.png" }
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly what I want. In order to unify the format, I think the image can be renamed to url

Besides, how about combining featuredImage and carousel into one attribute? When the new featuredImage is a string or an array which only contains one item, it will be the old featuredImage. And if this attribute has more than one item, carousel will be used. What do you think of this idea?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of too much automatization as I see a use case where featured image is not part of the carousel set. For example in featured image you make something totally related to title, to attract a reader, but then in carousel you just have images of details.

Based on below proposal of adding a video, I would leave image as that would enable us to use video and swap the text inside div from <img> to <video>

+++

This post includes a carousel on the end. It is displayed like a gallery and you can
move around the images so that they do not take too much space. Style is at the moment
not configurable, but configuration of the carousel style could be done in the future.

<!--more-->

## Example subtitle for carousel

Aenean vehicula non elit id varius. Mauris condimentum lacinia mollis. Nullam quis cursus metus, eget mattis erat. Aliquam nec ante lacus. In tellus augue, iaculis vitae sollicitudin quis, tempor nec urna. Aenean ut fermentum erat, vel gravida ligula. Etiam sed ex aliquet, egestas nibh eu, iaculis mi. Nunc sit amet fermentum ex. Sed convallis ac arcu tristique rhoncus. Suspendisse potenti.

Proin justo purus, porttitor et semper ut, commodo et nibh. Nam malesuada id arcu in tempus. Ut ornare vestibulum ultrices. Nullam tempor lectus quis ornare viverra. Vestibulum fringilla turpis ac leo fermentum, et dictum nisi consectetur. Integer ullamcorper fringilla mi, non volutpat sapien ultrices vel. Phasellus at blandit neque, pulvinar rutrum ante.

Etiam auctor, elit vel pretium consequat, orci magna aliquet dolor, quis varius felis purus ut elit. Sed ultrices feugiat blandit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Ut accumsan pulvinar purus et ornare. Vestibulum et tortor eget lacus hendrerit porttitor. Cras dapibus ac est posuere mattis. Pellentesque eu ligula ultricies, interdum nulla vel, sollicitudin ligula. Suspendisse sit amet massa sed dui placerat pharetra. Vestibulum massa sem, congue in vehicula vitae, aliquam eu mi. Suspendisse eget laoreet velit. Cras felis enim, molestie in enim nec, mollis venenatis lectus. Donec tincidunt, mi vel interdum varius, urna metus aliquet velit, ut venenatis nulla orci nec lectus. Nam id tortor imperdiet, tempor massa eget, congue nisl. Suspendisse venenatis facilisis orci, non scelerisque risus volutpat sit amet.

## Example subtitle2 for the carousel

After this section, you are suppose to see the carousel.

Aliquam posuere diam non ligula tristique congue. Donec dignissim eu justo sed dictum. Praesent at massa erat. Praesent mollis viverra velit. Aliquam maximus pharetra massa a efficitur. Sed tempus egestas purus sit amet tempor. Donec porttitor varius nisi, eu venenatis risus gravida id. Pellentesque blandit nunc non urna consectetur commodo. Sed at feugiat felis, sit amet malesuada nunc. Curabitur in tempor nisl. Pellentesque accumsan est orci, in commodo felis accumsan facilisis. Nulla maximus suscipit posuere. Nulla et consequat mauris, fermentum ultricies tellus.

Maecenas consectetur ac libero vitae congue. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec tortor eu lectus placerat varius. Mauris a nisi consectetur, ornare dolor ut, rutrum ligula. Sed enim nisl, fermentum a dictum vel, vestibulum ut odio. Suspendisse laoreet quis urna eu vestibulum. Maecenas commodo augue ex, eu egestas nulla aliquet ut. Cras aliquam dui ipsum, nec sodales erat convallis sit amet. Donec porttitor posuere hendrerit. Sed imperdiet at purus eget tempus. In ac est urna.
Binary file added exampleSite/content/posts/carousel1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exampleSite/content/posts/carousel2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions exampleSite/content/posts/carousel2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
+++
title = "Carousel with image array"
description = "Post with carousel which does not have description per image"
summary = ""
toc = true
authors = ["Example Author"]
tags = ["image"]
categories = ["themes"]
series = ["Themes Guide"]
date = "2020-05-26"
lastmod = "2020-05-26"
draft = false

carousel = ["../carousel1.png", "../carousel2.png", "../carousel3.png", "../carousel4.png"]
+++

This post includes a carousel without descriptions on the end. It is displayed like a gallery and you can
move around the images so that they do not take too much space. Style is at the moment
not configurable, but configuration of the carousel style could be done in the future.

<!--more-->

## Example subtitle for carousel

Aenean vehicula non elit id varius. Mauris condimentum lacinia mollis. Nullam quis cursus metus, eget mattis erat. Aliquam nec ante lacus. In tellus augue, iaculis vitae sollicitudin quis, tempor nec urna. Aenean ut fermentum erat, vel gravida ligula. Etiam sed ex aliquet, egestas nibh eu, iaculis mi. Nunc sit amet fermentum ex. Sed convallis ac arcu tristique rhoncus. Suspendisse potenti.

Proin justo purus, porttitor et semper ut, commodo et nibh. Nam malesuada id arcu in tempus. Ut ornare vestibulum ultrices. Nullam tempor lectus quis ornare viverra. Vestibulum fringilla turpis ac leo fermentum, et dictum nisi consectetur. Integer ullamcorper fringilla mi, non volutpat sapien ultrices vel. Phasellus at blandit neque, pulvinar rutrum ante.

Etiam auctor, elit vel pretium consequat, orci magna aliquet dolor, quis varius felis purus ut elit. Sed ultrices feugiat blandit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Ut accumsan pulvinar purus et ornare. Vestibulum et tortor eget lacus hendrerit porttitor. Cras dapibus ac est posuere mattis. Pellentesque eu ligula ultricies, interdum nulla vel, sollicitudin ligula. Suspendisse sit amet massa sed dui placerat pharetra. Vestibulum massa sem, congue in vehicula vitae, aliquam eu mi. Suspendisse eget laoreet velit. Cras felis enim, molestie in enim nec, mollis venenatis lectus. Donec tincidunt, mi vel interdum varius, urna metus aliquet velit, ut venenatis nulla orci nec lectus. Nam id tortor imperdiet, tempor massa eget, congue nisl. Suspendisse venenatis facilisis orci, non scelerisque risus volutpat sit amet.

## Example subtitle2 for the carousel

After this section, you are suppose to see the carousel.

Aliquam posuere diam non ligula tristique congue. Donec dignissim eu justo sed dictum. Praesent at massa erat. Praesent mollis viverra velit. Aliquam maximus pharetra massa a efficitur. Sed tempus egestas purus sit amet tempor. Donec porttitor varius nisi, eu venenatis risus gravida id. Pellentesque blandit nunc non urna consectetur commodo. Sed at feugiat felis, sit amet malesuada nunc. Curabitur in tempor nisl. Pellentesque accumsan est orci, in commodo felis accumsan facilisis. Nulla maximus suscipit posuere. Nulla et consequat mauris, fermentum ultricies tellus.

Maecenas consectetur ac libero vitae congue. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec tortor eu lectus placerat varius. Mauris a nisi consectetur, ornare dolor ut, rutrum ligula. Sed enim nisl, fermentum a dictum vel, vestibulum ut odio. Suspendisse laoreet quis urna eu vestibulum. Maecenas commodo augue ex, eu egestas nulla aliquet ut. Cras aliquam dui ipsum, nec sodales erat convallis sit amet. Donec porttitor posuere hendrerit. Sed imperdiet at purus eget tempus. In ac est urna.
Binary file added exampleSite/content/posts/carousel3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exampleSite/content/posts/carousel4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ <h1 class="font-bold text-3xl text-primary-text">{{ .Title }}</h1>
<div class="content">
{{ .Content}}
</div>

{{ if isset $.Params "carousel" }}
{{ partial "components/carousel" . }}
{{ end }}

{{ with .GetTerms "tags" }}
{{ partial "components/post-tags" . }}
{{ end }}
Expand Down Expand Up @@ -62,4 +67,4 @@ <h2 class="text-lg font-semibold mb-4">{{ i18n "seeAlso" }}</h2>
hljs.initHighlightingOnLoad();
})
</script>
{{ end }}
{{ end }}
54 changes: 54 additions & 0 deletions layouts/partials/components/carousel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<section>
<div id="tinyslider-carousel">
{{ range $.Params.carousel }}
<div class="item">
<div>
{{ if reflect.IsMap . }}
{{ $image := partial "utils/get-image" (dict "context" $ "url" .image "keyword" .image) }}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this get-image function calls (3a07d8f), yet the URL it produces is wrong as images are in public/posts yet this function resolves it to root .

Copy link
Owner

@wangchucheng wangchucheng Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed before, there is a mistake in organizing images in content folder. You can create a folder named carousel in this case and rename carousel.md to index.md and move it to carousel folder along with those images. And images will be in localhost:1313/posts/carousel/carousel1.jpg for example. The front matter should be carousel1.jpg for example. Please note that the images you uploaded is jpg, but the filename you entered is png.

This is called Leaf Bundles in Hugo.

And if you have done that, get-image should give you a correct result as I tested it in my machine.

Copy link
Author

@Letme Letme Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done this in 39b7b9c .

<img class="img-responsive" src="{{ $image }}" alt="{{ .description }}" />
</div>
{{ if .description }}
<p>{{ .description }}</p>
{{ end }}
{{ else }}
{{ $image := partial "utils/get-image" (dict "context" $ "url" . "keyword" .) }}
<img class="img-responsive" src="{{ $image }}" />
</div>
{{ end }}
</div>
{{ end }}
</div>
<div class="tinyslider-controls">
<ul class="thumbnails" id="customize-thumbnails">
{{ range $.Params.carousel }}
<li class="item">
{{ if reflect.IsMap . }}
{{ $image := partial "utils/get-image" (dict "context" $ "url" .image "keyword" .image) }}
<img class="img-responsive" src="{{ $image }}" alt="{{ .description }}" width="50px" />
{{ else }}
{{ $image := partial "utils/get-image" (dict "context" $ "url" . "keyword" .) }}
<img class="img-responsive" src="{{ $image }}" width="50px" />
{{ end }}
</li>
{{ end }}
</ul>
<ul class="controls" id="customize-controls">
<li class="prev"><i class="fas fa-angle-left"></i></li>
<li class="next"><i class="fas fa-angle-right"></i></li>
</ul>
</div>
<script src="{{ printf .Site.Data.assets.tinyslider.js.url .Site.Data.assets.tinyslider.version }}"></script>
<script> const slider = tns({
container: '#tinyslider-carousel',
items: 1,
autoplay: false,
center: true,
nav: true,
navContainer: "#customize-thumbnails",
controlsContainer: "#customize-controls",
navAsThumbnails: true,
autoHeight: true,
});
</script>

</section>
6 changes: 5 additions & 1 deletion layouts/partials/components/doc-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ <h1 class="font-bold text-3xl text-primary-text">{{ .Title }}</h1>
<div class="content">
{{ .Content}}
</div>
{{ if isset $.Params "carousel" }}
{{ partial "components/carousel" . }}
{{ end }}

{{ with .GetTerms "tags" }}
{{ partial "components/post-tags" . }}
{{ end }}
Expand Down Expand Up @@ -166,4 +170,4 @@ <h1 class="font-bold text-3xl text-primary-text">{{ .Title }}</h1>
{{ $versions := .context.Scratch.Get "versions" }}
{{ .context.Scratch.Delete "versions" }}
{{ return $versions }}
{{ end }}
{{ end }}
9 changes: 7 additions & 2 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@
{{ end }}
<title>{{ partial "get-title" . }}</title>

{{- $assets := .Site.Data.assets }}
{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
<link rel="stylesheet" href="{{ $eurekaCSS.Permalink }}">
{{ if isset $.Params "carousel" }}
<link preload rel="stylesheet" href="{{ printf $assets.tinyslider.css.url $assets.tinyslider.version }}" crossorigin>
{{- $carouselCSS := resources.Get "css/carousel.css" | minify }}
<link rel="stylesheet" href="{{ $carouselCSS.Permalink }}">
{{ end }}

{{- $eurekaJS := resources.Get "js/eureka.js" | minify }}
<script defer src="{{ $eurekaJS.Permalink }}"></script>
Expand All @@ -64,7 +70,6 @@
href="https://fonts.googleapis.com/css2?family=Lora:wght@400;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap"
as="style" onload="this.onload=null;this.rel='stylesheet'">

{{- $assets := .Site.Data.assets }}
<link rel="stylesheet" href="{{ printf $assets.highlightjs.css.url $assets.highlightjs.version }}"
{{ with $assets.highlightjs.css.sri }} integrity="{{ . }}" {{ end }} media="print"
onload="this.media='all';this.onload=null" crossorigin>
Expand Down Expand Up @@ -149,4 +154,4 @@
{{- partial "components/opengraph" . }}
{{- range .AlternativeOutputFormats }}
{{- printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{- end }}
{{- end }}