Swiftpack.co - markbattistella/image-zoom-publish-plugin as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by markbattistella.
markbattistella/image-zoom-publish-plugin 1.1.0
Add a Medium.com style image zoom for items within the document content.
⭐️ 0
🕓 3 weeks ago
.package(url: "https://github.com/markbattistella/image-zoom-publish-plugin.git", from: "1.1.0")

Image Zoom for Publish

Add a medium.com style image zoom for images within your document.

The script allows images to be zoomed to the full width of the view port so the user can expand images beyond the container width.

Users can continue scrolling and theimage will resign into its original place.

demo video


To install it into your Publish package, add it as a dependency within your Package.swift manifest:

let package = Package(
  dependencies: [
      name: "ImageZoom",
      url: "https://github.com/markbattistella/image-zoom-publish-plugin",
      from: "1.1.0"
  targets: [
    .target(dependencies: ["ImageZoom"])

You will need to add two javascript items into your <footer>.

The best way to inject the script is to add it to your .footer element:

extension Node where Context == HTML.BodyContext {
  static func footer(for site: Website) -> Node {
    return .footer(
      .raw("<script src='zoom-image.js'></script>"),
      .raw("<script>mediumZoom('[data-zoomable="true"]', { margin: 20, background: '#FFF' });</script>")


In the script configuration is where you can set up the medium.com style zooming.

mediumZoom('[data-zoomable="true"]', {
	margin: 20,
	background: '#FFF'

The first line is mandatory otherwise the images won't register the script.

You can change the margin and the background.

The margin is how much you want the image to be inset when enlarged into full view. It is in pixels.

The background is the colour of the overlay which the image sits on top of. The best way to handle it is to use a CSS variable and trigger it for light and dark mode.

For example:

::root {
  --background-colour: rgb( 255, 255, 255 );

@media all and (prefers-color-scheme: dark) {
	::root {
	  --background-colour: rgb( 0, 0, 0 );
mediumZoom('[data-zoomable="true"]', {
	margin: 20,
	background: 'var(--background-colour)'



The plugin can then be used within any publishing pipeline like this:

import ImageZoom

try DeliciousRecipes().publish(using: [

By default it will show the image captions, however if you wish to hide them under the image do so by installing the plugin as:

import ExtraComponents

try DeliciousRecipes().publish(using: [
  .installPlugin(.zoomImage(showCaption: false))


When writing your markdown documents you add an image as you normally would. This will automatically be transformed into accepting the zooming attributes.

![My image](https://raw.github.com/markbattistella/image-zoom-publish-plugin/main//my-awesome-image.jpg)

If you want to disable the zooming on a specific image add the nozoom attribute after the image url:

![My image - this wont zoom](https://raw.github.com/markbattistella/image-zoom-publish-plugin/main//my-awesome-image.jpg nozoom)

It is case insensitive, so any variation should work: NOZOOM, noZoom, NoZoom, or even nOZooM


I've turned off Issues and if you wish to add/change the codebase please create a Pull Request.

This way everyone can allow these components to grow, and be the best rather than waiting on me to write it.

How to help

  1. Clone the repo: git clone https://github.com/markbattistella/image-zoom-publish-plugin.git
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit the pull request


Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Release Notes

3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics