Feat: add CustomJS option (#24)

This commit is contained in:
Cell
2022-01-09 22:42:29 +08:00
parent ae98fa7bb7
commit 1a8d4907ef
5 changed files with 62 additions and 1 deletions
+1
View File
@@ -6,6 +6,7 @@
- :tada: Feat: add Watermark support ([#16](https://github.com/Lruihao/FixIt/issues/16))
- :tada: Feat: add "不蒜子" count and site run time ([#18](https://github.com/Lruihao/FixIt/issues/18))
- :sparkles: Feat: add public network security config (only in China) ([#15](https://github.com/Lruihao/FixIt/issues/15))
- :sparkles: Feat: add CustomJS option ([#24](https://github.com/Lruihao/FixIt/issues/24))
- :zap: Perf: optimize JS loading ([#25](https://github.com/Lruihao/FixIt/issues/25))
- :bug: Fix: add scroll-margin to headerlink
- :bug: Fix: Check if content is empty beforing passing
+36
View File
@@ -0,0 +1,36 @@
/**
* @author @Lruihao https://lruihao.cn
* @description Custom javascript for the hugo theme FixIt.
*/
const CustomJS = new (function () {
/**
* Hello World
* You can define your own functions below.
* @returns {CustomJS}
*/
this.hello = () => {
console.log('hello CustomJS!');
return this;
}
/**
* Initialize.
* @returns {CustomJS}
*/
this.init = () => {
// Custom infos.
this.hello();
return this;
};
})();
/**
* Immediate.
*/
(() => {
CustomJS.init();
// It will be executed when the DOM tree is built.
document.addEventListener('DOMContentLoaded', () => {
// Listen to any DOM change and automatically perform spacing via MutationObserver()
console.log('DOMContentLoaded!')
});
})();
+1
View File
@@ -0,0 +1 @@
const CustomJS=new function(){this.hello=(()=>(console.log("hello CustomJS!"),this)),this.init=(()=>(this.hello(),this))};CustomJS.init(),document.addEventListener("DOMContentLoaded",()=>{console.log("DOMContentLoaded!")});
+14
View File
@@ -1093,6 +1093,20 @@ enableEmoji = true
# 是否使用 object-fit-images 来兼容旧式浏览器
objectFit = false
# Custom JS at last. since v0.2.12
# "_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"
# 页面最后添加自定义 JS
# "_custom.js" 位于 "themes/FixIt/assets/js" 目录
# 可以在你的项目下相同路径存放你自己的自定义 JS 文件:
# "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 解析文档的配置
[markup]
+10 -1
View File
@@ -183,7 +183,7 @@
{{- end -}}
{{- range $params.library.js -}}
{{- dict "Source" . "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" . "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}
{{- with (.Scratch.Get "this").styleArr -}}
@@ -200,6 +200,15 @@
{{- dict "Source" "js/theme.min.js" "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $_ := (resources.Get "js/theme.min.js.map").RelPermalink -}}
{{- /* 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" -}}
{{- end -}}
{{- with (.Scratch.Get "this").scriptArr -}}
{{- delimit . "\n" | dict "Content" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}