Browse Source

fix(layouts): output urls relative to baseurl

fixes script-loading error when site not hosted at web root

fixes #4
Josh Habdas 1 year ago
parent
commit
0205bd16e3
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74
3 changed files with 23 additions and 21 deletions
  1. 4
    4
      layouts/_default/search.html
  2. 5
    5
      layouts/partials/async-scripts.html
  3. 14
    12
      layouts/partials/toc-maybe.html

+ 4
- 4
layouts/_default/search.html View File

@@ -36,10 +36,10 @@
36 36
 {{ end }}
37 37
 {{ define "footer" }}
38 38
   {{ partial "powered-by.html" . }}
39
-  <script src="/js/vue.min.js"></script>
40
-  <script src="/js/lodash.custom.min.js"></script>
41
-  <script src="/js/fuse.min.js"></script>
42
-  <script src="/js/mark.min.js"></script>
39
+  <script src={{ "/js/vue.min.js" | relURL }}></script>
40
+  <script src={{ "/js/lodash.custom.min.js" | relURL }}></script>
41
+  <script src={{ "/js/fuse.min.js" | relURL }}></script>
42
+  <script src={{ "/js/mark.min.js" | relURL }}></script>
43 43
   <script>
44 44
     (function (window, document, undefined) {
45 45
       "use strict"

+ 5
- 5
layouts/partials/async-scripts.html View File

@@ -1,6 +1,6 @@
1
-<script async src="/js/lazysizes.min.js"></script>
1
+<script async src={{ "/js/lazysizes.min.js" | relURL }}></script>
2 2
 {{ if ne .Site.Params.seo.disable_bpg true }}
3
-  <script async src="/js/bpgdec8a.js"></script>
4
-  <script async src="/js/bpgdec8.js"></script>
5
-  <script async src="/js/bpgdec.js"></script>
6
-{{ end }}
3
+  <script async src={{ "/js/bpgdec8a.js" | relURL }}></script>
4
+  <script async src={{ "/js/bpgdec8.js" | relURL }}></script>
5
+  <script async src={{ "/js/bpgdec.js" | relURL }}></script>
6
+{{ end }}

+ 14
- 12
layouts/partials/toc-maybe.html View File

@@ -4,17 +4,19 @@
4 4
     {{ .TableOfContents }}
5 5
   </details>
6 6
   <script>
7
-    const el = document.querySelector('details summary')
8
-    el.onclick = () => {
9
-      (function(l,o,a,d,e,r){e=o.createElement(a),r=o.getElementsByTagName(a)[0];e.async=1;e.src=d;r.parentNode.insertBefore(e,r)})(window,document,'script','/js/smoothscroll.js');
10
-      el.onclick = null
11
-    }
12
-    document.querySelectorAll('#TableOfContents a').forEach(link => {
13
-      link.addEventListener('click', () => {
14
-        document.querySelector(
15
-          link.href.slice(link.href.indexOf('#'))
16
-        ).scrollIntoView({ behavior: 'smooth' })
17
-      })
18
-    })
7
+    (function (window, document, undefined) {
8
+      const el = document.querySelector('details summary');
9
+      el.onclick = () => {
10
+        (function(l,o,a,d,e,r){e=o.createElement(a),r=o.getElementsByTagName(a)[0];e.async=1;e.src=d;r.parentNode.insertBefore(e,r)})(window,document,'script','{{ "/js/smoothscroll.js" | relURL | safeJS }}');
11
+        el.onclick = null;
12
+      };
13
+      document.querySelectorAll('#TableOfContents a').forEach(link => {
14
+        link.addEventListener('click', () => {
15
+          document.querySelector(
16
+            link.href.slice(link.href.indexOf('#'))
17
+          ).scrollIntoView({ behavior: 'smooth' });
18
+        });
19
+      });
20
+    })(window, document);
19 21
   </script>
20 22
 {{ end }}

Loading…
Cancel
Save