Skip to content

Commit 4b28366

Browse files
committed
Use Template More Faithfully
1 parent 00210a7 commit 4b28366

11 files changed

+294
-0
lines changed

.devcontainer/devcontainer.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "Jekyll",
3+
"image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye",
4+
"onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
5+
"postCreateCommand": "bash .devcontainer/post-create.sh",
6+
"customizations": {
7+
"vscode": {
8+
"settings": {
9+
"terminal.integrated.defaultProfile.linux": "zsh"
10+
},
11+
"extensions": [
12+
// Liquid tags auto-complete
13+
"killalau.vscode-liquid-snippets",
14+
// Liquid syntax highlighting and formatting
15+
"Shopify.theme-check-vscode",
16+
// Shell
17+
"timonwong.shellcheck",
18+
"mkhl.shfmt",
19+
// Common formatter
20+
"EditorConfig.EditorConfig",
21+
"esbenp.prettier-vscode",
22+
"stylelint.vscode-stylelint",
23+
"yzhang.markdown-all-in-one",
24+
// Git
25+
"mhutchie.git-graph"
26+
]
27+
}
28+
}
29+
}

.devcontainer/post-create.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -f package.json ]; then
4+
bash -i -c "nvm install --lts && nvm install-latest-npm"
5+
npm i
6+
npm run build
7+
fi
8+
9+
# Install dependencies for shfmt extension
10+
curl -sS https://webi.sh/shfmt | sh &>/dev/null
11+
12+
# Add OMZ plugins
13+
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
14+
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
15+
sed -i -E "s/^(plugins=\()(git)(\))/\1\2 zsh-syntax-highlighting zsh-autosuggestions\3/" ~/.zshrc
16+
17+
# Avoid git log use less
18+
echo -e "\nunset LESS" >>~/.zshrc

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
trim_trailing_whitespace = true
8+
# Unix-style newlines with a newline ending every file
9+
end_of_line = lf
10+
insert_final_newline = true
11+
12+
[*.{js,css,scss}]
13+
quote_type = single
14+
15+
[*.{yml,yaml}]
16+
quote_type = double
17+
18+
[*.md]
19+
trim_trailing_whitespace = false

.gitattributes

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto
3+
4+
# Force bash scripts to always use LF line endings so that if a repo is accessed
5+
# in Unix via a file share from Windows, the scripts will work.
6+
*.sh text eol=lf
7+
8+
# Force batch scripts to always use CRLF line endings so that if a repo is accessed
9+
# in Windows via a file share from Linux, the scripts will work.
10+
*.{cmd,[cC][mM][dD]} text eol=crlf
11+
*.{bat,[bB][aA][tT]} text eol=crlf
12+
13+
# Denote all files that are truly binary and should not be modified.
14+
*.png binary
15+
*.jpg binary
16+
*.ico binary

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ _site
1515
node_modules
1616
package-lock.json
1717

18+
# IDE Configurations
19+
.idea
20+
.vscode/*
21+
!.vscode/settings.json
22+
!.vscode/extensions.json
23+
!.vscode/tasks.json
24+
1825
# Miscellaneous
1926
_sass/vendors
2027
assets/js/dist

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "assets/lib"]
2+
path = assets/lib
3+
url = https://github.com/cotes2020/chirpy-static-assets.git

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["ms-vscode-remote.remote-containers"]
3+
}

.vscode/settings.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// Prettier
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true,
5+
// Shopify Liquid
6+
"files.associations": {
7+
"*.html": "liquid"
8+
},
9+
"[markdown]": {
10+
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
11+
},
12+
// Formatter
13+
"[html][liquid]": {
14+
"editor.defaultFormatter": "Shopify.theme-check-vscode"
15+
},
16+
"[shellscript]": {
17+
"editor.defaultFormatter": "mkhl.shfmt"
18+
},
19+
// Disable vscode built-in stylelint
20+
"css.validate": false,
21+
"scss.validate": false,
22+
"less.validate": false,
23+
// Stylint extension settings
24+
"stylelint.snippet": ["css", "scss"],
25+
"stylelint.validate": ["css", "scss"],
26+
// Run tasks in macOS
27+
"terminal.integrated.profiles.osx": {
28+
"zsh": { "path": "/bin/zsh", "args": ["-l", "-i"] }
29+
}
30+
}

.vscode/tasks.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Run Jekyll Server",
6+
"type": "shell",
7+
"command": "./tools/run.sh",
8+
"group": {
9+
"kind": "build",
10+
"isDefault": true
11+
},
12+
"problemMatcher": [],
13+
"detail": "Runs the Jekyll server with live reload."
14+
},
15+
{
16+
"label": "Build Jekyll Site",
17+
"type": "shell",
18+
"command": "./tools/test.sh",
19+
"group": {
20+
"kind": "build"
21+
},
22+
"problemMatcher": [],
23+
"detail": "Build the Jekyll site for production."
24+
}
25+
]
26+
}

tools/run.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run jekyll serve and then launch the site
4+
5+
prod=false
6+
command="bundle exec jekyll s -l"
7+
host="127.0.0.1"
8+
9+
help() {
10+
echo "Usage:"
11+
echo
12+
echo " bash /path/to/run [options]"
13+
echo
14+
echo "Options:"
15+
echo " -H, --host [HOST] Host to bind to."
16+
echo " -p, --production Run Jekyll in 'production' mode."
17+
echo " -h, --help Print this help information."
18+
}
19+
20+
while (($#)); do
21+
opt="$1"
22+
case $opt in
23+
-H | --host)
24+
host="$2"
25+
shift 2
26+
;;
27+
-p | --production)
28+
prod=true
29+
shift
30+
;;
31+
-h | --help)
32+
help
33+
exit 0
34+
;;
35+
*)
36+
echo -e "> Unknown option: '$opt'\n"
37+
help
38+
exit 1
39+
;;
40+
esac
41+
done
42+
43+
command="$command -H $host"
44+
45+
if $prod; then
46+
command="JEKYLL_ENV=production $command"
47+
fi
48+
49+
if [ -e /proc/1/cgroup ] && grep -q docker /proc/1/cgroup; then
50+
command="$command --force_polling"
51+
fi
52+
53+
echo -e "\n> $command\n"
54+
eval "$command"

tools/test.sh

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Build and test the site content
4+
#
5+
# Requirement: html-proofer, jekyll
6+
#
7+
# Usage: See help information
8+
9+
set -eu
10+
11+
SITE_DIR="_site"
12+
13+
_config="_config.yml"
14+
15+
_baseurl=""
16+
17+
help() {
18+
echo "Build and test the site content"
19+
echo
20+
echo "Usage:"
21+
echo
22+
echo " bash $0 [options]"
23+
echo
24+
echo "Options:"
25+
echo ' -c, --config "<config_a[,config_b[...]]>" Specify config file(s)'
26+
echo " -h, --help Print this information."
27+
}
28+
29+
read_baseurl() {
30+
if [[ $_config == *","* ]]; then
31+
# multiple config
32+
IFS=","
33+
read -ra config_array <<<"$_config"
34+
35+
# reverse loop the config files
36+
for ((i = ${#config_array[@]} - 1; i >= 0; i--)); do
37+
_tmp_baseurl="$(grep '^baseurl:' "${config_array[i]}" | sed "s/.*: *//;s/['\"]//g;s/#.*//")"
38+
39+
if [[ -n $_tmp_baseurl ]]; then
40+
_baseurl="$_tmp_baseurl"
41+
break
42+
fi
43+
done
44+
45+
else
46+
# single config
47+
_baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")"
48+
fi
49+
}
50+
51+
main() {
52+
# clean up
53+
if [[ -d $SITE_DIR ]]; then
54+
rm -rf "$SITE_DIR"
55+
fi
56+
57+
read_baseurl
58+
59+
# build
60+
JEKYLL_ENV=production bundle exec jekyll b \
61+
-d "$SITE_DIR$_baseurl" -c "$_config"
62+
63+
# test
64+
bundle exec htmlproofer "$SITE_DIR" \
65+
--disable-external \
66+
--ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/"
67+
}
68+
69+
while (($#)); do
70+
opt="$1"
71+
case $opt in
72+
-c | --config)
73+
_config="$2"
74+
shift
75+
shift
76+
;;
77+
-h | --help)
78+
help
79+
exit 0
80+
;;
81+
*)
82+
# unknown option
83+
help
84+
exit 1
85+
;;
86+
esac
87+
done
88+
89+
main

0 commit comments

Comments
 (0)