Write Blog With Hugo Workflow by Bash Script


用bash script启动hugo blog过程

Hugo自带了相关命令撰写blog,如:hugo new post/a-long-title , 也有大神(@yihui)写了一个R package blogdown,能符合大部分用户需求。

我专门针对我的需求写了一个bash script。

使用方法: hugonew post|talk|project|publication a long title with space

特点:

  • 标题可以用空格分开
  • 在指定类别下生成的文件路径与文件名格式为:content/TYPE/YYYYMMDD-a-long-title-with-space/index.md

Bash script记录如下:

$cat ~/bin/hugonew

#!/bin/bash

echo "Manual"
echo "hugonew post|talk|project|publication a long title with space"

title=$@
title=${title// /-}
title=${title/$1-/}
d=`date '+%Y%m%d'`

cd ~/unclassified/drwater.net
hugo new $1/$title/index.md

FILE=~/unclassified/drwater.net/content/"$1"/"$title"/index.md
echo $FILE

if [ -f $FILE ]; then
   echo "`CONTENT` will be used."
    mv ~/unclassified/drwater.net/content/$1/$title/ \
    ~/unclassified/drwater.net/content/$1/$d-$title/
    $EDITOR ~/unclassified/drwater.net/content/$1/$d-$title/index.md
else
   echo "`CONTENTZH` will be used."
    mv ~/unclassified/drwater.net/contentzh/$1/$title/ \
    ~/unclassified/drwater.net/contentzh/$1/$d-$title/
    $EDITOR ~/unclassified/drwater.net/contentzh/$1/$d-$title/index.md
fi
苏命
苏命
副研究员

我的研究方向:水源地水质安全保障,主要针对水源地由于藻类爆发引起的水体嗅味问题开展研究。