Created
September 25, 2020 14:26
-
-
Save zanshin/cf794de884095f5b8f076831ca0d5428 to your computer and use it in GitHub Desktop.
Bash script to aid in converting Jekyll posts to Hugo posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! /bin/bash | |
set -e | |
set -o pipefail | |
# header-cleanup.sh | |
# | |
# Read files with Jekyll style YAML headers and "clean them" so that Hugo | |
# conversion works. | |
# | |
# Problems: | |
# | |
# * date formatting | |
# | |
# Parse the given file to find the YAML-y bits | |
# Possible meta entries include: | |
# layout: | |
# title: | |
# date: | |
# categories: | |
# link: | |
# | |
function front-matter() { | |
echo -e "\n\nProcessing $filename" | |
if [[ "$1" =~ [^layout.*] ]]; then | |
echo "layout found" | |
fi | |
if [[ "$1" =~ [^title.*] ]]; then | |
echo "title found" | |
fi | |
if [[ "$1" =~ [^date.*] ]]; then | |
echo "date found" | |
fi | |
if [[ "$1" =~ [^categories.*] ]]; then | |
echo "categories found" | |
fi | |
if [[ "$1" =~ [^comments.*] ]]; then | |
echo "comments found" | |
fi | |
if [[ "$1" =~ [^link.*] ]]; then | |
echo "link found" | |
fi | |
} | |
echo "Starting clean up..." | |
BEFORE="$HOME/code/jtoh/before" | |
AFTER="$HOME/code/jtoh/after" | |
for filename in "$BEFORE"/*; do | |
echo -e "\n\n$filename" | |
while IFS= read -r line | |
do | |
front-matter "$line" | |
done < "$filename" | |
done | |
echo -e "\n\n\n... and done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment