diff options
-rw-r--r-- | functions.sh | 58 | ||||
-rwxr-xr-x | rssg | 26 | ||||
-rwxr-xr-x | ssg | 10 |
3 files changed, 47 insertions, 47 deletions
diff --git a/functions.sh b/functions.sh index 0468b29..163c0a2 100644 --- a/functions.sh +++ b/functions.sh @@ -1,24 +1,24 @@ #!/bin/sh -media_dir="media" -src_dir="src" -tmp_dir="tmp" -out_dir="out" - -tmp_file="${tmp_dir}/tmp" -rss_dir="${src_dir}/b" -rss_out_file="${out_dir}/rss.xml" - -website_domain="rgoncalves.se" -website_title="${website_domain}" -website_link="https://${website_domain}" -website_email="contact@${website_domain}" -website_generator="${website_domain}'s ssg" -website_description="devops and hacker D:" -website_language="en" - -date_default_hour="17:00:00" -date_default_timezone="+0200" +SSG_MEDIA_DIR="${SSG_MEDIA_DIR:-media}" +SSG_SRC_DIR="${SSG_SRC_DIR:-src}" +SSG_TMP_DIR="${SSG_TMP_DIR:-tmp}" +SSG_OUT_DIR="${SSG_OUT_DIR:-out}" + +SSG_TMP_FILE="${SSG_TMP_DIR}/tmp" +SSG_RSS_DIR="${SSG_SRC_DIR}/b" +SSG_RSS_OUT_FILE="${SSG_OUT_DIR}/rss.xml" + +SSG_WEBSITE_DOMAIN="${SSG_WEBSITE_DOMAIN:-example.org}" +SSG_WEBSITE_TITLE="${SSG_WEBSITE_TITLE:-Example}" +SSG_WEBSITE_LINK="${SSG_WEBSITE_LINK:-https://${SSG_WEBSITE_DOMAIN}}" +SSG_WEBSITE_EMAIL="${SSG_WEBSITE_EMAIL:-contact@${SSG_WEBSITE_DOMAIN}}" +SSG_WEBSITE_GENERATOR="${SSG_WEBSITE_GENERATOR:-${SSG_WEBSITE_DOMAIN} ssg}}" +SSG_WEBSITE_DESCRIPTION="${SSG_WEBSITE_DESCRIPTION:-example}" +SSG_WEBSITE_LANGUAGE="${SSG_WEBSITE_LANGUAGE:-en}" + +SSG_DATE_DEFAULT_HOUR="${SSG_DATE_DEFAULT_HOUR:-17:00:00}" +SSG_DATE_DEFAULT_TIMEZONE="${SSG_DATE_DEFAULT_TIMEZONE:-+0200}" uname=$(uname) @@ -85,7 +85,7 @@ __get_value_date_publication() { local _date _date="$(__get_value_date ${1})" - _date="${_date} ${date_default_hour} ${date_default_timezone}" + _date="${_date} ${SSG_DATE_DEFAULT_HOUR} ${SSG_DATE_DEFAULT_TIMEZONE}" if [ "${uname}" = "Linux" ]; then date -d "${_date}" +"%a, %d %b %Y %H:%M:%S %z" @@ -107,7 +107,7 @@ __get_out_filename() { echo "${_filename}" | sed 's/.md$/.html/g' | - sed "s/${src_dir}/${out_dir}/g" + sed "s/${SSG_SRC_DIR}/${SSG_OUT_DIR}/g" } __get_final_filename() { @@ -129,7 +129,7 @@ __list_files_date() { local _tmp_file _files=$(__list_files "${1}") - _tmp_file="${tmp_file}.list_files_date" + _tmp_file="${SSG_TMP_FILE}.list_files_date" cp /dev/null "${_tmp_file}" @@ -188,7 +188,7 @@ __generate_index() { local _file local _index_dir - _index_dir="${src_dir}/$(__get_value "${1}" index)" + _index_dir="${SSG_SRC_DIR}/$(__get_value "${1}" index)" [ -f "${_index_dir}" ] && _index_dir=$(dirname "${_index_dir}") [ ! -d "${_index_dir}" ] && return @@ -229,18 +229,18 @@ __generate_metadata() { __handle_md() { # 1: filename # Handle markdown files. - __lowdown "${1}" > "${tmp_file}.body" + __lowdown "${1}" > "${SSG_TMP_FILE}.body" - __generate_metadata "${1}" > "${tmp_file}.metadata" + __generate_metadata "${1}" > "${SSG_TMP_FILE}.metadata" if [ ! "$(__get_value "${1}" index)" = "" ]; then - __generate_index "${1}" > "${tmp_file}.index" + __generate_index "${1}" > "${SSG_TMP_FILE}.index" else - [ -f "${tmp_file}.index" ] && rm "${tmp_file}.index" + [ -f "${SSG_TMP_FILE}.index" ] && rm "${SSG_TMP_FILE}.index" fi - __apply_template "$(__get_value "${1}" template)" > "${tmp_file}" - __install "${tmp_file}" "$(__get_out_filename "${1}")" + __apply_template "$(__get_value "${1}" template)" > "${SSG_TMP_FILE}" + __install "${SSG_TMP_FILE}" "$(__get_out_filename "${1}")" } __handle() { @@ -6,32 +6,32 @@ set -e current_date=$(date +"%a, %d %b %Y %H:%M:%S %z") -cat <<-EOF > "${rss_out_file}" +cat <<-EOF > "${SSG_RSS_OUT_FILE}" <rss version="2.0"> <channel> -<title>${website_title}</title> -<description>${website_description}</description> -<link>${website_link}</link> -<copyright>$(date +"%Y") ${website_title} - All rights reserved</copyright> -<managingEditor>${website_email}</managingEditor> -<webMaster>${website_email}</webMaster> +<title>${SSG_WEBSITE_TITLE}</title> +<description>${SSG_WEBSITE_DESCRIPTION}</description> +<link>${SSG_WEBSITE_LINK}</link> +<copyright>$(date +"%Y") ${SSG_WEBSITE_TITLE} - All rights reserved</copyright> +<managingEditor>${SSG_WEBSITE_EMAIL}</managingEditor> +<webMaster>${SSG_WEBSITE_EMAIL}</webMaster> <lastBuildDate>${current_date}</lastBuildDate> <pubDate>${current_date}</pubDate> -<generator>${website_generator}</generator> -<language>${website_language}</language> +<generator>${SSG_WEBSITE_GENERATOR}</generator> +<language>${SSG_WEBSITE_LANGUAGE}</language> <docs>https://validator.w3.org/feed/docs/rss2.html</docs> <ttl>1800</ttl> EOF -for file in $(__list_files_date "${rss_dir}"); do +for file in $(__list_files_date "${SSG_RSS_DIR}"); do __get_value "${file}" "draft" >/dev/null && continue title=$(__get_value_title "${file}") date=$(__get_value_date_publication "${file}") - link="${website_link}/$(__get_final_filename "${file}")" + link="${SSG_WEBSITE_LINK}/$(__get_final_filename "${file}")" guid="$(echo "${link}" | "${__sha256}" | cut -d ' ' -f 1)" description=$(__generate_rss_body "${file}") - cat <<-EOF >> "${rss_out_file}" + cat <<-EOF >> "${SSG_RSS_OUT_FILE}" <item> <title>${title}</title> <link>${link}</link> @@ -42,7 +42,7 @@ for file in $(__list_files_date "${rss_dir}"); do EOF done -cat <<-EOF >> "${rss_out_file}" +cat <<-EOF >> "${SSG_RSS_OUT_FILE}" </channel> </rss> EOF @@ -6,11 +6,11 @@ set -xe media_branch="media" -src_files="$(__list_files ${src_dir})" -dirs="${media_dir} \ - ${src_dir} \ - ${tmp_dir} \ - ${out_dir}" +src_files="$(__list_files ${SSG_SRC_DIR})" +dirs="${SSG_MEDIA_DIR} \ + ${SSG_SRC_DIR} \ + ${SSG_TMP_DIR} \ + ${SSG_OUT_DIR}" # Ensure directories exist. for dir in ${dirs}; do |