docsy
docsy copied to clipboard
Feature Request: Support offline environments (no internet access)
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/[email protected]/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/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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/[email protected]/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.
Watching this - I've done something similar in my implementation.
This issue is related to #605