.. back to home

hugo new content 命令使用 & 自定义新增文章脚本


hugo new content

创建新的内容文件并自动设置日期和标题。它将根据提供的路径猜测要创建的文件类型。

1hugo new content [path] [flags]

hugo 新建文章,基本就是路径加文件名的命令,并不能只写名字,自动补全时间戳这种,自己写一个吧

1# 基本新建命令
2hugo new blogs/xxxxx.md

hugonew.sh 脚本

 1post_name=$1
 2post_name=`echo $post_name | tr -s ''` # 去除多余空格
 3post_name=` echo ${post_name} | sed 's/[ ]/-/g'` # 替换空格为 - 
 4echo ${post_name}
 5date_string=`date +%Y%m%d` # 日期字符串
 6date_string=`date +%Y%m%d%H%M%S` # 毫秒字符串
 7date
 8hugo new blogs/${post_name}.md $@
 9cd content/blogs/
10mv ${post_name}.md ${date_string}-${post_name}.md

执行 自动拼接日期串 可以自己替换为毫秒字符串

1sh hugonew.sh "tests    dsds SDASD    "
2tests-dsds-SDASD
3Sat Oct 14 22:19:43 CST 2023
4Content "/home/sharif/myblog/content/blogs/tests-dsds-SDASD.md" created

小问题生成之后文件中,文章名中带了日期,修改脚本,先建立文件,然后替换文件名