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

Use links? #20

Open
rctneil opened this issue Jun 16, 2023 · 4 comments
Open

Use links? #20

rctneil opened this issue Jun 16, 2023 · 4 comments

Comments

@rctneil
Copy link

rctneil commented Jun 16, 2023

Hey,

I have added some links into my caption but they don't show up. Are links not allowed?

@thkukuk
Copy link

thkukuk commented Aug 6, 2023

I have the same question, how to add URLs/links in the caption?
If I use "<a href=..." the URL is shown in the image thumbnail and photoswipe seems to think it's an additional image to show. But it's never shown in the caption text.

@dimsemenov
Copy link
Owner

dimsemenov commented Aug 6, 2023

There is an example in the demo, you can check the HTML file.

<div class="pswp-gallery__item">
  <a  
    href="https://cdn.photoswipe.com/photoswipe-demo-images/photos/5/img-2500.jpg" 
    data-pswp-width="2500" 
    data-pswp-height="1668" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/5/img-200.jpg" alt="Demo image 4" />
  </a>
  <div class="pswp-caption-content">
    Short caption with <a href="https://example.com" target="_blank">the link</a>.
  </div>
</div>
childSelector: '.pswp-gallery__item',

@tianmengzhe
Copy link

When I use data separation, I use lightbox.loadAndOpen(1) to open the preview, how do I use the plugin

@nicokaiser
Copy link

Okay, I figured out how to do this:

  • Create a <div> around the image link
  • Move the gallery-item class to the new div
  • Inside the div, create the pswp-caption-content span

So gallery.html might look something like this:

<section class="gallery">
  <div id="gallery" style="visibility: hidden; height: 1px; overflow: hidden">
    {{ $images := slice }}
    {{ range $image :=  .Resources.ByType "image" }}
      {{ $title := "" }}
      {{ with $image.Exif }}
        {{ with .Tags.ImageDescription }}
          {{/* Title from EXIF ImageDescription */}}
          {{ $title = . }}
        {{ end }}
      {{ end }}
      {{ if ne $image.Title $image.Name }}
        {{/* Title from front matter */}}
        {{ $title = $image.Title }}
      {{ end }}
      {{ $images = $images | append (dict
        "Name" $image.Name
        "Title" $title
        "image" $image
        )
      }}
    {{ end }}
    {{ range sort $images (.Params.sort_by | default "Name") (.Params.sort_order | default "asc") }}
      {{ $image := .image }}
      {{ $thumbnail := $image.Filter (slice images.AutoOrient (images.Process "fit 600x600")) }}
      {{ $full := $image.Filter (slice images.AutoOrient (images.Process "fit 1600x1600")) }}
      {{ $color := index $thumbnail.Colors 0 | default "transparent" }}
      <div class="gallery-item">
        <a href="{{ $image.RelPermalink }}" data-pswp-src="{{ $full.RelPermalink }}" data-pswp-width="{{ $full.Width }}" data-pswp-height="{{ $full.Height }}" title="{{ .Title }}" itemscope itemtype="https://schema.org/ImageObject" style="aspect-ratio: {{ $thumbnail.Width }} / {{ $thumbnail.Height }}">
          <figure style="background-color: {{ $color }}; aspect-ratio: {{ $thumbnail.Width }} / {{ $thumbnail.Height }}">
            <img class="lazyload" width="{{ $thumbnail.Width }}" height="{{ $thumbnail.Height }}" data-src="{{ $thumbnail.RelPermalink }}" alt="{{ .Title }}" />
          </figure>
          <meta itemprop="contentUrl" content="{{ $image.RelPermalink }}" />
          {{ with site.Params.Author }}
            <span itemprop="creator" itemtype="https://schema.org/Person" itemscope>
              <meta itemprop="name" content="{{ site.Params.Author.name }}" />
            </span>
          {{ end }}
        </a>
        {{ if $image.Exif }}
          <span class="pswp-caption-content">
            {{ with .Title }}{{ . }}<br />{{ end }}
            {{ with $image.Exif.Tags }}
              {{ if .Model }}
                {{ .Make }} {{ .Model }} &middot;
              {{ end }}
              {{ with .FocalLength }}{{ . }}mm &middot;{{ end }}
              {{ with .ApertureValue }}f/{{ div (math.Round (mul (float .) 10)) 10 }}{{ end }}
              {{ with .ExposureTime }}{{ . }}s &middot;{{ end }}
              {{ with .ISO }}ISO {{ . }}{{ end }}
              {{ with $image.Exif.Long }}
                &middot; <a href="https://www.google.com/maps/place/{{ $image.Exif.Lat }},{{ $image.Exif.Long }}">Map</a>
              {{ end }}
            {{ end }}
          </span>
        {{ end }}
      </div>
    {{ end }}
  </div>
</section>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants