From 99dac59d826080bb75a3356347dfbe48a8d02ef6 Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Tue, 20 Jun 2023 01:11:01 -0700 Subject: [PATCH] :memo: Added new scripts, aliases, etc. --- aliases | 1 + robots_examples.txt | 20 ++++++++++++++++++++ scripts/minify | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/uglify | 8 ++++++++ updates.txt | 6 ++++++ 5 files changed, 76 insertions(+) create mode 100644 robots_examples.txt create mode 100755 scripts/minify create mode 100755 scripts/uglify diff --git a/aliases b/aliases index 526adfc8..70ddd2e3 100644 --- a/aliases +++ b/aliases @@ -241,6 +241,7 @@ alias duuid="dbus-uuidgen" # generate unique ids from cli, example for no special characters: alias manoid="nanoid --alphabet 'abcdefghijklmnopqrstuvwxyz' --size 40" alias nanoid="npx nanoid" +alias uglifyhtml="html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true" # autoprefixes css files # requires installation: # npm install -g postcss postcss-cli autoprefixer diff --git a/robots_examples.txt b/robots_examples.txt new file mode 100644 index 00000000..96da8971 --- /dev/null +++ b/robots_examples.txt @@ -0,0 +1,20 @@ +# Allows all: +User-agent: * +Disallow: + +# Disallow all (you don't want ANY site traffic here...): +User-agent: * +Disallow: / + +# Disallow specific files and folders +User-agent: * +Disallow: /topsy/ +Disallow: /crets/ +Disallow: /hidden/file.html + +# Disallow Specific Bots +User-agent: Bingbot +Disallow: / + +User-agent: * +Disallow: diff --git a/scripts/minify b/scripts/minify new file mode 100755 index 00000000..4ab69173 --- /dev/null +++ b/scripts/minify @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Function to minify HTML files +minify_html() { + html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true "$1" -o "$1" +} + +# Function to minify CSS files +minify_css() { + uglifycss "$1" >"$1.tmp" && mv "$1.tmp" "$1" +} + +# Function to minify JS files +minify_js() { + uglifyjs --no-annotations "$1" -o "$1" -c -m +} + +# Backup dist directory +if [[ -d "dist_bak" ]]; then + sudo rm -r dist_bak +fi + +cp -r ./dist dist_bak + +# Store HTML file paths in an array +mapfile -t html_files < <(find ./dist -type f -name "*.html") +mapfile -t css_files < <(find ./dist -type f -name "*.css") +mapfile -t js_files < <(find ./dist -type f -name "*.js") + +# Loop over HTML files and minify them +for file in "${html_files[@]}"; do + minify_html "$file" +done +# Loop over CSS files and minify them +for file in "${css_files[@]}"; do + minify_html "$file" +done +# Loop over JS files and minify them +for file in "${js_files[@]}"; do + minify_html "$file" +done diff --git a/scripts/uglify b/scripts/uglify new file mode 100755 index 00000000..9b1457be --- /dev/null +++ b/scripts/uglify @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +if [[ -d "dist_bak" ]]; then + sudo rm -r dist + mv dist_bak dist +else + echo "no dist_bak directory" +fi diff --git a/updates.txt b/updates.txt index 9cc06439..9a445b5c 100644 --- a/updates.txt +++ b/updates.txt @@ -256,3 +256,9 @@ doas npm i -g typescript Install rome in nvim to get proper linting :Mason select rome + +06/19/2023 +Install nginx and html-minifier (and uglifycss and uglifyjs if not already) +doas pacman -S nginx nginx-runit +doas sv ln -s /etc/runit/sv/nginx /run/runit/service/ +doas npm install -g html-minifier uglifyjs uglifycss