From add1a53991c31f393e1f67e01d501d2102dd2a51 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 1 Jun 2024 04:15:38 +0800 Subject: [PATCH 1/7] feat(dev): support vscode devcontainer --- .devcontainer/devcontainer.json | 20 ++++++++++++++++++++ .devcontainer/post-create.sh | 10 ++++++++++ .github/dependabot.yml | 4 ++++ .gitignore | 2 +- .vscode/extensions.json | 5 ++++- .vscode/settings.json | 4 ++-- tools/run.sh | 6 ++++++ 7 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/post-create.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..4fa88467101 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,20 @@ +{ + "name": "Jekyll", + "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye", + "onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", + "postCreateCommand": "bash .devcontainer/post-create.sh", + "customizations": { + "vscode": { + "extensions": [ + "EditorConfig.EditorConfig", + "esbenp.prettier-vscode", + "foxundermoon.shell-format", + "killalau.vscode-liquid-snippets", + "mhutchie.git-graph", + "Shopify.theme-check-vscode", + "stylelint.vscode-stylelint", + "yzhang.markdown-all-in-one" + ] + } + } +} diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100644 index 00000000000..f53e186e50a --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +npm_buid() { + bash -i -c "nvm install --lts" + npm i && npm run build +} + +[[ -d _sass/dist && -d assets/js/dist ]] || npm_buid + +exec zsh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 393fa980313..82bf3f7774c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -23,3 +23,7 @@ updates: - "major" schedule: interval: "weekly" + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.gitignore b/.gitignore index d6bf5096400..e7803e6e697 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ package-lock.json # IDE configurations .idea -.vscode +.vscode/* !.vscode/settings.json !.vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 52bd6fbd046..f58eb468990 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,9 +5,12 @@ // Liquid syntax highlighting and formatting "Shopify.theme-check-vscode", // Common formatter + "EditorConfig.EditorConfig", "esbenp.prettier-vscode", "foxundermoon.shell-format", "stylelint.vscode-stylelint", - "yzhang.markdown-all-in-one" + "yzhang.markdown-all-in-one", + // DevContainer + "ms-vscode-remote.remote-containers" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index b0e2e099dc0..465f3615cb0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,6 +22,6 @@ "scss.validate": false, "less.validate": false, // Stylint extension settings - "stylelint.snippet": ["css", "less", "postcss", "scss"], - "stylelint.validate": ["css", "less", "postcss", "scss"] + "stylelint.snippet": ["css", "scss"], + "stylelint.validate": ["css", "scss"] } diff --git a/tools/run.sh b/tools/run.sh index 04f23f5e76b..3cb32901d04 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -46,5 +46,11 @@ if $prod; then command="JEKYLL_ENV=production $command" fi +if [ -e /proc/1/cgroup ]; then + if grep -q docker /proc/1/cgroup; then + command="$command --force_polling" + fi +fi + echo -e "\n> $command\n" eval "$command" From 77a6bf8cd2456df6072c3ab5cbe522335e97c28e Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 1 Jun 2024 17:48:31 +0800 Subject: [PATCH 2/7] chore: improve settings --- .devcontainer/devcontainer.json | 17 +++++++++++++---- .devcontainer/post-create.sh | 32 +++++++++++++++++++++++++++----- .vscode/extensions.json | 15 +-------------- .vscode/settings.json | 2 +- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4fa88467101..ca2eeace87b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,15 +3,24 @@ "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye", "onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", "postCreateCommand": "bash .devcontainer/post-create.sh", + "postAttachCommand": "exec zsh", "customizations": { "vscode": { + "settings": { + // Speed up extension installation + "extensions.verifySignature": false + }, "extensions": [ - "EditorConfig.EditorConfig", - "esbenp.prettier-vscode", - "foxundermoon.shell-format", + // Liquid tags auto-complete "killalau.vscode-liquid-snippets", - "mhutchie.git-graph", + // Liquid syntax highlighting and formatting "Shopify.theme-check-vscode", + // Shell + "timonwong.shellcheck", + "mkhl.shfmt", + // Common formatter + "EditorConfig.EditorConfig", + "esbenp.prettier-vscode", "stylelint.vscode-stylelint", "yzhang.markdown-all-in-one" ] diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index f53e186e50a..bfcc0ce897e 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,10 +1,32 @@ #!/usr/bin/env bash -npm_buid() { - bash -i -c "nvm install --lts" - npm i && npm run build +setup_node() { + bash -i -c "nvm install --lts && nvm install-latest-npm" + + [[ -f package-lock.json && -d node_modules ]] || npm i +} + +setup_assets() { + has_built_css=false + has_built_js=false + + CSS_DIST="_sass/dist" + JS_DIST="assets/js/dist" + + if [ -d "$CSS_DIST" ]; then + [ -z "$(ls -A $CSS_DIST)" ] || has_built_css=true + fi + + if [ -d "$JS_DIST" ]; then + [ -z "$(ls -A $JS_DIST)" ] || has_built_js=true + fi + + $has_built_css || npm run build:css + $has_built_js || npm run build:js } -[[ -d _sass/dist && -d assets/js/dist ]] || npm_buid +setup_node +setup_assets -exec zsh +# Install dependencies for shfmt extension +curl -sS https://webi.sh/shfmt | sh &>/dev/null diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f58eb468990..082bc94c026 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,16 +1,3 @@ { - "recommendations": [ - // Liquid tags auto-complete - "killalau.vscode-liquid-snippets", - // Liquid syntax highlighting and formatting - "Shopify.theme-check-vscode", - // Common formatter - "EditorConfig.EditorConfig", - "esbenp.prettier-vscode", - "foxundermoon.shell-format", - "stylelint.vscode-stylelint", - "yzhang.markdown-all-in-one", - // DevContainer - "ms-vscode-remote.remote-containers" - ] + "recommendations": ["ms-vscode-remote.remote-containers"] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 465f3615cb0..787a0c844ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,7 @@ "editor.defaultFormatter": "Shopify.theme-check-vscode" }, "[shellscript]": { - "editor.defaultFormatter": "foxundermoon.shell-format" + "editor.defaultFormatter": "mkhl.shfmt" }, // Disable vscode built-in stylelint "css.validate": false, From 42284789f5c0cefa74b02844e201961376e65bcc Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:36:29 +0800 Subject: [PATCH 3/7] chore: add git-graph extension --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ca2eeace87b..8f2995b2a70 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,7 +22,9 @@ "EditorConfig.EditorConfig", "esbenp.prettier-vscode", "stylelint.vscode-stylelint", - "yzhang.markdown-all-in-one" + "yzhang.markdown-all-in-one", + // Git + "mhutchie.git-graph" ] } } From efb3e4d2a926e2ba42f048eea132030e14362972 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 2 Jun 2024 01:27:17 +0800 Subject: [PATCH 4/7] chore: check npm config on script --- .devcontainer/post-create.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index bfcc0ce897e..8c732eef3c9 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -25,8 +25,10 @@ setup_assets() { $has_built_js || npm run build:js } -setup_node -setup_assets +if [ -f package.json ]; then + setup_node + setup_assets +fi # Install dependencies for shfmt extension curl -sS https://webi.sh/shfmt | sh &>/dev/null From b62ac23ad1f7a80868d41b308e485c58c205fb05 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 2 Jun 2024 01:55:02 +0800 Subject: [PATCH 5/7] chore: enable zsh for all sessions --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8f2995b2a70..a891b7ee557 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,10 +3,10 @@ "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye", "onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", "postCreateCommand": "bash .devcontainer/post-create.sh", - "postAttachCommand": "exec zsh", "customizations": { "vscode": { "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", // Speed up extension installation "extensions.verifySignature": false }, From a3990ce88051f7d63ab4de42fe747bf4a85befdb Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:39:43 +0800 Subject: [PATCH 6/7] docs: add dev-container badge to readme --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 747b8bc1dd3..6f3b158e717 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ A minimal, responsive, and feature-rich Jekyll theme for technical writing. - [![Gem Version](https://img.shields.io/gem/v/jekyll-theme-chirpy?color=brightgreen)][gem]  - [![CI](https://github.com/cotes2020/jekyll-theme-chirpy/actions/workflows/ci.yml/badge.svg?branch=master&event=push)][ci]  + [![Gem Version](https://img.shields.io/gem/v/jekyll-theme-chirpy?&logo=RubyGems&logoColor=gainsboro&label=gem&color=brightgreen)][gem]  + [![CI](https://img.shields.io/github/actions/workflow/status/cotes2020/jekyll-theme-chirpy/ci.yml?logo=github&logoColor=gainsboro)][ci]  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4e556876a3c54d5e8f2d2857c4f43894)][codacy]  - [![GitHub license](https://img.shields.io/github/license/cotes2020/jekyll-theme-chirpy.svg)][license]  - [![996.icu](https://img.shields.io/badge/link-996.icu-%23FF4D5B.svg)](https://996.icu) + [![GitHub license](https://img.shields.io/github/license/cotes2020/jekyll-theme-chirpy)][license]  + [![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&logo=visualstudiocode&logoColor=gainsboro&message=Open&color=deepskyblue)][open-container] [**Live Demo** →][demo] @@ -72,6 +72,7 @@ This project is published under [MIT License][license]. [ci]: https://github.com/cotes2020/jekyll-theme-chirpy/actions/workflows/ci.yml?query=event%3Apush+branch%3Amaster [codacy]: https://app.codacy.com/gh/cotes2020/jekyll-theme-chirpy/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade [license]: https://github.com/cotes2020/jekyll-theme-chirpy/blob/master/LICENSE +[open-container]: https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/cotes2020/jekyll-theme-chirpy [jekyllrb]: https://jekyllrb.com/ [clipartmax]: https://www.clipartmax.com/middle/m2i8b1m2K9Z5m2K9_ant-clipart-childrens-ant-cute/ [demo]: https://cotes2020.github.io/chirpy-demo/ From 21fbd7098636623ce909044549e9b40ba4f27633 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:21:22 +0800 Subject: [PATCH 7/7] chore: simplify scripts --- .devcontainer/post-create.sh | 30 +++--------------------------- tools/run.sh | 6 ++---- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 8c732eef3c9..14422cbf0a4 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,33 +1,9 @@ #!/usr/bin/env bash -setup_node() { - bash -i -c "nvm install --lts && nvm install-latest-npm" - - [[ -f package-lock.json && -d node_modules ]] || npm i -} - -setup_assets() { - has_built_css=false - has_built_js=false - - CSS_DIST="_sass/dist" - JS_DIST="assets/js/dist" - - if [ -d "$CSS_DIST" ]; then - [ -z "$(ls -A $CSS_DIST)" ] || has_built_css=true - fi - - if [ -d "$JS_DIST" ]; then - [ -z "$(ls -A $JS_DIST)" ] || has_built_js=true - fi - - $has_built_css || npm run build:css - $has_built_js || npm run build:js -} - if [ -f package.json ]; then - setup_node - setup_assets + bash -i -c "nvm install --lts && nvm install-latest-npm" + npm i + npm run build fi # Install dependencies for shfmt extension diff --git a/tools/run.sh b/tools/run.sh index 3cb32901d04..0efc452d363 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -46,10 +46,8 @@ if $prod; then command="JEKYLL_ENV=production $command" fi -if [ -e /proc/1/cgroup ]; then - if grep -q docker /proc/1/cgroup; then - command="$command --force_polling" - fi +if [ -e /proc/1/cgroup ] && grep -q docker /proc/1/cgroup; then + command="$command --force_polling" fi echo -e "\n> $command\n"