fix: remove inline script usage (#133)

This commit is contained in:
Robert Kaussow 2021-05-21 11:33:17 +02:00 committed by GitHub
parent ae421f0050
commit 649e3cf752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 31 deletions

View file

@ -213,10 +213,10 @@ gulp.task("iconfont", function () {
gulp.task("js", function () { gulp.task("js", function () {
return gulp return gulp
.src(["src/js/*.js"]) .src(["src/js/*.js"])
.pipe(sourcemaps.init()) .pipe(devBuild ? sourcemaps.init() : noop())
.pipe(uglify()) .pipe(uglify())
.pipe(rename({ extname: ".min.js" })) .pipe(rename({ extname: ".min.js" }))
.pipe(sourcemaps.write(".")) .pipe(devBuild ? sourcemaps.write(".") : noop())
.pipe(gulp.dest(JS_BUILD)); .pipe(gulp.dest(JS_BUILD));
}); });

View file

@ -8,9 +8,5 @@
{{ if default true .Site.Params.GeekdocAnchorCopy }} {{ if default true .Site.Params.GeekdocAnchorCopy }}
<script defer src="{{ index .Site.Data.assets "js/clipboard.min.js" | relURL }}"></script> <script defer src="{{ index .Site.Data.assets "js/clipboard.min.js" | relURL }}"></script>
<script> <script defer src="{{ index .Site.Data.assets "js/clipboard-loader.min.js" | relURL }}"></script>
document.addEventListener("DOMContentLoaded", function(event) {
var clipboard = new ClipboardJS('.clip');
});
</script>
{{ end }} {{ end }}

View file

@ -1,30 +1,7 @@
{{ if not (.Page.Scratch.Get "mermaid") }} {{ if not (.Page.Scratch.Get "mermaid") }}
<!-- Include mermaid only first time --> <!-- Include mermaid only first time -->
<script defer src="{{ index .Site.Data.assets "js/mermaid.min.js" | relURL }}"></script> <script defer src="{{ index .Site.Data.assets "js/mermaid.min.js" | relURL }}"></script>
<script> <script defer src="{{ index .Site.Data.assets "js/mermaid-loader.min.js" | relURL }}"></script>
document.addEventListener("DOMContentLoaded", function(event) {
let currentMode = localStorage.getItem(THEME);
let darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
let primaryColor = "#ececff";
let darkMode = false;
console.log(currentMode)
if (currentMode === DARK_MODE || (currentMode === AUTO_MODE && darkModeQuery.matches)) {
primaryColor = "#6C617E";
darkMode = true;
}
mermaid.initialize({
flowchart: { useMaxWidth: true },
theme: "base",
themeVariables: {
darkMode: darkMode,
primaryColor: primaryColor,
},
});
});
</script>
{{ .Page.Scratch.Set "mermaid" true }} {{ .Page.Scratch.Set "mermaid" true }}
{{ end }} {{ end }}

View file

@ -0,0 +1,3 @@
document.addEventListener("DOMContentLoaded", function (event) {
var clipboard = new ClipboardJS(".clip");
});

25
src/js/mermaid-loader.js Normal file
View file

@ -0,0 +1,25 @@
document.addEventListener("DOMContentLoaded", function (event) {
let currentMode = localStorage.getItem(THEME);
let darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
let primaryColor = "#ececff";
let darkMode = false;
console.log(currentMode);
if (
currentMode === DARK_MODE ||
(currentMode === AUTO_MODE && darkModeQuery.matches)
) {
primaryColor = "#6C617E";
darkMode = true;
}
mermaid.initialize({
flowchart: { useMaxWidth: true },
theme: "base",
themeVariables: {
darkMode: darkMode,
primaryColor: primaryColor,
},
});
});