google / docsy

A set of Hugo doc templates for launching open source content.
https://docsy.dev
Apache License 2.0
2.62k stars 904 forks source link

Feature Request: Support offline environments (no internet access) #873

Open at055612 opened 2 years ago

at055612 commented 2 years ago

The documentation site I am developing with docsy needs to support deployment into some environments that have no internet access. Currently docsy pulls in various js libs and fonts from cdns. It would be good if docsy could be changed to make the use of the cdn based libs optional instead getting them from /static/js/. The use of the cdns would be the default.

I have made the following changes that fix it for my needs. It would need to be extended to cover the other libs like mermaid that I am currently not using. If you are happy with this approach I don't mind submitting a PR. Is there a neater way of doing this or doing it without changing docsy?

diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index a40f447..2c5ffb8 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -27,15 +27,23 @@
 {{ template "_internal/schema.html" . -}}
 {{ template "_internal/twitter_cards.html" . -}}
 {{ partialCached "head-css.html" . "asdf" -}}
+{{ if .Site.Params.offline_site }}
+<script src='{{ "/js/jquery-3.6.0.min.js" | relURL }}'></script>
+{{ else }}
 <script
   src="https://code.jquery.com/jquery-3.6.0.min.js"
   integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK"
   crossorigin="anonymous"></script>
+{{ end }}
 {{ if .Site.Params.offlineSearch -}}
+  {{ if .Site.Params.offline_site }}
+<script src='{{ "/js/lunr.min.js" | relURL }}'></script>
+  {{ else }}
 <script
   src="https://unpkg.com/lunr@2.3.9/lunr.min.js"
   integrity="sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli"
   crossorigin="anonymous"></script>
+  {{ end }}
 {{ end -}}

 {{ if .Site.Params.prism_syntax_highlighting -}}
diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html
index 0e3177e..517e4ed 100644
--- a/layouts/partials/scripts.html
+++ b/layouts/partials/scripts.html
@@ -1,9 +1,14 @@
+{{ if .Site.Params.offline_site }}
+<script src='{{ "/js/popper.min.js" | relURL }}'></script>
+<script src='{{ "/js/bootstrap.min.js" | relURL }}'></script>
+{{ else }}
 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
     integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
     crossorigin="anonymous"></script>
 <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js"
     integrity="sha512-UR25UO94eTnCVwjbXozyeVd6ZqpaAE9naiEUBK/A+QDbfSTQFhPGj5lOR6d8tsgbBk84Ggb5A3EkjsOgPRPcKA=="
     crossorigin="anonymous"></script>
+{{ end }}

 {{ if .Site.Params.mermaid.enable }}
 <script src="https://cdn.jsdelivr.net/npm/mermaid@8.13.4/dist/mermaid.min.js" integrity="sha512-JERecFUBbsm75UpkVheAuDOE8NdHjQBrPACfEQYPwvPG+fjgCpHAz1Jw2ci9EXmd3DdfiWth3O3CQvcfEg8gsA==" crossorigin="anonymous"></script>

I then just set this in my config.toml

[params]
  offline_site = true

and have these in my /static/js/

bootstrap.min.js
jquery-3.6.0.min.js
lunr.min.js
popper.min.js

themes/docsy/assets/scss/rtl/_main.scss also contains cdn based fonts but as I am not using hebrew/arabic/persian I have not done anything about these.

honzik20 commented 2 years ago

Watching this - I've done something similar in my implementation.

at055612 commented 1 year ago

This issue is related to #605