Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
at055612 opened this issue Feb 1, 2022 · 2 comments
Open

Comments

@at055612
Copy link
Contributor

at055612 commented Feb 1, 2022

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.

@at055612 at055612 changed the title Support deployment to environments with no internet access Feature Request: Support deployment to environments with no internet access Feb 1, 2022
@at055612 at055612 changed the title Feature Request: Support deployment to environments with no internet access Feature Request: Support offline environments (no internet access) Feb 1, 2022
@honzik20
Copy link

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

@at055612
Copy link
Contributor Author

This issue is related to #605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants