commit dd0e58a4b697c1e845dae5799e75b2934d2fec9a
parent 845f2f7f12d8037d4e67c3307bd7b1efae646b96
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Tue, 7 Apr 2020 20:09:15 -0400
Improvements to publish script
Diffstat:
M | publish | | | 133 | +++++++++++++++++++------------------------------------------------------------ |
1 file changed, 31 insertions(+), 102 deletions(-)
diff --git a/publish b/publish
@@ -19,64 +19,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see \<https://www.gnu.org/licenses/\>.
-# $1 = flag which determines which action to take
-# $2 = file to act upon
-
mainFeed="public/feeds/sitewide-feed.xml"
descriptionFile="/tmp/publish-description.txt"
destination="paritybit.ca:uploads/"
+
date=$(date +"%a, %d %b %Y %T %z")
miniDate=$(date +"%F")
-filename=$(basename -s .md -- "$2")
-pageTitle=$(head -n 1 "$2" | cut -d' ' -f2-)
+filename=$(basename -s .md -- "$1")
+pageTitle=$(head -n 1 "$1" | cut -d' ' -f2-)
entry=""
-if [ "$1" = "-b" ]; then
- publishBlog=1
- baseURL="https://www.paritybit.ca/blog"
- basePage="blog"
- categoryPage="html/blog.html"
- newString="Blog:"
- article="html/blog/$filename.html"
- feed="feeds/blog-feed.xml"
-elif [ "$1" = "-p" ]; then
- publishProject=1
- baseURL="https://www.paritybit.ca/projects"
- basePage="projects"
- newString="Project:"
- categoryPage="html/projects.html"
- article="html/projects/$filename.html"
- feed="feeds/projects-feed.xml"
-elif [ "$1" = "-g" ]; then
- publishGuide=1
- baseURL="https://www.paritybit.ca/guides"
- basePage="guides"
- newString="Guide:"
- categoryPage="html/guides.html"
- article="html/guides/$filename.html"
- feed="feeds/guides-feed.xml"
-else
- cat << EOF
-Usage: publish <-b|-p|-g> <page_to_publish>
-Options:
- -b — Publish a blog post
- -p — Publish a project
- -g — Publish a guide
-Examples:
- publish -b pages/blog/sample-post.md
- publish -p pages/projects/sample-project.md
- publish -g pages/guides/sample-guide.md"
-EOF
- exit 1
-fi
+baseURL="https://www.paritybit.ca/blog"
+basePage="blog"
+categoryPage="html/blog.html"
+article="html/blog/$filename.html"
-if [ "$2" = "" ]; then
- echo "Missing second argument."
+if [ "$1" = "" ]; then
+ echo "Missing file to publish."
exit 2
fi
-if [ ! -f "$2" ]; then
- echo "File $2 not found."
+if [ ! -f "$1" ]; then
+ echo "File $1 not found."
exit 2
fi
@@ -91,43 +55,21 @@ if [ ! -x "$(command -v ed)" ]; then
fi
# Make sure that there is an up-to-date compiled version of the page
-./compile "$2"
-
-# Update the relevant category page
-if [ $publishBlog ]; then
- awk -v pt="$pageTitle" -v bp="$basePage" -v f="$filename" -v d="$miniDate"\
- '{print} /^<ul>/ && !n {print " <li>"d" <a href=\""bp"/"f"\">"pt"</a></li>"; n++}'\
- pages/"$basePage".md > tmp.md && mv tmp.md pages/"$basePage".md
-elif [ $publishProject ]; then
- while true; do
- read -p "Is this a web-utility? " yn
- case $yn in
- [Yy]* ) webUtil=1; break;;
- [Nn]* ) webUtil=0; break;;
- * ) echo "Please answer Y|y or N|n.";;
- esac
- done
- if [ "$webUtil" = "1" ]; then
- sed -i "/web-utils/a \ \ \ \ \<li\>\<a href=\"$basePage\/$filename\"\>$pageTitle\<\/a\>\<\/li\>" pages/$basePage.md
- else
- # The meta text of the .md becomes the description on the projects.html page
- metaText=$(sed '3!d' pages/"$basePage"/"$filename".md | cut -d# -f 2)
- # Remove leading whitespace, surrounding quotes, forward slash characters
- metaTextClean=$(echo -e "${metaText}" | sed -e 's/^[[:space:]]*//')
- metaTextClean=$(sed -e 's/\//\\\//g' <<< "$metaTextClean")
- metaTextClean=$(sed -e 's/^"//' -e 's/"$//' <<< "$metaTextClean")
- sed -i "/normal-projects/a \ \ \ \ \<li\>\<a href=\"$basePage\/$filename\"\>$pageTitle\<\/a\>: $metaTextClean\<\/li\>" pages/$basePage.md
- fi
-else
- sed -i "/<ul>/a \ \ \ \ \<li\>\<a href=\"$basePage\/$filename\"\>$pageTitle\<\/a\>\<\/li\>" pages/$basePage.md
-fi
+./compile "$1"
+
+# Update the main blog list page
+awk -v pt="$pageTitle" -v bp="$basePage" -v f="$filename" -v d="$miniDate" \
+ '{print} /^<ul>/ && !n {print " <li>"d" <a href=\""bp"/"f"\">"pt"</a></li>"; n++}' \
+pages/"$basePage".md > tmp.md && mv tmp.md pages/"$basePage".md
+
./compile pages/$basePage.md
# Update the home page to show the new published article and remove oldest entry
-sed -i "/<\/div>/a $miniDate \<a class=\"feed-item\" href=\"$basePage\/$filename\"\>$newString $pageTitle\<\/a\>\n" pages/home.md
+sed -i "/<\/div>/a $miniDate \<a class=\"feed-item\" href=\"$basePage\/$filename\"\>$pageTitle\<\/a\>\n" pages/home.md
ed -s pages/home.md <<< $'8,$g/### What is a Parity Bit/-2,-1d\nw'
./compile pages/home.md
+
tput setaf 3; tput bold; tput smul
echo "### PUBLISHING: $filename"
tput sgr0
@@ -150,20 +92,9 @@ entry="${entry}
entry="${entry}
<pubDate>$date</pubDate>"
-if [ $publishBlog ]; then
- # Get content of \<page\>-content.html and make description
- pageContent=$(cat build/blog/"$filename"-content.html)
- entry="${entry}
- <description><![CDATA[$pageContent]]></description>"
-else
- # Otherwise get description from user
- echo "REPLACE THIS TEXT WITH A DESCRIPTION FOR THE PROJECT/GUIDE." \
- > $descriptionFile
- /usr/bin/editor $descriptionFile
- description=$(cat $descriptionFile)
- entry="${entry}
- <description><![CDATA[$description]]></description>"
-fi
+pageContent=$(cat build/blog/"$filename"-content.html)
+entry="${entry}
+<description><![CDATA[$pageContent]]></description>"
# Close the entry
entry="${entry}
@@ -173,23 +104,20 @@ tput setaf 2; tput bold
echo "[DONE]"
tput sgr0
-# Update the main feed and the relevant category feed
-printf " Updating feed files... "
+
+# Update the RSS feed
+printf " Updating RSS feed... "
mv "$mainFeed" "$mainFeed.bak"
head -n 8 "$mainFeed.bak" > "$mainFeed"
echo "$entry" >> "$mainFeed"
tail -n +9 "$mainFeed.bak" >> "$mainFeed"
-mv "public/$feed" "public/$feed.bak"
-head -n 8 "public/$feed.bak" > "public/$feed"
-echo "$entry" >> "public/$feed"
-tail -n +9 "public/$feed.bak" >> "public/$feed"
-
tput setaf 2; tput bold
echo "[DONE]"
tput sgr0
+
# Update the sitemap
printf " Updating sitemap.xml "
baseURLClean=$(sed -e 's/\//\\\//g' <<< "$baseURL")
@@ -199,11 +127,12 @@ tput setaf 2; tput bold
echo "[DONE]"
tput sgr0
-# Upload the new feeds plus the new article and updated pages to the website
-printf " Uploading pages and feeds... "
+
+# Upload the new feed plus the new article and updated pages to the website
+printf " Uploading pages and feed... "
cd public && rsync -rR html/home.html sitemap.xml feeds/sitewide-feed.xml \
-"$feed" "$categoryPage" "$article" "$destination" && cd ..
+"$categoryPage" "$article" "$destination" && cd ..
tput setaf 2; tput bold
echo "[DONE]"