Skip to content

Commit e0ebd22

Browse files
authored
improve build/deploy scripts/instructions (#113)
* make bin/build more robust * make bin/deploy more robust * exclude Makefile from build/deploy * consolidate build/deploy/etc instructions into README * update exclude config to remove old files
1 parent b0ad9f1 commit e0ebd22

File tree

6 files changed

+149
-62
lines changed

6 files changed

+149
-62
lines changed

Makefile

-30
This file was deleted.

PUBLISHING.md

-15
This file was deleted.

README.md

+40-13
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,43 @@ This is the [Jekyll](https://jekyllrb.com/) source for http://www.devalias.net/
66

77
Feel free to create an issue/pull request for any typo's/bugs you might find :) <3
88

9-
## Cheatsheet
10-
11-
* Link to other posts
12-
* `[other post]({% post_url 2017-01-01-other-post %})`
13-
* Embed an image with [jekyll-postfiles](https://github.com/nhoizey/jekyll-postfiles#how-does-it-work)
14-
* create a folder under `_posts` named the same as your post's markdown file
15-
* add any images for your post there, along with the post's markdown file
16-
* use a relative markdown image tag to reference and embed the images
17-
* eg. `![a title or something](foo.jpg)`
18-
* Embed a gist with [jekyll-gist](https://github.com/jekyll/jekyll-gist)
19-
* `{% gist foo/12345678901234567890 %} `
20-
* Embed a tweet with [jekyll-twitter-plugin](https://github.com/rob-murray/jekyll-twitter-plugin)
21-
* `{% twitter https://twitter.com/rubygems/status/518821243320287232 %}`
9+
<!-- TOC start (generated with https://derlin.github.io/bitdowntoc/) -->
10+
- [Quick Start](#quick-start)
11+
- [Managing Posts and Drafts](#managing-posts-and-drafts)
12+
- [Drafts](#drafts)
13+
- [Tips and Tricks](#tips-and-tricks)
14+
- [Additional Commands](#additional-commands)
15+
<!-- TOC end -->
16+
17+
## Quick Start
18+
19+
To get started quickly, use the following commands:
20+
21+
- Serve the site locally: `./bin/serve` or `./bin/serve-drafts` (includes drafts)
22+
- Build the site: `./bin/build`
23+
- Deploy the site: `./bin/deploy`
24+
25+
## Managing Posts and Drafts
26+
27+
### Drafts
28+
29+
- Create a new draft: `jekyll draft "Name of Post"`
30+
- Serve drafts locally: `./bin/serve-drafts` or `jekyll serve --incremental --drafts`
31+
- Promote a draft to a published post: `./bin/publish ./_drafts/post-name.md` or `jekyll publish ./_drafts/post-name.md`
32+
- This will move the specified draft post to the `_posts` directory, making it a published post (though it won't be built or deployed automatically).
33+
- Unpublish a post: `jekyll unpublish ./_posts/post-name.md`
34+
- This will move the specified post from the `_posts` directory back to the `_drafts` directory, making it a draft again.
35+
36+
### Tips and Tricks
37+
38+
- Link to other posts: `[other post]({% post_url 2017-01-01-other-post %})`
39+
- Embed an image with [jekyll-postfiles](https://github.com/nhoizey/jekyll-postfiles#how-does-it-work)
40+
- Create a folder under `_posts` named the same as your post's markdown file
41+
- Add images to that folder and use a relative markdown image tag: `![a title or something](foo.jpg)`
42+
- Embed a gist with [jekyll-gist](https://github.com/jekyll/jekyll-gist): `{% gist foo/12345678901234567890 %}`
43+
- Embed a tweet with [jekyll-twitter-plugin](https://github.com/rob-murray/jekyll-twitter-plugin): `{% twitter https://twitter.com/rubygems/status/518821243320287232 %}`
44+
45+
## Additional Commands
46+
47+
- Check outdated dependencies: `./bin/outdated`
48+
- This will list all outdated dependencies for your project.

_config.yml

-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ keep_files:
9191
- .nojekyll # To prevent GitHub re-processing
9292

9393
exclude:
94-
- "PUBLISHING.md"
9594
- "README.md"
9695
- "TODO.txt"
97-
- "ojekyll.txt"
9896
- "bin/"
9997

10098
# TODO: Enable these checks + fix any errors associated with them

bin/build

+61-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1-
#!/bin/sh
1+
#!/usr/bin/env zsh
22

3+
set -e
4+
5+
# Variables
6+
SITE_DIR="_site"
7+
REPO_URL="https://github.com/0xdevalias/devalias.net"
8+
BRANCH="gh-pages"
9+
10+
# Function to prompt the user for yes/no input with a default response
11+
prompt_yes_no() {
12+
local prompt=$1
13+
local default=${2:-Y}
14+
15+
local yn
16+
while true; do
17+
if [[ $default == [Yy]* ]]; then
18+
echo -n "$prompt [Y/n]: "
19+
read yn
20+
yn=${yn:-Y}
21+
else
22+
echo -n "$prompt [y/N]: "
23+
read yn
24+
yn=${yn:-N}
25+
fi
26+
27+
case $yn in
28+
[Yy]* ) return 0;;
29+
[Nn]* ) return 1;;
30+
* ) echo "Please answer yes or no.";;
31+
esac
32+
done
33+
}
34+
35+
# Function to check if the site directory is a valid git repository with the correct branch
36+
check_site_setup() {
37+
if [ -d "$SITE_DIR" ] && [ -d "$SITE_DIR/.git" ]; then
38+
if (cd "$SITE_DIR" && git rev-parse --verify "$BRANCH" > /dev/null 2>&1); then
39+
return 0
40+
fi
41+
fi
42+
return 1
43+
}
44+
45+
# Function to clone the branch into the site directory
46+
setup_site_clone() {
47+
rm -rf "$SITE_DIR"
48+
git clone -b "$BRANCH" "$REPO_URL" "$SITE_DIR"
49+
}
50+
51+
# Main script logic
52+
if ! check_site_setup; then
53+
echo "WARNING: $SITE_DIR directory does not exist or is not a proper git repository."
54+
if prompt_yes_no "Would you like to set up the $SITE_DIR directory as a clone of the $BRANCH branch?" Y; then
55+
setup_site_clone
56+
else
57+
echo "Error: $SITE_DIR directory is not set up. Aborting build."
58+
exit 1
59+
fi
60+
fi
61+
62+
# Build the Jekyll site
363
JEKYLL_ENV=production bundle exec jekyll build --lsi --profile $@

bin/deploy

+48-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1-
#!/bin/sh
1+
#!/usr/bin/env zsh
22

3+
set -e
4+
5+
# Variables
6+
SITE_DIR="_site"
7+
REPO_URL="https://github.com/0xdevalias/devalias.net"
8+
BRANCH="gh-pages"
9+
10+
# Function to check if the site directory is a valid git repository with the correct branch
11+
check_site_setup() {
12+
if [ -d "$SITE_DIR" ] && [ -d "$SITE_DIR/.git" ]; then
13+
if git -C "$SITE_DIR" rev-parse --verify "$BRANCH" > /dev/null 2>&1; then
14+
return 0
15+
fi
16+
fi
17+
return 1
18+
}
19+
20+
# Function to check for changes in the site directory
21+
check_for_changes() {
22+
if git -C "$SITE_DIR" diff --quiet && git -C "$SITE_DIR" diff --cached --quiet; then
23+
return 1
24+
fi
25+
return 0
26+
}
27+
28+
# Main script logic
29+
if ! check_site_setup; then
30+
echo "ERROR: $SITE_DIR directory does not exist or is not a proper git repository."
31+
echo
32+
echo "Please set up the $SITE_DIR directory as a clone of the $BRANCH branch."
33+
echo
34+
echo "You can do this automatically by running:"
35+
echo " bin/build"
36+
echo
37+
echo "Or manually with the following commands:"
38+
echo " rm -rf $SITE_DIR"
39+
echo " git clone -b $BRANCH $REPO_URL $SITE_DIR"
40+
exit 1
41+
fi
42+
43+
# Check for changes before deployment
44+
if ! check_for_changes; then
45+
echo "No changes to deploy."
46+
exit 0
47+
fi
48+
49+
# Deploy the Jekyll site
350
bundle exec jekyll deploy $@

0 commit comments

Comments
 (0)