diff --git a/CHANGELOG.md b/CHANGELOG.md index b520cfee..2cbedcf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. - :wheelchair: Feat(accessibility): use `aria-hidden=true` on icons that AT should ignore - :recycle: Refactor: image rendering - :recycle: Refactor: back to top and scroll to comments +- :recycle: Refactor: custom.js rendering and remove `params.customJS` ([#189](https://github.com/hugo-fixit/FixIt/pull/189)) - :bug: Fix: add function `dos2unix` to unify new lines symbol between Windows and Unix/Mac OS - :bug: Fix: author display error in post and markdown file - :bug: Fix: use data attributes or class replace for custom attributes diff --git a/assets/js/_custom.js b/assets/js/custom.js.example similarity index 63% rename from assets/js/_custom.js rename to assets/js/custom.js.example index a77c8533..2c4c28dc 100644 --- a/assets/js/_custom.js +++ b/assets/js/custom.js.example @@ -1,20 +1,20 @@ /** + * Custom javascript for FixIt site. * @author @Lruihao https://lruihao.cn - * @description Custom javascript for the hugo theme FixIt. */ -const CustomJS = new (function () { +const FixItCustom = new (function () { /** * Hello World * You can define your own functions below. - * @returns {CustomJS} + * @returns {FixItCustom} */ this.hello = () => { - // console.log('Hello CustomJS!'); + console.log('FixItCustom echo: Hello FixIt!'); return this; - } + }; /** * Initialize. - * @returns {CustomJS} + * @returns {FixItCustom} */ this.init = () => { // Custom infos. @@ -27,9 +27,9 @@ const CustomJS = new (function () { * Immediate. */ (() => { - CustomJS.init(); + FixItCustom.init(); // It will be executed when the DOM tree is built. document.addEventListener('DOMContentLoaded', () => { - // console.log('DOM content loaded!') + // FixItCustom.init(); }); })(); diff --git a/config.toml b/config.toml index 0ada434d..1df1c0e1 100644 --- a/config.toml +++ b/config.toml @@ -664,13 +664,7 @@ polyfill = false # whether to use object-fit-images to be compatible with older browsers objectFit = false - - # FixIt 0.2.12 | NEW 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 + # FixIt 0.2.14 | NEW GitHub banner in the top-right or top-left corner [params.githubCorner] enable = false diff --git a/docs b/docs index 99725861..c63bb5cc 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 997258619cb5f76207ff077f51b4cdf8cd86c743 +Subproject commit c63bb5cc070c8f7997d649440096c818a9460ce0 diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 44a91477..bc05527b 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -235,8 +235,8 @@ {{- $options := dict -}} {{- $options = dict "targetPath" "service-worker.min.js" | merge $options -}} {{- $options = dict "minify" true | merge $options -}} - {{- $js := resources.Get "js/service-worker.js" | js.Build $options -}} - {{- $_ := $js.RelPermalink -}} + {{- $source := resources.Get "js/service-worker.js" | js.Build $options -}} + {{- $_ := $source.RelPermalink -}} {{- $config = dict "enablePWA" .Site.Params.enablePWA | merge $config -}} {{- end -}} @@ -263,9 +263,8 @@ {{- $_ := (resources.Get "js/theme.min.js.map").RelPermalink -}} {{- /* Custom script */ -}} -{{- if eq .Site.Params.customJS.enable true -}} - {{- $source := "js/_custom.js" -}} - {{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} +{{- with ((resources.Get "js/custom.js") | default (resources.Get "js/_custom.js")) -}} + {{- dict "Source" .RelPermalink "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}} {{- end -}} {{- with (.Scratch.Get "this").scriptArr -}}