2016-06-21 07:40:25 +00:00
|
|
|
|
#!/usr/bin/env bash
|
2016-06-21 11:48:08 +00:00
|
|
|
|
# This file:
|
|
|
|
|
#
|
|
|
|
|
# - Injects markdown files into the ./website directory
|
|
|
|
|
# - Changes them a little to make them more suitable for Jekyll building
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
#
|
|
|
|
|
# ./inject.sh
|
|
|
|
|
#
|
|
|
|
|
# Based on a template by BASH3 Boilerplate v2.0.0
|
|
|
|
|
# http://bash3boilerplate.sh/#authors
|
2016-11-08 20:15:46 +00:00
|
|
|
|
#
|
|
|
|
|
# The MIT License (MIT)
|
|
|
|
|
# Copyright (c) 2013 Kevin van Zonneveld and contributors
|
|
|
|
|
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
|
|
|
|
|
# as you leave these references intact in the header comments of your source files.
|
2016-06-21 11:48:08 +00:00
|
|
|
|
|
|
|
|
|
# Exit on error. Append || true if you expect an error.
|
2016-06-21 07:40:25 +00:00
|
|
|
|
set -o errexit
|
2016-06-21 11:48:08 +00:00
|
|
|
|
# Exit on error inside any functions or subshells.
|
|
|
|
|
set -o errtrace
|
|
|
|
|
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
|
2016-06-21 07:40:25 +00:00
|
|
|
|
set -o nounset
|
2016-06-21 11:48:08 +00:00
|
|
|
|
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
|
|
|
|
set -o pipefail
|
|
|
|
|
# Turn on traces, useful while debugging but commented out by default
|
2016-06-21 07:40:25 +00:00
|
|
|
|
# set -o xtrace
|
|
|
|
|
|
2016-06-21 11:48:08 +00:00
|
|
|
|
# Set magic variables for current file, directory, os, etc.
|
2016-06-21 07:40:25 +00:00
|
|
|
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
2016-12-16 07:18:03 +00:00
|
|
|
|
__base="$(basename "${__file}" .sh)"
|
2016-06-21 11:48:08 +00:00
|
|
|
|
|
2016-06-24 09:47:28 +00:00
|
|
|
|
# Offer the main template for download as http://bash3boilerplate.sh/main.sh
|
|
|
|
|
cp -v main.sh website/
|
2016-06-21 07:40:25 +00:00
|
|
|
|
|
|
|
|
|
for doc in "README" "FAQ" "CHANGELOG"; do
|
|
|
|
|
targetName="$(echo "${doc}" | awk '{print tolower($0)}')"
|
|
|
|
|
permalink="/${targetName}/"
|
2016-12-16 07:18:03 +00:00
|
|
|
|
subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | "
|
2016-06-21 07:40:25 +00:00
|
|
|
|
redirectFrom="/${doc}.md/"
|
2016-06-21 09:20:59 +00:00
|
|
|
|
backLink="\n\n<a href=\"/\">« Home</a>"
|
2016-12-16 07:18:03 +00:00
|
|
|
|
if [[ "${doc}" = "README" ]]; then
|
2016-06-21 07:40:25 +00:00
|
|
|
|
targetName="index"
|
|
|
|
|
permalink="/"
|
|
|
|
|
subtitle=""
|
|
|
|
|
redirectFrom="nothing"
|
2016-06-21 09:20:59 +00:00
|
|
|
|
backLink=""
|
2016-06-21 07:40:25 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2016-12-16 07:18:03 +00:00
|
|
|
|
cat <<EOF > "website/${targetName}.md"
|
2016-06-21 07:40:25 +00:00
|
|
|
|
---
|
|
|
|
|
layout: default
|
|
|
|
|
permalink: ${permalink}
|
|
|
|
|
redirect_from: ${redirectFrom}
|
2016-06-22 08:14:33 +00:00
|
|
|
|
title: ${subtitle}BASH3 Boilerplate – Template for writing better Bash scripts
|
2016-06-21 07:40:25 +00:00
|
|
|
|
warning: This page is generated by ${__base}.sh based on ${doc}.md, please don't edit ${targetName}.md directly.
|
|
|
|
|
---
|
|
|
|
|
EOF
|
2016-11-30 13:57:40 +00:00
|
|
|
|
# If '<!--more-->' exists, only inject what comes after it, so you can have e.g. a ToC or buildbuttons
|
|
|
|
|
# on GitHub, without that also rendering in the site (site may have its own ToC rendering for instance)
|
2016-12-16 07:18:03 +00:00
|
|
|
|
if grep '<!--more-->' "${doc}.md"; then
|
|
|
|
|
sed -n -e '/<!--more-->/,$p' "${doc}.md" | tail -n +2 >> "website/${targetName}.md"
|
2016-06-21 09:20:59 +00:00
|
|
|
|
else
|
2016-12-16 07:18:03 +00:00
|
|
|
|
cat "${doc}.md" >> "website/${targetName}.md"
|
2016-06-21 09:20:59 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2016-11-30 13:57:40 +00:00
|
|
|
|
# Add a "<- Back Home" link, if any
|
2016-12-16 07:18:03 +00:00
|
|
|
|
echo -e $backLink >> "website/${targetName}.md"
|
2016-06-21 07:40:25 +00:00
|
|
|
|
|
2016-11-30 13:57:40 +00:00
|
|
|
|
echo "--> written website/${targetName}.md"
|
2016-06-21 07:40:25 +00:00
|
|
|
|
done
|