Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor: custom.js rendering and remove params.customJS #189

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions assets/js/_custom.js → assets/js/custom.js.example
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
});
})();
8 changes: 1 addition & 7 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand All @@ -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 -}}
Expand Down