Reworked figure shortcode to use Page Resources

This commit is contained in:
Chris Hodapp 2020-04-24 23:52:27 -04:00
parent e26a98b711
commit 4969191708
4 changed files with 76 additions and 26 deletions

3
.gitignore vendored
View File

@ -33,3 +33,6 @@ Temporary Items
# End of https://www.gitignore.io/api/macos
*~
# Local Netlify folder
.netlify

2
.lfsconfig Normal file
View File

@ -0,0 +1,2 @@
[lfs]
url = https://5f7bd828-f7e2-4481-83c3-178851380a2b.netlify.app/.netlify/large-media

View File

@ -6,24 +6,37 @@ tags:
{{< load-photoswipe >}}
<!-- link2 is to the actual page (until I can figure out how to link this properly) -->
<!-- class="no-photoswipe" to make a figure just link to 'link' but only if it's an image -->
{{< gallery >}}
{{< figure src="/works/ramhorn-0004.jpg" title="Ram's Horn (September 15, 2019)" link="2019-09-15-rams-horns.md" >}}
{{< figure src="/works/2011-11-04-crystal1.png" title="Crystal #1 (November 4, 2011)" link="2011-11-04-crystal1.md" >}}
{{< figure src="/works/2011-09-09-conch.jpg" title="Conch (September 9, 2011)" link="2011-09-11-conch.md" >}}
{{< figure src="/works/2005-08-23-shear6.jpg" title="Shear #6 (August 23, 2005)" link="2005-08-23-shear6.md" >}}
{{< figure src="/works/2005-08-19-beach.jpg" title="Beach (August 19, 2005)" link="2005-08-19-beach.md" >}}
{{< figure src="/works/2005-08-06-tears.jpg" title="Tears (August 6, 2005)" link="2005-08-06-tears.md" >}}
{{< figure src="/works/2005-08-05-oasis.jpg" title="Oasis (August 5, 2005)" link="2005-08-05-oasis.md" >}}
{{< figure src="/works/2005-07-08-vaguely-celtic-metalwork.jpg" title="Vaguely Celtic Metalwork (July 8, 2005)" link="2005-07-08-vaguely-celtic-metalwork.md" >}}
{{< figure src="/works/2005-07-05-spiral-isosurface2.jpg" title="Spiral Isosurface (July 5, 2005)" link="2005-07-05-spiral.md" >}}
{{< figure src="/works/2005-06-09-superellipsoids.jpg" title="Superellipsoids (June 9, 2005)" link="2005-06-09-superellipsoids.md" >}}
{{< figure src="/works/2005-05-11-unknown-planet.jpg" title="Unknown Planet (May 11, 2005)" link="2005-05-11-unknown-planet.md" >}}
{{< figure src="/works/2005-05-10-haze.png" title="Haze 3 (May 10, 2005)" link="2005-05-10-haze.md" >}}
{{< figure src="/works/2004-12-23-butterfly.jpg" title="Butterfly (December 23, 2004)" link="2004-12-23-butterfly.md" >}}
{{< figure src="/works/2004-09-28-m4c-intro.png" title="M4C intro (September 28, 2004)" link="2004-09-28-m4c-intro.md" >}}
{{< figure src="/works/2004-09-19-roses.png" title="Roses (September 19, 2004)" link="2004-09-19-roses.md" >}}
{{< figure src="/works/2004-07-16-crunchy-bubbles.jpg" title="Crunchy Bubbles (July 16, 2004)" link="2004-07-16-crunchy-bubbles.md" >}}
{{< figure src="/works/2004-07-15-kpovmodeler-test.jpg" title="KPovModeler test (?) (July 15, 2004)" link="2004-07-15-kpovmodeler.md" >}}
{{< figure src="/works/1999-12-22-table.png" title="'Table' or something (Dec 22, 1999)" link="1999-12-22-table-polyray.md" >}}
{{< figure src="/works/1999-12-21-moo.png" caption="*Foo* [link](./link)" title="Moo (Dec 21, 1999)" link="../1999-12-21-moo-polyray/" class="no-photoswipe">}}
{{< figure resource="placeholder/screw0006.jpg" title="Screw (April 12, 2020)" >}}
{{< figure resource="placeholder/cinquefoil0010.png" title="Cinquefoil (November 16, 2019)" caption="Foo">}}
{{< figure resource="placeholder/dream20191115b_1000.png" title="Dream (November 15, 2019)" >}}
{{< figure resource="placeholder/ramhorn_branch_0002.png" title="ramhorn_branch? (December 16, 2019)" >}}
{{< figure resource="portfolio/ramhorn-0004.jpg" title="Ram's Horn (September 15, 2019)" link2="../2019-09-15-rams-horns.md" >}}
{{< figure resource="placeholder/iso_draft_0017.png" title="Isosurface try 2 (August 24, 2019)" >}}
{{< figure resource="placeholder/appleseed_spiral_thing_thumb.jpg" title="Appleseed spiral thing (August 20, 2018)" >}}
{{< figure resource="placeholder/appleseed_spiral_thing2_thumb.jpg" title="Appleseed spiral thing 2 (June 25, 2018)" >}}
{{< figure resource="placeholder/2011-11-25-electron.png" title="Electron (November 25, 2011)" >}}
{{< figure resource="portfolio/2011-11-04-crystal1.png" title="Crystal #1 (November 4, 2011)" link2="../2011-11-04-crystal1.md" >}}
{{< figure resource="placeholder/2011-11-03-feather2-thumb.jpg" title="Feather #2 (November 3, 2011)" >}}
{{< figure resource="placeholder/2011-11-03-feather1-thumb.jpg" title="Feather #1 (November 3, 2011)" >}}
{{< figure resource="portfolio/2011-09-09-conch.jpg" title="Conch (September 9, 2011)" link2="../2011-09-11-conch.md" >}}
{{< figure resource="placeholder/2011-09-09-flow1-thumb.jpg" title="Flow? (September 9, 2011)" >}}
{{< figure resource="portfolio/2005-08-23-shear6.jpg" title="Shear #6 (August 23, 2005)" link2="../2005-08-23-shear6.md" >}}
{{< figure resource="portfolio/2005-08-19-beach.jpg" title="Beach (August 19, 2005)" link2="../2005-08-19-beach.md" >}}
{{< figure resource="portfolio/2005-08-06-tears.jpg" title="Tears (August 6, 2005)" link2="../2005-08-06-tears.md" >}}
{{< figure resource="portfolio/2005-08-05-oasis.jpg" title="Oasis (August 5, 2005)" link2="../2005-08-05-oasis.md" >}}
{{< figure resource="portfolio/2005-07-08-vaguely-celtic-metalwork.jpg" title="Vaguely Celtic Metalwork (July 8, 2005)" link2="../2005-07-08-vaguely-celtic-metalwork.md" >}}
{{< figure resource="portfolio/2005-07-05-spiral-isosurface2.jpg" title="Spiral Isosurface (July 5, 2005)" link2="../2005-07-05-spiral.md" >}}
{{< figure resource="portfolio/2005-06-09-superellipsoids.jpg" title="Superellipsoids (June 9, 2005)" link2="../2005-06-09-superellipsoids.md" >}}
{{< figure resource="portfolio/2005-05-11-unknown-planet.jpg" title="Unknown Planet (May 11, 2005)" link2="../2005-05-11-unknown-planet.md" >}}
{{< figure resource="portfolio/2005-05-10-haze.png" title="Haze 3 (May 10, 2005)" link2="../2005-05-10-haze.md" >}}
{{< figure resource="portfolio/2004-12-23-butterfly.jpg" title="Butterfly (December 23, 2004)" link2="../2004-12-23-butterfly.md" >}}
{{< figure resource="portfolio/2004-09-28-m4c-intro.png" title="M4C intro (September 28, 2004)" link2="../2004-09-28-m4c-intro.md" >}}
{{< figure resource="portfolio/2004-09-19-roses.png" title="Roses (September 19, 2004)" link2="../2004-09-19-roses.md" >}}
{{< figure resource="portfolio/2004-07-16-crunchy-bubbles.jpg" title="Crunchy Bubbles (July 16, 2004)" link2="../2004-07-16-crunchy-bubbles.md" >}}
{{< figure resource="portfolio/2004-07-15-kpovmodeler-test.jpg" title="KPovModeler test (?) (July 15, 2004)" link2="../2004-07-15-kpovmodeler.md" >}}
{{< figure resource="portfolio/1999-12-22-table.png" title="'Table' or something (Dec 22, 1999)" link2="../1999-12-22-table-polyray.md" >}}
{{< figure resource="portfolio/1999-12-21-moo.png" caption="*Foo* [link](./link)" title="Moo (Dec 21, 1999)" caption="*Foo* [link](./link)" link2="../1999-12-21-moo-polyray/">}}
{{< /gallery >}}

View File

@ -3,21 +3,53 @@ Put this file in /layouts/shortcodes/figure.html
NB this overrides Hugo's built-in "figure" shortcode but is backwards compatible
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 }}
{{- $.Page.Scratch.Add "figurecount" 1 -}}
<!-- Some constants: -->
<!-- What page to find images as Page Resources in -->
{{ $pagename := "images" }}
<!-- Thumbnail image size/type -->
{{ $resize_opts := "600x jpg" }}
<!-- TODO: This isn't generating a JPEG on my configuration. Not sure why. -->
<!-- if 'resource' is given, look there in the "images" bundle -->
<!-- (yes, my description is probably at least 50% wrong) -->
{{ $thumb := "" }}
{{ $href := "" }}
{{ if .Get "resource" }}
{{ $page := $.Site.GetPage $pagename }}
{{- if eq $page nil -}}
{{- errorf "Error: Can't find page %s" $pagename -}}
{{- end -}}
{{ $resource := (.Get "resource") }}
{{ $original := $page.Resources.GetMatch (printf "*%s*" $resource) }}
{{- if eq $original nil -}}
{{- errorf "Error: Can't find resource %s on page %s" $resource $pagename -}}
{{- end -}}
{{ .Scratch.Set "image" ($original.Resize $resize_opts) }}
{{ $image := .Scratch.Get "image" }}
{{- $thumb = $image.RelPermalink }}
{{- $href = $original.RelPermalink }}
{{ else }}
<!-- use either src or link-thumb for thumbnail image -->
{{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
{{- $thumb = .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
{{- $href = .Get "link" | default (.Get "src") }}
{{ end }}
<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('{{ $thumb | relURL }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
<img itemprop="thumbnail" src="{{ $thumb | relURL }}" {{ with .Get "alt" | default (.Get "caption") }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
<img itemprop="thumbnail" src="{{ $thumb | relURL }}" {{ with .Get "alt" | default (.Get "caption" | markdownify) }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
</div>
{{ with .Get "link" | default (.Get "src") }}<a href="{{.}}" itemprop="contentUrl"></a>{{ end }}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
<a href="{{ $href }}" itemprop="contentUrl"></a>
{{- if or (or (.Get "title") (.Get "caption" | markdownify)) (.Get "attr")}}
<figcaption>
{{- with .Get "title" }}<h4>{{.}}</h4>{{ end }}
{{- if or (.Get "caption") (.Get "attr")}}
{{- if or (.Get "caption" | markdownify) (.Get "attr")}}
<p>
{{- .Get "caption" -}}
{{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}}