From a973344b66abf7992ba59514679000ccde9dc26e Mon Sep 17 00:00:00 2001 From: Charlton Trezevant Date: Sun, 5 Jun 2022 11:43:09 -0400 Subject: [PATCH 1/3] Move loading of pdf.js and CSS styles to a separate partial --- layouts/partials/embed-pdf-dependencies.html | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 layouts/partials/embed-pdf-dependencies.html diff --git a/layouts/partials/embed-pdf-dependencies.html b/layouts/partials/embed-pdf-dependencies.html new file mode 100644 index 0000000..4cbf151 --- /dev/null +++ b/layouts/partials/embed-pdf-dependencies.html @@ -0,0 +1,51 @@ + {{ if .HasShortcode "embed-pdf" }} + + + + {{ end }} From 6d00f04f9ff4b1ee18c78dea0367263404f075cd Mon Sep 17 00:00:00 2001 From: Charlton Trezevant Date: Sun, 5 Jun 2022 11:48:41 -0400 Subject: [PATCH 2/3] Enables multiple PDF embeds by appending a unique ID to each shortcode instance's elements. Migrates JS initialization of the viewer to an IIFE rather than using window.onload. Moves pagination controls underneath the PDF image and adds a link to the original document. This link will also appear for users with JavaScript disabled. --- layouts/shortcodes/embed-pdf.html | 356 +++++++++++++----------------- 1 file changed, 159 insertions(+), 197 deletions(-) diff --git a/layouts/shortcodes/embed-pdf.html b/layouts/shortcodes/embed-pdf.html index e977f03..966b8bf 100644 --- a/layouts/shortcodes/embed-pdf.html +++ b/layouts/shortcodes/embed-pdf.html @@ -1,204 +1,166 @@ - - - -
- - -     - Page: / -
-
-
-
+
+
+
- + +
+ +
+ +     + + / + + [pdf]
+ + From 195431ffd7a45341595537a63039076c85ba6a50 Mon Sep 17 00:00:00 2001 From: Charlton Trezevant Date: Sun, 5 Jun 2022 11:49:01 -0400 Subject: [PATCH 3/3] Update README with instructions on how to install the dependencies partial --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cec7ca..39f060e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,23 @@ cp ./layouts/shortcodes/embed-pdf.html /path/to/your/hugo/website/layouts/shortc ```
-3. Copy the pdf.js library files from `./static/js/pdf-js` to `./static/js` in your Hugo website directory. +3. Copy the file `./layouts/partials/embed-pdf-dependencies.html` to `./layouts/partials` in your Hugo website directory. +
+ +```shell +cp ./layouts/partials/embed-pdf-dependencies.html /path/to/your/hugo/website/layouts/partials +``` +
+ +4. Add the `embed-pdf-dependencies.html` partial to your theme. + +You'll want to add the following line to a layout in your `partials` directory responsible for generating the `` section of your blog. This will include the JavaScript dependencies and CSS styles for the `hugo-embed-pdf` shortcode exactly once on pages that use it. + +``` +{{ partial "embed-pdf-dependencies.html" . }} +``` + +5. Copy the pdf.js library files from `./static/js/pdf-js` to `./static/js` in your Hugo website directory.
**Note:** If you do not have a `./static/js` directory you can create it.