welpo / tabi

A modern Zola theme with search, multilingual support, optional JavaScript, a perfect Lighthouse score, and a focus on accessibility.

Home Page:https://welpo.github.io/tabi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Standardize JavaScript Tooling

donovanglover opened this issue · comments

Feature Request

Summary

I want to contribute some JavaScript for headings and table of contents, but currently there's no official formatter.

I also don't know the procedure used to create the minified files.

Motivation

Having a standard formatter and/or bundler would make it easier to contribute without worrying about stylistic choices like semicolon vs no semicolon. The CI can be in charge of formatting/linting and building the minified JavaScript files.

Detailed Description

Biome is a modern formatter and linter written in Rust. Bun is a modern JavaScript toolkit that supports minifying JS.

Additional Context

I assume this would be done in such a way that regular end-users don't have to worry about any JavaScript tooling on their end. That is, only contributors would need to know that it exists.

commented

I create the minified files with either terser or uglifyjs, whichever does best on a given file.

I check for this as part of my pre-commit hook for tabi, which doesn't allow me to commit a file with the name min.js if it can be compressed further:

tabi/.githooks/pre-commit

Lines 99 to 122 in fd1c50a

function is_minified() {
local file="$1"
# Original file size.
local original_size=$(wc -c < "$file")
# File size after compression with terser.
local terser_size=$(terser --compress --mangle -- "$file" | wc -c)
# File size after compression with uglifyjs.
local uglifyjs_size=$(uglifyjs --compress --mangle -- "$file" | wc -c)
# Check if the file is already as small as or smaller than both minified versions.
if (( original_size <= terser_size && original_size <= uglifyjs_size )); then
return 0
fi
# If the file isn't as small as it can be, suggest the better compressor in the error message
if (( terser_size < uglifyjs_size )); then
error_exit "Minified JS file $file isn't as small as it can be! Try using terser for better compression."
else
error_exit "Minified JS file $file isn't as small as it can be! Try using uglifyjs for better compression."
fi
}

Regarding stylistic choices, I'm not too worried about them, to be honest.

My general approach to JS is:

  • Can it be done with HTML/CSS? If so, do that.
  • If it can't, how important is the feature? If the answer is "not very", then I'll probably be against adding it.

The CI can be in charge of formatting/linting and building the minified JavaScript files.

How do you picture this happening? A commit/PR is made and a GitHub action triggers the minification of a file, overwriting the previous minification (if it existed)? I'd be open to this.

Yeah a GitHub Action would be nice. The .githooks are great though and it may be easier to just mention it in CONTRIBUTING.md

commented

I've updated the CONTRIBUTING file to mention the pre-commit hook as well as some pointers regarding coding style guidelines.

I am now exploring the GitHub Action route. If it's not too complex, I'll implement it.

commented

Since I don't plan on making too many JS additions in the future, I'll leave it as is for now.