Hi,
Inspired by the post/blog of @brunoamaral I’m trying to setup a simple hugo site that uses Photoswipe for displaying images. Unfortunately the gallery is just rendered as a list of images that link to full size images. The Photoswipe gallery functionality of displaying them isn’t working. The rendered HTML of the gallery post page looks okay to me, so I suspect it has to do with the CSS and/or Javascript. Does anyone have an idea on what I’m doing wrong here?
Here is what I roughly did so far:
add the files from Photoswipe plus initphotoswipe.js into static/plugins/photoswipe
init Photoswipe in the layouts/partials/footer.html
add custom.css public/css that is used by the shortcode below
create the layouts/shortcodes/gallery.html shortcode that the “post” will use
create sample post in content/post/index.md that uses the gallery
I run it with:
git clone --recurse-submodules https://github.com/kenwphoto/hugo-photoswipe-test.git
cd hugo-photoswipe-test
hugo server
Any hints to get it working are appreciated.
Regards,
Ken
Thanks for your quick reply. I’d have thought if the JavaScript files cannot be found, I’d see an error on the console in the browsers debugging tooling, but there aren’t any.
@jmooring you are right, when replacing the shortcut with contents from the initial blog post it does work for me as well. Thank you!
I sort of like the approach from the blog post though, as it puts the CSS, Javascript, and HTML in different places.
You are probably right, but I don’t know what I’m missing yet. The blog post describes five steps, that I think I’ve done as well. Do you have any specific hints?
Thanks for sharing the code, you have a PR waiting for you to approve
I am not always able to debug the implementations people make of this shortcode, this was an exception. And thank you for posting on the forum, I get emails once in a while and this way people can find help by themselves.
@brunoamaral this is it. The div in the gallery shortcode was closed too early. I was stripping down class attributes from that div by commenting the original and create a new line but I overlooked that my text editor put in a closing tag automatically.
Thank you for the PR! I appreciate it. There’s one aspect I don’t quite understand yet: Why do you move the PhotoSwipe initialization from layouts/partials/site-footer.html to layouts/_default/baseof.html as well?
Ah, thanks! Yeah, the original base template of the Ananke theme pulls in the footer.html contents inside the <body> and with your approach the <link> and <script>tags that reference the Photoswipe CSS and JavaScript files can be placed outside the body.
I was referring to the photoswipe version 5 which is still in beta heavily focused on clean code. and made a single css file and even support custom icons etc.
in that case, the answer is maybe if I have the need to update my blog to use the new code.
@kenw that would be another thread but to answer your question the homepage is a section and therefore can’t access resources in a folder for some reasons.
You can use the get resources on a seperate page to add all the images and then on home page use the .Site.GetPage "the-page-you-created" and simply use the photoswipe partial weird way I know I tried this using the shortcode of @brunoamaral yesterday and it works for me
Thanks @brunoamaral I follow you for updates on photoswipe