some more info
parent
bbced67d87
commit
71bfe60b89
@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
|
||||
build_articles() {
|
||||
articles_build_path="$1"
|
||||
tags_build_path="$2"
|
||||
|
||||
for file in $ARTICLES
|
||||
do
|
||||
build_article "$file" "$articles_build_path" "$tags_build_path"
|
||||
cleanup_all_exports
|
||||
done
|
||||
}
|
||||
build_article() {
|
||||
file="$1"
|
||||
articles_build_path="$2"
|
||||
tags_build_path="$3"
|
||||
|
||||
file_no_extension="$(basename "$file" .md)"
|
||||
|
||||
article_build_path="$articles_build_path/$file_no_extension"
|
||||
mkdir -p "$article_build_path"
|
||||
|
||||
set_page_dates "$file"
|
||||
|
||||
# Save the information for tag building
|
||||
set_page_tags "$file"
|
||||
for tag in $TAGS
|
||||
do
|
||||
tag_path="$tags_build_path/$tag"
|
||||
mkdir -p "$tag_path"
|
||||
echo "$file_no_extension" >> "$tag_path/occurences"
|
||||
done
|
||||
|
||||
set_page_titles "$file"
|
||||
set_page_descs "$file"
|
||||
set_page_author "$file"
|
||||
set_page_body "$file"
|
||||
|
||||
# Clean the file…
|
||||
out_file="$(get_built_file_path "blog/article/$file_no_extension")"
|
||||
rm -f "$out_file"
|
||||
# …and start writing to it.
|
||||
{
|
||||
render_header "article"
|
||||
|
||||
read_template "article/header"
|
||||
read_template "article/body"
|
||||
read_template "tag/link/header" "article"
|
||||
for tag in $TAGS
|
||||
do
|
||||
setup_tag_link_in_list "$tag" "../"
|
||||
read_template "tag/link" "article"
|
||||
done
|
||||
read_template "tag/link/footer" "article"
|
||||
read_template "article/footer"
|
||||
|
||||
render_footer "article"
|
||||
} >> "$out_file"
|
||||
|
||||
# Save for other build steps.
|
||||
echo "$CREATE_TIMESTAMP" > "$article_build_path/creation"
|
||||
echo "$MODIFY_TIMESTAMP" > "$article_build_path/modification"
|
||||
echo "$TITLE_HTML" > "$article_build_path/title_html"
|
||||
echo "$TITLE_NO_MD" > "$article_build_path/title_no_md"
|
||||
echo "$DESC_HTML" > "$article_build_path/desc_html"
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
|
||||
build_feeds() {
|
||||
articles_build_path="$1"
|
||||
|
||||
non_crucial_message "Building rss feed…"
|
||||
build_rss "$articles_build_path"
|
||||
non_crucial_message "Building atom feed…"
|
||||
build_atom "$articles_build_path"
|
||||
}
|
||||
|
||||
build_rss() {
|
||||
articles_build_path="$1"
|
||||
out_file="$(path blog/rss.xml)"
|
||||
|
||||
rm -f "$out_file"
|
||||
{
|
||||
read_template "feeds/rss/header" "" "xml"
|
||||
for article in $ARTICLES_WITHOUT_MD
|
||||
do
|
||||
setup_article_in_list "$article" "$articles_build_path"
|
||||
create_date="$(date -d "@$ARTICLE_CREATE_TIMESTAMP" "+%a, %d %b %Y %T %Z")"
|
||||
export ARTICLE_CREATE_DATE="$create_date"
|
||||
read_template "feeds/rss/entry" "" "xml"
|
||||
cleanup_all_exports
|
||||
done
|
||||
read_template "feeds/rss/footer" "" "xml"
|
||||
} >> "$out_file"
|
||||
}
|
||||
|
||||
build_atom() {
|
||||
articles_build_path="$1"
|
||||
out_file="$(path blog/atom.xml)"
|
||||
|
||||
rm -f "$out_file"
|
||||
{
|
||||
read_template "feeds/atom/header" "" "xml"
|
||||
for article in $ARTICLES_WITHOUT_MD
|
||||
do
|
||||
setup_article_in_list "$article" "$articles_build_path"
|
||||
create_date="$(date -d "@$ARTICLE_CREATE_TIMESTAMP" "+%Y-%m-%dT%H:%M:%SZ")"
|
||||
modify_date="$(date -d "@$ARTICLE_MODIFY_TIMESTAMP" "+%Y-%m-%dT%H:%M:%SZ")"
|
||||
export ARTICLE_CREATE_DATE="$create_date"
|
||||
export ARTICLE_MODIFY_DATE="$modify_date"
|
||||
read_template "feeds/atom/entry" "" "xml"
|
||||
cleanup_all_exports
|
||||
done
|
||||
read_template "feeds/atom/footer" "" "xml"
|
||||
} >> "$out_file"
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Get the filename to write into
|
||||
get_built_file_path() {
|
||||
out_file="$1"
|
||||
test "$USE_HTML_IN_LINKS" = "true" && out_file="$out_file.html"
|
||||
echo "$out_file"
|
||||
}
|
||||
|
||||
get_override_path() {
|
||||
template="$1"
|
||||
context="$2"
|
||||
echo "templates/$context/$template.html"
|
||||
}
|
||||
|
||||
# Find an appropriate file to read. Accepts extra context infromation to allow overriding of global
|
||||
# templates with page/article specific ones.
|
||||
get_template_path() {
|
||||
context="$2"
|
||||
override_path="$(get_override_path "$1" "$context")"
|
||||
# If additional context is passed, check if an override file exists for that context.
|
||||
if test ! -z "$context" && test -f "$override_path"
|
||||
then
|
||||
# It exists, so let's read it instead of the standard file.
|
||||
file="$override_path"
|
||||
else
|
||||
# It doesn't, so let's just use the global file.
|
||||
file="$(get_override_path "$1" "")"
|
||||
test ! -f "$file" && missing_global_template "$file" && return
|
||||
fi
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
# Find an appropriate file to read and substitute the contents with env variables. Accepts extra
|
||||
# context infromation to allow overriding of global templates with page/article specific ones.
|
||||
read_template() {
|
||||
context="$2"
|
||||
extension="$3"
|
||||
test -z "$3" && extension="html"
|
||||
|
||||
global_template="$1.$extension"
|
||||
|
||||
file="templates"
|
||||
# If additional context is passed, check if an override file exists for that context.
|
||||
if test ! -z "$context" && test -f "$file/$context/$global_template"
|
||||
then
|
||||
# It exists, so let's read it instead of the standard file.
|
||||
file="$file/$context/$global_template"
|
||||
else
|
||||
# It doesn't, so let's just use the global file.
|
||||
file="$file/$global_template"
|
||||
test ! -f "$file" && missing_global_template "$file" && return
|
||||
fi
|
||||
|
||||
envsubst < "$file"
|
||||
}
|
||||
|
||||
build_article_index() {
|
||||
articles="$1"
|
||||
articles_build_path="$2"
|
||||
context="$3"
|
||||
url_prefix="$4"
|
||||
|
||||
read_template "article/index/header" "$context"
|
||||
first=true
|
||||
for article in $articles
|
||||
do
|
||||
# shellcheck disable=SC2015
|
||||
"$first" && read_template "article/separator" "$context" || true
|
||||
setup_article_in_list "$article" "$articles_build_path" "$url_prefix"
|
||||
read_template "article/entry" "$context"
|
||||
first=false
|
||||
done
|
||||
read_template "article/index/footer" "$context"
|
||||
}
|
||||
|
||||
build_tag_index() {
|
||||
tags="$1"
|
||||
tags_build_path="$2"
|
||||
context="$3"
|
||||
url_prefix="$4"
|
||||
|
||||
read_template "tag/index/header" "$context"
|
||||
first=true
|
||||
for tag in $tags
|
||||
do
|
||||
# shellcheck disable=SC2015
|
||||
"$first" && read_template "tag/separator" "$context" || true
|
||||
setup_tag_in_list "$tag" "$tags_build_path" "$url_prefix"
|
||||
read_template "tag/index/entry" "$context"
|
||||
first=false
|
||||
done
|
||||
read_template "tag/index/footer" "$context"
|
||||
}
|
||||
|
||||
build_tag_list() {
|
||||
tags="$1"
|
||||
tags_build_path="$2"
|
||||
context="$3"
|
||||
|
||||
read_template "tag/index/header" "$context"
|
||||
first=true
|
||||
echo "$tags" | while IFS= read -r tag
|
||||
do
|
||||
# shellcheck disable=SC2015
|
||||
"$first" && read_template "tag/separator" "$context" || true
|
||||
setup_tag_link_in_list "$tag" "$tags_build_path"
|
||||
read_template "tag/link" "$context"
|
||||
first=false
|
||||
done
|
||||
read_template "tag/index/footer" "$context"
|
||||
}
|
||||
|
||||
render_header() {
|
||||
context="$1"
|
||||
read_template "html/header/start" "$context"
|
||||
read_template "$context/html-header"
|
||||
read_template "html/header/end" "$context"
|
||||
}
|
||||
|
||||
render_footer() {
|
||||
context="$1"
|
||||
read_template "html/footer/start" "$context"
|
||||
read_template "$context/html-footer"
|
||||
read_template "html/footer/end" "$context"
|
||||
}
|
||||
|
||||
cleanup_all_exports() {
|
||||
unset TITLE_HTML
|
||||
unset TITLE_SEO
|
||||
unset TITLE_TAB
|
||||
|
||||
unset DESC_HTML
|
||||
unset DESC_SEO
|
||||
|
||||
unset DATE_POSTED
|
||||
unset DATE_EDITED
|
||||
|
||||
unset AUTHOR
|
||||
|
||||
unset TAGS
|
||||
|
||||
unset BODY
|
||||
|
||||
unset ARTICLE_URL
|
||||
unset ARTICLE_DATE
|
||||
unset ARTICLE_TITLE
|
||||
unset ARTICLE_DESC
|
||||
|
||||
unset TAG_LINK
|
||||
unset TAG_NAME
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
build_pages() {
|
||||
articles_build_path="$1"
|
||||
tags_build_path="$2"
|
||||
|
||||
ARTICLE_LIST="$(build_article_index "$ARTICLES_WITHOUT_MD" "$articles_build_path" "page")"
|
||||
export ARTICLE_LIST
|
||||
|
||||
TAG_LIST="$(build_tag_index "$TAGFILES" "$tags_build_path" "page")"
|
||||
export TAG_LIST
|
||||
|
||||
for file in $PAGES
|
||||
do
|
||||
build_page "$file" "$articles_build_path" "$tags_build_path"
|
||||
cleanup_all_exports
|
||||
done
|
||||
}
|
||||
|
||||
# Just like read_template, but can prioritize page-specific templates (eg. special html header for
|
||||
# an index page) over templates specific for pages (eg. special html header for all pages).
|
||||
read_page_template() {
|
||||
context="$2"
|
||||
|
||||
# There is an additional check here but let's just roll with that.
|
||||
if test ! -z "$context" && test -f "$(get_override_path "$1" "page/$context")"
|
||||
then
|
||||
read_template "$1" "page/$2"
|
||||
else
|
||||
read_template "$1" "page"
|
||||
fi
|
||||
}
|
||||
|
||||
build_page() {
|
||||
file="$1"
|
||||
articles_build_path="$2"
|
||||
tags_build_path="$3"
|
||||
|
||||
file_no_extension="$(basename "$file" .md)"
|
||||
|
||||
set_page_dates "$file"
|
||||
set_page_titles "$file"
|
||||
set_page_descs "$file"
|
||||
set_page_author "$file"
|
||||
set_page_body "$file"
|
||||
|
||||
# Clean the file…
|
||||
out_file="$(get_built_file_path "blog/$file_no_extension")"
|
||||
rm -f "$out_file"
|
||||
# …and start writing to it.
|
||||
{
|
||||
read_page_template "html/header/start" "$file_no_extension"
|
||||
read_page_template "html-header" "$file_no_extension"
|
||||
read_page_template "html/header/end" "$file_no_extension"
|
||||
|
||||
read_page_template "header" "$file_no_extension"
|
||||
read_page_template "body" "$file_no_extension"
|
||||
read_page_template "footer" "$file_no_extension"
|
||||
|
||||
read_page_template "html/footer/start" "$file_no_extension"
|
||||
read_page_template "html-footer" "$file_no_extension"
|
||||
read_page_template "html/footer/end" "$file_no_extension"
|
||||
} >> "$out_file"
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
|
||||
build_tags() {
|
||||
tags_build_path="$1"
|
||||
articles_build_path="$2"
|
||||
|
||||
TAGFILES=""
|
||||
for tag_build_path in "$tags_build_path"/*
|
||||
do
|
||||
# If there is no occurences file in tag's directory, it means that articles aren't using it.
|
||||
test ! -f "$tag_build_path/occurences" && rm -rf "$tag_build_path" && continue
|
||||
|
||||
tag_name="$(basename "$tag_build_path")"
|
||||
TAGFILES="$TAGFILES $tag_name"
|
||||
build_tag "$tag_name" "$tag_build_path" "$articles_build_path"
|
||||
cleanup_all_exports
|
||||
done
|
||||
export TAGFILES
|
||||
}
|
||||
|
||||
get_tag_file_path() {
|
||||
name="$1"
|
||||
path tags/"$name.md"
|
||||
}
|
||||
|
||||
set_tag_titles() {
|
||||
file="$(get_tag_file_path "$1")"
|
||||
if test -f "$file" && git ls-files --error-unmatch "$file" > /dev/null 2>&1
|
||||
then
|
||||
set_page_titles "$file"
|
||||
else
|
||||
export TITLE_HTML="Articles tagged #$name"
|
||||
export TITLE_SEO="Articles tagged #$name"
|
||||
TITLE_TAB="$(get_tab_title "$TITLE_SEO")"
|
||||
export TITLE_TAB
|
||||
fi
|
||||
}
|
||||
set_tag_descs() {
|
||||
file="$(get_tag_file_path "$1")"
|
||||
if test -f "$file" && git ls-files --error-unmatch "$file" > /dev/null 2>&1
|
||||
then
|
||||
set_page_descs "$file"
|
||||
else
|
||||
export DESC_SEO="Everything from this blogged tagged with #$name"
|
||||
fi
|
||||
}
|
||||
|
||||
build_tag() {
|
||||
name="$1"
|
||||
tag_build_path="$2"
|
||||
articles_build_path="$3"
|
||||
|
||||
file="$(path tags/"$name.md")"
|
||||
set_tag_titles "$name"
|
||||
set_tag_descs "$name"
|
||||
|
||||
# Clean the file…
|
||||
out_file="$(get_built_file_path "blog/tag/$name")"
|
||||
rm -f "$out_file"
|
||||
# …and start writing to it.
|
||||
{
|
||||
render_header "tag"
|
||||
|
||||
read_template "tag/directory/header"
|
||||
test ! -z "$DESC_HTML" && read_template "tag/directory/desc"
|
||||
build_article_index "$(cat "$tag_build_path/occurences")" "$articles_build_path" "tag" "../"
|
||||
read_template "tag/directory/footer"
|
||||
|
||||
render_footer "tag"
|
||||
} >> "$out_file"
|
||||
|
||||
# Save for other build steps .
|
||||
echo "$TITLE_HTML" > "$tag_build_path/title_html"
|
||||
echo "$DESC_HTML" > "$tag_build_path/desc_html"
|
||||
}
|
Loading…
Reference in New Issue