Skip to content

Commit

Permalink
improve build/deploy scripts/instructions (#113)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
0xdevalias authored Jul 3, 2024
1 parent b0ad9f1 commit e0ebd22
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 62 deletions.
30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

15 changes: 0 additions & 15 deletions PUBLISHING.md

This file was deleted.

53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,43 @@ This is the [Jekyll](https://jekyllrb.com/) source for http://www.devalias.net/

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

## Cheatsheet

* Link to other posts
* `[other post]({% post_url 2017-01-01-other-post %})`
* Embed an image with [jekyll-postfiles](https://github.com/nhoizey/jekyll-postfiles#how-does-it-work)
* create a folder under `_posts` named the same as your post's markdown file
* add any images for your post there, along with the post's markdown file
* use a relative markdown image tag to reference and embed the images
* eg. `![a title or something](foo.jpg)`
* Embed a gist with [jekyll-gist](https://github.com/jekyll/jekyll-gist)
* `{% gist foo/12345678901234567890 %} `
* Embed a tweet with [jekyll-twitter-plugin](https://github.com/rob-murray/jekyll-twitter-plugin)
* `{% twitter https://twitter.com/rubygems/status/518821243320287232 %}`
<!-- TOC start (generated with https://derlin.github.io/bitdowntoc/) -->
- [Quick Start](#quick-start)
- [Managing Posts and Drafts](#managing-posts-and-drafts)
- [Drafts](#drafts)
- [Tips and Tricks](#tips-and-tricks)
- [Additional Commands](#additional-commands)
<!-- TOC end -->

## Quick Start

To get started quickly, use the following commands:

- Serve the site locally: `./bin/serve` or `./bin/serve-drafts` (includes drafts)
- Build the site: `./bin/build`
- Deploy the site: `./bin/deploy`

## Managing Posts and Drafts

### Drafts

- Create a new draft: `jekyll draft "Name of Post"`
- Serve drafts locally: `./bin/serve-drafts` or `jekyll serve --incremental --drafts`
- Promote a draft to a published post: `./bin/publish ./_drafts/post-name.md` or `jekyll publish ./_drafts/post-name.md`
- 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).
- Unpublish a post: `jekyll unpublish ./_posts/post-name.md`
- This will move the specified post from the `_posts` directory back to the `_drafts` directory, making it a draft again.

### Tips and Tricks

- Link to other posts: `[other post]({% post_url 2017-01-01-other-post %})`
- Embed an image with [jekyll-postfiles](https://github.com/nhoizey/jekyll-postfiles#how-does-it-work)
- Create a folder under `_posts` named the same as your post's markdown file
- Add images to that folder and use a relative markdown image tag: `![a title or something](foo.jpg)`
- Embed a gist with [jekyll-gist](https://github.com/jekyll/jekyll-gist): `{% gist foo/12345678901234567890 %}`
- Embed a tweet with [jekyll-twitter-plugin](https://github.com/rob-murray/jekyll-twitter-plugin): `{% twitter https://twitter.com/rubygems/status/518821243320287232 %}`

## Additional Commands

- Check outdated dependencies: `./bin/outdated`
- This will list all outdated dependencies for your project.
2 changes: 0 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ keep_files:
- .nojekyll # To prevent GitHub re-processing

exclude:
- "PUBLISHING.md"
- "README.md"
- "TODO.txt"
- "ojekyll.txt"
- "bin/"

# TODO: Enable these checks + fix any errors associated with them
Expand Down
62 changes: 61 additions & 1 deletion bin/build
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
#!/bin/sh
#!/usr/bin/env zsh

set -e

# Variables
SITE_DIR="_site"
REPO_URL="https://github.com/0xdevalias/devalias.net"
BRANCH="gh-pages"

# Function to prompt the user for yes/no input with a default response
prompt_yes_no() {
local prompt=$1
local default=${2:-Y}

local yn
while true; do
if [[ $default == [Yy]* ]]; then
echo -n "$prompt [Y/n]: "
read yn
yn=${yn:-Y}
else
echo -n "$prompt [y/N]: "
read yn
yn=${yn:-N}
fi

case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}

# Function to check if the site directory is a valid git repository with the correct branch
check_site_setup() {
if [ -d "$SITE_DIR" ] && [ -d "$SITE_DIR/.git" ]; then
if (cd "$SITE_DIR" && git rev-parse --verify "$BRANCH" > /dev/null 2>&1); then
return 0
fi
fi
return 1
}

# Function to clone the branch into the site directory
setup_site_clone() {
rm -rf "$SITE_DIR"
git clone -b "$BRANCH" "$REPO_URL" "$SITE_DIR"
}

# Main script logic
if ! check_site_setup; then
echo "WARNING: $SITE_DIR directory does not exist or is not a proper git repository."
if prompt_yes_no "Would you like to set up the $SITE_DIR directory as a clone of the $BRANCH branch?" Y; then
setup_site_clone
else
echo "Error: $SITE_DIR directory is not set up. Aborting build."
exit 1
fi
fi

# Build the Jekyll site
JEKYLL_ENV=production bundle exec jekyll build --lsi --profile $@
49 changes: 48 additions & 1 deletion bin/deploy
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
#!/bin/sh
#!/usr/bin/env zsh

set -e

# Variables
SITE_DIR="_site"
REPO_URL="https://github.com/0xdevalias/devalias.net"
BRANCH="gh-pages"

# Function to check if the site directory is a valid git repository with the correct branch
check_site_setup() {
if [ -d "$SITE_DIR" ] && [ -d "$SITE_DIR/.git" ]; then
if git -C "$SITE_DIR" rev-parse --verify "$BRANCH" > /dev/null 2>&1; then
return 0
fi
fi
return 1
}

# Function to check for changes in the site directory
check_for_changes() {
if git -C "$SITE_DIR" diff --quiet && git -C "$SITE_DIR" diff --cached --quiet; then
return 1
fi
return 0
}

# Main script logic
if ! check_site_setup; then
echo "ERROR: $SITE_DIR directory does not exist or is not a proper git repository."
echo
echo "Please set up the $SITE_DIR directory as a clone of the $BRANCH branch."
echo
echo "You can do this automatically by running:"
echo " bin/build"
echo
echo "Or manually with the following commands:"
echo " rm -rf $SITE_DIR"
echo " git clone -b $BRANCH $REPO_URL $SITE_DIR"
exit 1
fi

# Check for changes before deployment
if ! check_for_changes; then
echo "No changes to deploy."
exit 0
fi

# Deploy the Jekyll site
bundle exec jekyll deploy $@

0 comments on commit e0ebd22

Please sign in to comment.