-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make images zoomable in the single post page (#345)
* feat: make images zoomable in the single post page * fix: img selector * feat: allow customizing medium-zoom * docs: update
- Loading branch information
Showing
4 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ stickyNav = true | |
# noDefaultSummaryCover = true | ||
showTableOfContents = true | ||
showSummaryCoverInPost = true | ||
imageZoomableInPost = true | ||
showPrevNextPost = true | ||
# reorderShares = ["x", "facebook", "whatsapp"] | ||
|
||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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 }} |