Skip to content
Open
Show file tree
Hide file tree
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
47 changes: 42 additions & 5 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,27 +282,61 @@ usage() {

case "$1" in
bake)
rm -rf "$DRAFT_DIR"
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)

echo "Rendering Posts..." >&2
idx=0
id_all=0
time for post in "${posts[@]}"; do
idx_prev=1;idx_next=1
id="$(basename "$post" .md)"
# skip drafts
[[ "$(header draft < "$post")" == false ]] || continue
if [ "$(header draft < "$post")" != false ]; then
(( id_all++ ))
POST_PREV='index.html';POST_NEXT='index.html'; render_file "$post" > "$DRAFT_DIR/$id.html"; continue;
fi
if [ ${idx} -eq 0 ]; then # It's the first post, so the newer one is index
id_prev=0
else # search for the previous post not draft
while [ -f "${posts[$((id_all-idx_prev))]}" -a "$(header draft < "${posts[$((id_all-idx_prev))]}" 2>/dev/null)" != false ]; do
(( idx_prev++ ))
if [ ${idx_prev} -gt ${id_all} ]; then idx_prev=${id_all}; break; fi
done 2>/dev/null
fi
# look for the next older post not draft
while [ -f "${posts[$((id_all+idx_next))]}" -a "$(header draft < "${posts[$((id_all+idx_next))]}" 2>/dev/null)" != false ]; do
(( idx_next++ ))
done 2>/dev/null

if [ ${idx} -eq 0 -o $((idx_all-idx_prev)) -eq 0 -a ${id_all} -eq 0 ]; then
POST_PREV="index.html"
else
POST_PREV="$( basename "${posts[$((id_all-idx_prev))]}" )"
POST_PREV="${POST_PREV%*.md}.html"
fi
POST_NEXT="$( basename "${posts[$((id_all+idx_next))]}" )"
[[ -z "${POST_PREV:=}" ]] && POST_PREV='index.html'
[[ -z "${POST_NEXT:=}" ]] && POST_NEXT='index.md'
echo "$idx - $idx_next - $id [Prev:${POST_PREV}][Next:${POST_NEXT}]"
POST_NEXT="${POST_NEXT%*.md}.html"

echo "$id"
render_file "$post" > "$OUTPUT_DIR/$id.html" &
declare "posts_${idx}_id"="$id"
export_headers "$post" "posts_${idx}_"
POST_PREV="$id.html"
(( id_all++ ))
(( idx++ ))
done

echo "Rendering Index..." >&2
render_file "$LAYOUT_DIR/index.md" > "$OUTPUT_DIR/index.html" &
wait
;;
Expand Down
2 changes: 2 additions & 0 deletions layout/post.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<nav>
<ul class="nav nav-pills pull-right">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="{{ POST_PREV }}" title="Newer"><i class="fa fa-long-arrow-left fa-2x"></i></a></li>
<li><a href="{{ POST_NEXT }}" title="Older"><i class="fa fa-long-arrow-right fa-2x"></i></a></li>
<li><a href="#author">About</a></li>
</ul>
</nav>
Expand Down
11 changes: 11 additions & 0 deletions post/2015-11-20-welcome-to-baker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Welcome to Baker!
date: 2015-11-20T11:06:07Z
layout: post
draft: false
summary: This is your second post.
---

With the **Markdown** syntax, expect more readbility. Be prepared to start blogging!

<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/121515363&color=ff5500"></iframe>