Static comments script for Hugo (in PHP)

I wrote a small(ish) moderation script for the shell. Requires ksh (probably works with bash too) and yq. You’ll need to store moderated comments as .yml2 (just change the $filepath line in the PHP script!).

#!/usr/bin/env ksh
done_something=0    # 1, if Hugo needs to be run

echo Comments moderation script for Hugo.
read content_path?"Path to /content: "

# Remove the trailing /, if any:
if [[ "$content_path" == */ ]]; then
    content_path=${content_path%?}
fi

if [ -d $content_path ]; then
    # Path exists.
    # Search for .yml2 files:
    file_list=`find $content_path -name "*.yml2"`
    if [ -z $file_list ]; then
        echo No comments are currently awaiting moderation.
        exit
    fi

    # Comments were found.
    comment_counter=1
    for comment_file in $file_list; do
        echo ""
        echo ---------------------
        echo Comment no. $comment_counter:
        echo ""

        # Read:
        echo "    Post:     `yq -e '.post_id' $comment_file`"
        echo "    Author:   `yq -e '.author' $comment_file` (`yq -e '.email' $comment_file`)"
        echo "    Text:     `yq -e '.comment' $comment_file`"
        echo ""

        # What to do?
        read action?"[P]ublish, [D]elete, [E]dit first? "
        case $action in
            P|p)
                # Rename .yml2 to .yml:
                newName=${comment_file%?}
                mv $comment_file $newName
                done_something=1
                echo The comment will be published.
                ;;
            D|d)
                # Delete $comment_file:
                rm $comment_file
                echo Comment deleted.
                ;;
            E|e)
                # Edit $comment_file, then publish it:
                vi $comment_file  # you could also use ed here, or emacs...
                newName=${comment_file%?}
                mv $comment_file $newName
                done_something=1
                echo The comment has been edited and will be published.
                ;;
            *)
                echo This comment will be skipped.
                ;;
        esac
        
        ((comment_counter++))
    done

    # Run Hugo if a new comment has been published:
    if [[ $done_something -eq 1 ]]; then
        cd $content_path/..
        hugo
    fi
else
    echo Wrong path.
fi