joshed-io / reveal-hugo

📽️ Create rich HTML-based presentations with Hugo and Reveal.js
https://reveal-hugo.dzello.com/
MIT License
683 stars 143 forks source link

reveal-hugo not working offline #168

Open FilouPlains opened 1 week ago

FilouPlains commented 1 week ago

reveal-hugo not working offline

Hi !

First, thanks for this extension, it helps to make presentation way easier! I was trying to make a presentation 100% offline. You never know if the Wi-Fi connection will be there during a presentation… But it is not working.

The error

ERROR 2024/10/17 16:11:48 render of "section" failed: "/home/rouaud/Documents/
reveal_hugo_tutorial/themes/reveal-hugo/layouts/_default/baseof.reveal.html:44
:8": execute of template failed: template: _default/list.reveal.html:44:8:
executing "_default/list.reveal.html" at <partial "layout/javascript" .>: error
calling partial: "/home/rouaud/Documents/reveal_hugo_tutorial/themes/reveal-
hugo/layouts/partials/layout/javascript.html:109:76": execute of template
failed: template: partials/layout/javascript.html:109:76: executing "partials/
layout/javascript.html" at <$mathjaxSrc.RelPermalink>: error calling
RelPermalink: error calling resources.GetRemote: Get "https://cdn.jsdelivr.net/
npm/mathjax@3/es5/tex-svg.js": dial tcp: lookup cdn.jsdelivr.net on 127.0.0.53:
53: server misbehaving

It cannot load MathJax (and same for Mermaid).

Investigation

I think it comes from there for Mermaid:

{{ $mermaidSrc := resources.GetRemote "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js" }}

and from here for MathJax:

{{ $mathjaxSrc := resources.GetRemote "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" }}

Solution?

I do not know if that me who has done something wrong. But, a workarround that I see should be to simply let the user give the path to Mermaid and MathJax JS. Like that, I would be abble to point to a JS in static/ directory! Like I am doing for Mol* or Plotly integration for instance.

joshed-io commented 1 week ago

@FilouPlains Thanks for opening the issue and glad you're getting use from the project 🙏🏻 It looks like when those features were added there wasn't a way to fallback to a local version or at least to not make the remote call and fail. I will check on it. For now you may have to comment those lines out locally or in a fork and load the files you need statically instead. I'll keep you posted.

FilouPlains commented 2 days ago

@joshed-io

Just to maintain you updated, I have made a fork of your project: https://github.com/FilouPlains/reveal-hugo/blob/master/layouts/partials/layout/javascript.html

Additions

In the file that I ping you, I added:

{{- $mermaid_location := $.Param "reveal_hugo.mermaid_cdn" | default "__fetch_cdn__" -}} 

{{ if eq $mermaid_location "__fetch_mermaid_cdn__"  }}
  {{ $mermaid_location := resources.GetRemote "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js" }}
  <script type="text/javascript" src="{{ $mermaid_location.RelPermalink }}"></script>
{{ else }}
  <script type="text/javascript" src="{{ $mermaid_location }}"></script>
{{ end  }}

And:

{{- $mathjax_location := $.Param "reveal_hugo.mathjax_cdn" | default "__fetch_cdn__" -}} 

{{ if eq $mathjax_location "__fetch_cdn__"  }}
  {{ $mathjax_location := resources.GetRemote "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" }}
  <script type="text/javascript" id="MathJax-script" async src="{{ $mathjax_location.RelPermalink }}"></script>
{{ else }}
  <script type="text/javascript" id="MathJax-script" async src="{{ $mathjax_location }}"></script>
{{ end  }}

What it does

You can add in the hugo.toml the next parameters:

[params.reveal_hugo]
mermaid_cdn = "path"
mathjax_cdn = "path

In order to point to the path you want to! Note that I did not test it fully offline. I am very new to hugo, so the syntax might not be that good, but I do hope you understand the idea behind what I tried to add.

Have a lovely day and I keep you in touch if the addition work or not fully offline!