From a5a05a6a95ea981b15e81ff50492cbef5e2cb135 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 17 Feb 2022 14:36:33 +0800 Subject: [PATCH] :memo: Docs: add documentation for customJS option --- assets/js/_custom.js | 4 ++-- assets/js/_custom.min.js | 1 - exampleSite/config.toml | 3 --- .../content/posts/theme-documentation-basics/index.en.md | 9 ++++++++- .../posts/theme-documentation-basics/index.zh-cn.md | 7 +++++++ layouts/partials/assets.html | 9 +++------ 6 files changed, 20 insertions(+), 13 deletions(-) delete mode 100644 assets/js/_custom.min.js diff --git a/assets/js/_custom.js b/assets/js/_custom.js index 1d403e80..a77c8533 100644 --- a/assets/js/_custom.js +++ b/assets/js/_custom.js @@ -9,7 +9,7 @@ const CustomJS = new (function () { * @returns {CustomJS} */ this.hello = () => { - console.log('Hello CustomJS!'); + // console.log('Hello CustomJS!'); return this; } /** @@ -30,6 +30,6 @@ const CustomJS = new (function () { CustomJS.init(); // It will be executed when the DOM tree is built. document.addEventListener('DOMContentLoaded', () => { - console.log('DOM content loaded!') + // console.log('DOM content loaded!') }); })(); diff --git a/assets/js/_custom.min.js b/assets/js/_custom.min.js deleted file mode 100644 index ec36e1a3..00000000 --- a/assets/js/_custom.min.js +++ /dev/null @@ -1 +0,0 @@ -const CustomJS=new function(){this.hello=(()=>(console.log("Hello CustomJS!"),this)),this.init=(()=>(this.hello(),this))};CustomJS.init(),document.addEventListener("DOMContentLoaded",()=>{console.log("DOM content loaded!")}); \ No newline at end of file diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 8b90434c..85e977da 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -976,9 +976,6 @@ enableEmoji = true # "assets/js/_custom.js" [params.customJS] enable = true - # Use "_custom.min.js" in the same path - # 使用同目录下的压缩文件 "_custom.min.js" - minify = true # Markup related configuration in Hugo # Hugo 解析文档的配置 diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index 19a97714..c219b79f 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -696,8 +696,15 @@ Please open the code block below to view the complete sample configuration :(far polyfill = false # whether to use object-fit-images to be compatible with older browsers objectFit = false + + # {{< version 0.2.12 >}} Custom JS at last + # "_custom.js" located in "themes/FixIt/assets/js/" + # you can store your custom JS file in the same path under your project: + # "assets/js/_custom.js" + [params.customJS] + enable = true -# Markup related config in Hugo +# Markup related configuration in Hugo [markup] # {{< link "https://gohugo.io/content-management/syntax-highlighting" "Syntax Highlighting" >}} (https://gohugo.io/content-management/syntax-highlighting) [markup.highlight] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index c9300692..38e7fe9f 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -707,6 +707,13 @@ hugo polyfill = false # 是否使用 object-fit-images 来兼容旧式浏览器 objectFit = false + + # {{< version 0.2.12 >}} 页面最后添加自定义 JS + # "_custom.js" 位于 "themes/FixIt/assets/js" 目录 + # 可以在你的项目下相同路径存放你自己的自定义 JS 文件: + # "assets/js/_custom.js" + [params.customJS] + enable = true # Hugo 解析文档的配置 [markup] diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index cfeebde4..8ad73c68 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -116,7 +116,7 @@ {{- /* mermaid */ -}} {{- if (.Scratch.Get "this").mermaid -}} {{- $source := $cdn.mermaidJS | default "lib/mermaid/mermaid.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} + {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $options := dict "targetPath" "lib/mermaid/mermaid.min.css" "enableSourceMap" true -}} {{- dict "Source" "lib/mermaid/mermaid.scss" "ToCSS" $options "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} {{- end -}} @@ -135,7 +135,7 @@ {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} {{- $source := $cdn.mapboxGLJS | default "lib/mapbox-gl/mapbox-gl.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- dict "Source" "lib/mapbox-gl/mapbox-gl-language.js" "Minify" true "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} + {{- dict "Source" "lib/mapbox-gl/mapbox-gl-language.js" "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $config = dict "accessToken" $params.mapbox.accessToken "RTLTextPlugin" "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js" | dict "mapbox" | merge $config -}} {{- end -}} @@ -218,10 +218,7 @@ {{- /* Custom script */ -}} {{- if eq .Site.Params.customJS.enable true -}} {{- $source = "js/_custom.js" -}} - {{- if eq .Site.Params.customJS.minify true -}} - {{- $source = "js/_custom.min.js" -}} - {{- end -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} + {{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- end -}} {{- with (.Scratch.Get "this").scriptArr -}}