Skip to content

Commit

Permalink
feat: make images zoomable in the single post page (#345)
Browse files Browse the repository at this point in the history
* feat: make images zoomable in the single post page

* fix: img selector

* feat: allow customizing medium-zoom

* docs: update
  • Loading branch information
g1eny0ung authored Dec 23, 2024
1 parent 35cb451 commit 26a62f1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
8 changes: 6 additions & 2 deletions docs/pages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Add `imageZoomableInPost` param to control the zoomable of images in the single post page [#345](https://github.com/g1eny0ung/hugo-theme-dream/pull/345)

### Changed

- Make TOC scrollable when it is too long
- Make TOC scrollable when it is too long [#340](https://github.com/g1eny0ung/hugo-theme-dream/pull/340)

## [3.9.0] - 2024-11-17

Expand Down Expand Up @@ -179,7 +183,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- Support image optimization for summary images. See [Image Optimization](https://g1en.site/hugo-theme-dream/summary-images#image-optimization) for more details.
- Support image optimization for summary images. See [Image Optimization](https://g1en.site/hugo-theme-dream/summary-images#image-optimization) for more details

### Changed

Expand Down
23 changes: 23 additions & 0 deletions docs/pages/params-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ stickyNav = true
# noDefaultSummaryCover = true
showTableOfContents = true
showSummaryCoverInPost = true
imageZoomableInPost = true
showPrevNextPost = true
# reorderShares = ["x", "facebook", "whatsapp"]

Expand Down Expand Up @@ -262,6 +263,28 @@ Show table of contents in the single post page.

Show summary cover image in the single post page.

### imageZoomableInPost

Make images zoomable in the single post page. This feature uses [medium-zoom](https://github.com/francoischalifour/medium-zoom) under the hood.

<Callout type="info">
For advanced usage, you may want to customize the medium-zoom options. Dream allows you to
create a partial file named `medium-zoom.html` in the `layouts/partials` folder to replace the
default behavior. For example, you can put the following code in the `medium-zoom.html` file:

```html
<script type="module">
import mediumZoom from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
mediumZoom('#dream-single-post-content img', {
// Put your custom options here.
}) // #dream-single-post-content is the id of the post content.
// You can also further control the logic of zooming images.
// Like zooming lazy-loaded images.
</script>
```
</Callout>

### showPrevNextPost

Show previous and next post links in the single post page.
Expand Down
1 change: 1 addition & 0 deletions hugo.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ siteStartYear = 2016
# noDefaultSummaryCover = true
# showTableOfContents = true
# showSummaryCoverInPost = true
# imageZoomableInPost = true
# showPrevNextPost = true
# reorderShares = ["x", "facebook", "whatsapp"]

Expand Down
21 changes: 17 additions & 4 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ <h1 itemprop="headline">{{ .Title }}</h1>
</div>
</header>

{{ if and .Params.Cover site.Params.showSummaryCoverInPost }}
<img src="{{ .Params.Cover }}" alt="{{ .Title }}" />
{{ end }}
<section id="dream-single-post-content" itemprop="articleBody">
{{ if and .Params.Cover site.Params.showSummaryCoverInPost }}
<img src="{{ .Params.Cover }}" alt="{{ .Title }}" />
{{ end }}

{{ .Content | emojify }}
{{ .Content | emojify }}
</section>

{{ if site.Params.showPrevNextPost }}
<div class="divider"></div>
Expand Down Expand Up @@ -149,4 +151,15 @@ <h1 itemprop="headline">{{ .Title }}</h1>
</script>
{{ end }}

{{ if site.Params.imageZoomableInPost }}
{{ if fileExists "layouts/partials/medium-zoom.html" }}
{{ partialCached "medium-zoom.html" . }}
{{ else }}
<script type="module">
import mediumZoom from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
mediumZoom('#dream-single-post-content img')
</script>
{{ end }}
{{ end }}

{{ end }}

0 comments on commit 26a62f1

Please sign in to comment.