Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions baker
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ readonly POST_DIR=post
# OUTPUT_DIR stores all compiled html
readonly OUTPUT_DIR=out

# DRAFT_DIR stores all compiled html
readonly DRAFT_DIR=draft

# LAYOUT_DIR stores all layout markdown files
readonly LAYOUT_DIR=layout

Expand Down Expand Up @@ -56,7 +59,7 @@ body() {

# slug creates a friendly URL like 'hello-world'
slug() {
tr -cs '[:alnum:]\n' - | tr '[:upper:]' '[:lower:]' | sed 's|^-*||;s|-*$||'
iconv -f utf8 -t ascii//TRANSLIT | tr -cs '[:alnum:]\n' - | tr '[:upper:]' '[:lower:]' | sed 's|^-*||;s|-*$||'
}

#
Expand Down Expand Up @@ -279,19 +282,25 @@ usage() {

case "$1" in
bake)
rm -rf "$DRAFT_DIR"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply merge all rm and mkdir together.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in commit 563a6ab

mkdir -p "$DRAFT_DIR"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

[[ -d "$POST_DIR" ]] || usage
[[ -d "$PUBLIC_DIR" ]] && cp -r "$PUBLIC_DIR"/. "$OUTPUT_DIR"
[[ -d "$PUBLIC_DIR" ]] && cp -r "$PUBLIC_DIR"/. "$DRAFT_DIR"
touch "$DRAFT_DIR/index.html"

readarray -t posts < <(find "$POST_DIR" -name '*.md' | sort -r)

idx=0
time for post in "${posts[@]}"; do
id="$(basename "$post" .md)"
# skip drafts
[[ "$(header draft < "$post")" == false ]] || continue
if [ "$(header draft < "$post")" != false ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. use [[ for if
  2. use if and else in this case.
if draft
  render draft
else
  render output
  add to index

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be slower ?
If i rewrote with the if...else...fi, the shell will have to jump until the enf of fi and then start a new turn in the for.
By using the continue, the shell directly jmp to for statement.

render_file "$post" > "$DRAFT_DIR/$id.html"; continue;
fi

echo "$id"
render_file "$post" > "$OUTPUT_DIR/$id.html" &
Expand Down