Jekyll快速新建文章脚本
Jekyll 新建文章很麻烦,除了粘贴复制头,还要改文章的标题和时间,非常繁琐,下面的脚本可以自动获取文章创建时间,并添加基础信息,非常方便。
创建 new-post.sh
, 放到jekyll 网站根目录,即和_posts
同级目录,内容如下:
这是一个模板信息,作者,分类,标签等都可以根据自己的需要修改。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
DIR="${0%/*}"
title=`echo $@ | sed 's/[ ][ ]*/-/g'`
post_date=`date +"%Y-%m-%d %T"`
post_name="`date "+%Y-%m-%d"`-${title}.markdown"
random_addr=`openssl rand -hex 8 | md5 | cut -c1-8`
cat > ${DIR}/_posts/${post_name} << EOF
---
layout: post
title: "${title}"
description: ""
author: 作者
date: ${post_date} +0800
permalink: ${random_addr}.html
categories:
- 分类
tags:
- 标签
---
EOF
# 创建完打开文章
open ${DIR}/_posts/${post_name}
如果创建新文章,执行 ./new-post.sh 文章名字
即可

本文由作者按照 CC BY 4.0 进行授权