hugo-embed-pdf-shortcode
hugo-embed-pdf-shortcode copied to clipboard
PDF.js library loading broken
Describe the bug
The script src
is incorrect, which means the page breaks as the library will not load.
To Reproduce Steps to reproduce the behavior:
- Include the library using the steps in README.
- Run the local webserver with
hugo serve -D
or deploy
Expected behavior The PDF should display normally.
Screenshots
The correct URL should be /js/pdf-js/...
, without the extra slash at the beginning. Manually removing the slash fixes the bug.
Reverting https://github.com/anvithks/hugo-embed-pdf-shortcode/commit/704485be7df2b42eda41c3e24db17d0788992191 fixes the bug as well, but it will break if your site depends on the prepended relative link.
Seems like the loading is broken even when deployed to GH Pages/Actions.
Reverting https://github.com/anvithks/hugo-embed-pdf-shortcode/commit/704485be7df2b42eda41c3e24db17d0788992191 fixes the problem, but it would break the library for everybody else using relative links.
@ericswpark Thanks for raising this issue. Let me take a look. If you have a fix for this would you be able to raise a PR? Let me know.
I've also encountered this error.
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
Followed by:
Uncaught TypeError: Cannot read property 'GlobalWorkerOptions' of undefined
at window.onload
Quick (local) fix:
<script type="text/javascript" src= '/js/pdf-js/build/pdf.js'></script>
<!--
Bug: see https://github.com/anvithks/hugo-embed-pdf-shortcode/issues/18
<script type="text/javascript" src= '{{"/" | relURL}}/js/pdf-js/build/pdf.js'></script>
-->
The above fix while working locally would not work when deployed to Amazon AWS (Amplify). Second workaround: switched to CDN:
shortcode: embed-pdf.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js" integrity="sha512-i+UmpoqoJqHkpXQ3mQfaIF8UZ2RAGoyqJvMzAKTadhBVhRk883EHluxdPsMf7c5/43D5tVpwIE8KLE1kQa0uCg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js" integrity="sha512-NuVK4+sDE809oDhbdAABRO1nTe80t56vXda8dg1UQ+RcQ8x7WakwTzKE7LOosoNCKi7EH7FXo7mritFNWpZiLQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Removed the local pdf-js install in static/js
. So long as the deployed site rewrites URLs that commence with "www." by stripping out www.
the above solution works without having to mess around with CORS.
Thank you for reporting these. I have not been able to spend time on this lately. I see there are a few PRs and fixes that need to be tested and merged. I hope to make another release soon.
I am planning on putting this together in some sort of an installation package.
Something like npm. With options to install either local or cdn based shortcode.
Same Issue here. Fresh install of hugo as well as the pdf addon._ Is this Repo maintained?
Same Issue here. Fresh install of hugo as well as the pdf addon._ Is this Repo maintained?
You may want to change the first line of embed-pdf.html
to something like
<script type="text/javascript" src='{{"/js/pdf-js/build/pdf.js" | relURL}}'></script>
I also had to play with the parameter baseURL
in the config.toml
file.
You should share a public Git repo to get better advices