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

allow dots in thumb path or filename #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

it-gro
Copy link

@it-gro it-gro commented Jan 10, 2018

Thx for hugo-easy-gallery! Awesome!

I fixed an issue with the shortcodes (figure.html, gallery.html)
When a path or filename includes dot(s) a wrong thumb filename is assumed.

static/
├── css
│   └── hugo-easy-gallery.css
├── img
│   ├── gohugo.io
│   │   ├── hugo.ipsum.png
│   │   └── hugo.ipsum-thumb.png
│   ├── hugo-dolor.png
│   ├── hugo-dolor-thumb.png
│   ├── hugo.lorem.png
│   └── hugo.lorem-thumb.png
└── js
    └── load-photoswipe.js

e.g.
{{< figure thumb="-thumb" link="/img/hugo.lorem.png" size="400x400" >}}
gives:
<img itemprop="thumbnail" src="/img/hugo-thumb.lorem-thumb.png"
instead of
<img itemprop="thumbnail" src="/img/hugo.lorem-thumb.png"

Test site is here:
https://github.com/it-gro/HugoTestingHegDotIssue
(using blank as theme)

I untabified gallery.html as well - but commited separately.

Thx again!

@liwenyip
Copy link
Owner

Thanks @it-gro, I'll review this asap.

@HunterGraubard
Copy link

HunterGraubard commented Apr 13, 2018

Same issue here. I just came here to report it.

Edit: @it-gro's solution works great. Thanks.

@liwenyip
Copy link
Owner

@it-gro and @HunterGraubard sorry that "asap" has turned into 12 months. Having a look now.

Copy link
Owner

@liwenyip liwenyip left a comment

Choose a reason for hiding this comment

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

Hi @it-gro

Changes to fix the issue with dots in filename are all good. Thanks :-)

I have some queries about the use of relURL, probably all good, but please have a look.

And are there any other places where we should be using relURL instead of baseURL?

Regards
Li-Wen

{{- $.Page.Scratch.Add "figurecount" 1 -}}
<!-- use either src or link-thumb for thumbnail image -->
{{- $filetype := index (findRE "[^.]+$" (.Get "link") ) 0 }}
{{- $thumb := .Get "src" | default (printf "%s.%s" (replaceRE "\\.[^.]+$" (.Get "thumb") (.Get "link") ) $filetype ) | relURL }}
<div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}" {{ with .Get "width" }}style="max-width:{{.}}"{{end}}>
<figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<div class="img"{{ if .Parent }} style="background-image: url('{{ print .Site.BaseURL $thumb }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
<div class="img"{{ if .Parent }} style="background-image: url('{{ print ($thumb | relURL) }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
Copy link
Owner

Choose a reason for hiding this comment

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

Can this be simplified to {{ relURL $thumb }}?

@@ -4,17 +4,17 @@
Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
-->
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{ end }}
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="{{ relURL "/css/hugo-easy-gallery.css" }}" />{{ end }}
Copy link
Owner

Choose a reason for hiding this comment

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

When using relURL do you need to remove the leading slash from the URL, e.g.

{{ relURL "css/hugo-easy-gallery.css" }}

or does it not matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

The slash doesn't matter. Hugo "does the right thing".

@@ -3,7 +3,7 @@
Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
-->
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{ end }}
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="{{ relURL "/css/hugo-easy-gallery.css" }}" />{{ end }}
Copy link
Owner

Choose a reason for hiding this comment

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

See previous comment about leading slash

@@ -14,7 +14,7 @@
-->
<!-- these files are loaded in the theme footer
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="/js/load-photoswipe.js"></script>
<script src="{{.Site.BaseURL}}/js/load-photoswipe.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

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

Is it better to use

{{ relURL "/js/load-photoswipe.js" }}

to avoid a double slash in the output URL?, e.g. /path-to-my-site//js/load-photoswipe.js

@@ -13,7 +13,7 @@
- If your template already loads jQuery in the footer, then you could load load-photoswipe.js from the footer instead
-->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="/js/load-photoswipe.js"></script>
<script src="{{.Site.BaseURL}}/js/load-photoswipe.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

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

See previous comment about using relURL

@liwenyip liwenyip added the bug label Apr 22, 2019
Darthagnon added a commit to Darthagnon/hugo-easy-gallery that referenced this pull request Mar 27, 2022
Resolve liwenyip#17
Merge remote-tracking branch 'pr-it-gro/master' into production
# Conflicts:
#	layouts/shortcodes/figure.html
#	layouts/shortcodes/gallery.html
#	layouts/shortcodes/load-photoswipe-theme.html
#	layouts/shortcodes/load-photoswipe.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants