diff options
| author | Giusto <giusto@Macbook-M1-Max.local> | 2024-07-25 09:33:12 +0800 | 
|---|---|---|
| committer | Giusto <giusto@Macbook-M1-Max.local> | 2024-07-25 09:33:12 +0800 | 
| commit | 421f0b1693d668a2d450b909db18eeb67328db7a (patch) | |
| tree | f5ee27157b6d8c40eeacd8820b7275e9d5b999bd /blog-zola.sh | |
create a directory to contain only script that fill my own needs
Diffstat (limited to 'blog-zola.sh')
| -rwxr-xr-x | blog-zola.sh | 119 | 
1 files changed, 119 insertions, 0 deletions
| diff --git a/blog-zola.sh b/blog-zola.sh new file mode 100755 index 0000000..c620789 --- /dev/null +++ b/blog-zola.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env sh + +###################################################################### +# @author      : garhve (dev@garhve.com) +# @file        : blog +# @created     : Friday Dec 09, 2022 16:09:42 CST +# +# @description : simplify blog publishing, it only can use in blog dir +###################################################################### + +# usage: prog funct + +push() { +    read -r -p "Do you want to push?[y/n] " ans +    if [ "$ans" == 'y' ]; then +        zola build +        git add . +        if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then +            read -r -p "commit message: " msg +            git commit -m "$msg" +            git push origin main +        fi +    echo -e "push done" +    fi +} + +edit() { +    path="content/post" + +    # --- get editing file +    choice=1 +    declare -a arr +    for file in $path/*; do +        [[ "$file" == *"_index.md" ]] && continue +        echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m  "     # n get rid of trailing new line, e strip backslash +        arr[$choice]="$file" +        choice=$((choice+1)) +    done +    echo "" +    read -r -p "please choose file by number you want to edit from above: " num +    [[ "$num" == "q" ]] && exit 0 +    vim "${arr[$num]}" +    # --- end +    echo -e "edit done\n" + +    push +    echo -e "\nall done" +} + +new() { +    read -r -p "blog name: " name +    path="content/post/$name" + +    if [ ! -f "$path".md ]; then + +        # get basic format +        d="$(date +%F)" +        echo -ne "\x1b[32m" +        echo -n "existing categories: " +        grep -wrn content -e "categories" | \ +            awk -F = '{ print $2 }' | \ +            sort | uniq | paste -s -d ' ' +        echo -ne "\x1b[0m" +        read -r -p "category: " category +        echo -ne "\x1b[32m" +        echo -n "existing tags: " +        grep -wrn content -e "tags" | \ +            awk -F = '{ print $2 }' | \ +            sort | uniq | paste -s -d ' ' +        echo -ne "\x1b[0m" +        read -r -p "tag: " tags +        read -r -p "math support [y/n]: " m +        if [ "${m,,}" == 'y' ]; then +            math_support="true" +        else +            math_support="false" +        fi + +        cat << EOF > "$path".md ++++ +title = "$name" +date = $d +[taxonomies] +categories = ["$category"] +tags = ["$tags"] +[extra] +math = $math_support ++++ +EOF + +        [ "$?" -eq 0 ] && echo "creation done" +        [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1 + +    else +        echo "File exist" +    fi + +    read -r -p "do you want to edit now?[y/n] " ans +    [ "${ans,,}" == 'y' ] && vim "$path.md" && echo "edit done" + +    push + +    echo -e "\nall done" +} + +list() { +    echo -e "\x1b[1;34mList content:\x1b[0m" +    tree ./content/post +} + + +funct="new/edit/push/ls" + +[ $# -lt 1 ] && echo "usage: $(basename $0) $funct" + +[ $1 == "new" ] && new +[ $1 == "edit" ] && edit +[ $1 == "push" ] && push +[ $1 == "ls" ] && list | 
