diff --git a/.gitignore b/.gitignore
index 63c9b894e77..d6bf5096400 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,5 +17,10 @@ package-lock.json
# IDE configurations
.idea
+.vscode
+!.vscode/settings.json
+!.vscode/extensions.json
# Misc
+_sass/dist
+assets/js/dist
diff --git a/_config.yml b/_config.yml
index e423a5dbad2..017ddd224e9 100644
--- a/_config.yml
+++ b/_config.yml
@@ -213,7 +213,7 @@ exclude:
- tools
- README.md
- LICENSE
- - rollup.config.js
+ - "*.config.js"
- package*.json
jekyll-archives:
diff --git a/_data/origin/basic.yml b/_data/origin/basic.yml
index 9f3415a7ef7..9027e6e4e82 100644
--- a/_data/origin/basic.yml
+++ b/_data/origin/basic.yml
@@ -4,9 +4,6 @@ webfonts: /assets/lib/fonts/main.css
# Libraries
-bootstrap:
- css: /assets/lib/bootstrap/bootstrap.min.css
-
toc:
css: /assets/lib/tocbot/tocbot.min.css
js: /assets/lib/tocbot/tocbot.min.js
diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml
index 220d131eeb1..abedb6c6ed4 100644
--- a/_data/origin/cors.yml
+++ b/_data/origin/cors.yml
@@ -19,9 +19,6 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Sour
# Libraries
-bootstrap:
- css: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css
-
toc:
css: https://cdn.jsdelivr.net/npm/tocbot@4.25.0/dist/tocbot.min.css
js: https://cdn.jsdelivr.net/npm/tocbot@4.25.0/dist/tocbot.min.js
diff --git a/_includes/head.html b/_includes/head.html
index 0e4725c78ac..fd260c0e22b 100644
--- a/_includes/head.html
+++ b/_includes/head.html
@@ -69,7 +69,9 @@
{% endunless %}
-
+ {% unless jekyll.environment == 'production' %}
+
+ {% endunless %}
diff --git a/_sass/main.bundle.scss b/_sass/main.bundle.scss
new file mode 100644
index 00000000000..52e893feb36
--- /dev/null
+++ b/_sass/main.bundle.scss
@@ -0,0 +1,2 @@
+@import 'dist/bootstrap';
+@import 'main';
diff --git a/assets/css/jekyll-theme-chirpy.scss b/assets/css/jekyll-theme-chirpy.scss
index 1280b9e650b..d20545ba80b 100644
--- a/assets/css/jekyll-theme-chirpy.scss
+++ b/assets/css/jekyll-theme-chirpy.scss
@@ -1,6 +1,10 @@
---
---
-@import 'main';
+@import 'main
+{%- if jekyll.environment == 'production' -%}
+ .bundle
+{%- endif -%}
+';
/* append your custom style below */
diff --git a/package.json b/package.json
index ef094a125b9..a52b377f9ee 100644
--- a/package.json
+++ b/package.json
@@ -13,11 +13,12 @@
},
"homepage": "https://github.com/cotes2020/jekyll-theme-chirpy/",
"scripts": {
- "build": "npm run build:js",
+ "build": "concurrently npm:build:*",
+ "build:css": "purgecss -c purgecss.config.js",
"build:js": "rollup -c --bundleConfigAsCjs --environment BUILD:production",
"watch:js": "rollup -c --bundleConfigAsCjs -w",
- "lint:style": "stylelint _sass/**/*.scss",
- "lint:fix:style": "npm run lint:style -- --fix",
+ "lint:scss": "stylelint _sass/**/*.scss",
+ "lint:fix:scss": "npm run lint:style -- --fix",
"test": "npm run lint:scss"
},
"dependencies": {
@@ -37,8 +38,10 @@
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
+ "concurrently": "^8.2.2",
"conventional-changelog-conventionalcommits": "^7.0.2",
"husky": "^9.0.11",
+ "purgecss": "^6.0.0",
"rollup": "^4.15.0",
"rollup-plugin-license": "^3.3.1",
"semantic-release": "^23.0.8",
diff --git a/purgecss.config.js b/purgecss.config.js
new file mode 100644
index 00000000000..de370dea30c
--- /dev/null
+++ b/purgecss.config.js
@@ -0,0 +1,23 @@
+const fs = require('fs');
+const DIST_PATH = '_sass/dist';
+
+fs.rm(DIST_PATH, { recursive: true, force: true }, (err) => {
+ if (err) {
+ throw err;
+ }
+
+ fs.mkdirSync(DIST_PATH);
+});
+
+module.exports = {
+ content: ['_includes/**/*.html', '_layouts/**/*.html', '_javascript/**/*.js'],
+ css: ['node_modules/bootstrap/dist/css/bootstrap.min.css'],
+ keyframes: true,
+ variables: true,
+ output: `${DIST_PATH}/bootstrap.css`,
+ // The `safelist` should be changed appropriately for future development
+ safelist: {
+ standard: [/^collaps/, /^w-/, 'shadow', 'border', 'kbd'],
+ greedy: [/^col-/, /tooltip/]
+ }
+};
diff --git a/tools/init b/tools/init
index be8ac0150f5..ed478d793f7 100755
--- a/tools/init
+++ b/tools/init
@@ -82,7 +82,7 @@ init_files() {
rm -rf "$temp"
## Cleanup image settings in site config
- _sedi "s/(^.*cdn:).*/\1/;s/(^avatar:).*/\1/" _config.yml
+ _sedi "s/(^timezone:).*/\1/;s/(^.*cdn:).*/\1/;s/(^avatar:).*/\1/" _config.yml
fi
# remove the other files
@@ -91,8 +91,8 @@ init_files() {
# build assets
npm i && npm run build
- # track the js output
- _sedi "/^assets.*\/dist/d" .gitignore
+ # track the CSS/JS output
+ _sedi "/.*\/dist$/d" .gitignore
}
commit() {
diff --git a/tools/release b/tools/release
index 90b18232ea6..351321a984b 100755
--- a/tools/release
+++ b/tools/release
@@ -15,6 +15,7 @@ NODE_SPEC="package.json"
CHANGELOG="docs/CHANGELOG.md"
CONFIG="_config.yml"
+CSS_DIST="_sass/dist"
JS_DIST="assets/js/dist"
FILES=(
@@ -79,17 +80,12 @@ _check_src() {
done
}
-_check_node_packages() {
- if [[ ! -d node_modules || "$(du node_modules | awk '{print $1}')" == "0" ]]; then
- npm i
- fi
-}
-
-check() {
+init() {
_check_cli
_check_git
_check_src
- _check_node_packages
+ echo -e "> npm install\n"
+ npm i
}
## Bump new version to gem-spec file
@@ -115,24 +111,31 @@ prepare() {
build_gem() {
if $opt_pkg; then
BACKUP_PATH="$(mktemp -d)"
- cp "$JS_DIST"/* "$BACKUP_PATH"
+ mkdir -p "$BACKUP_PATH"/css "$BACKUP_PATH"/js
+ [[ -d $CSS_DIST ]] && cp "$CSS_DIST"/* "$BACKUP_PATH"/css
+ [[ -d $JS_DIST ]] && cp "$JS_DIST"/* "$BACKUP_PATH"/js
fi
# Remove unnecessary theme settings
- sed -i "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" $CONFIG
+ sed -i -E "s/(^timezone:).*/\1/;s/(^cdn:).*/\1/;s/(^avatar:).*/\1/" $CONFIG
rm -f ./*.gem
npm run build
- git add "$JS_DIST" -f # add JS distribution files to gem
+ # add CSS/JS distribution files to gem package
+ git add "$CSS_DIST" "$JS_DIST" -f
+
+ echo -e "\n> gem build $GEM_SPEC\n"
gem build "$GEM_SPEC"
- # resume the settings
+ echo -e "\n> Resume file changes ...\n"
git reset
git checkout .
if $opt_pkg; then
# restore the dist files for future development
- mkdir -p "$JS_DIST" && cp "$BACKUP_PATH"/* "$JS_DIST"
+ mkdir -p "$CSS_DIST" "$JS_DIST"
+ cp "$BACKUP_PATH"/css/* "$CSS_DIST"
+ cp "$BACKUP_PATH"/js/* "$JS_DIST"
rm -rf "$BACKUP_PATH"
fi
}
@@ -157,7 +160,7 @@ merge() {
}
main() {
- check
+ init
if $opt_pre; then
prepare