jekyll post page 生成脚本

脚本功能:

  1. md 文件创建
  2. md 头内容生成
  3. 生成随机短地址作为permalink,以便为每个page实现固定地址

脚本内容:

#!/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: ""
date: ${post_date} +0800
categories: default
permalink: /posts/${random_addr}/
tags: [writing]
---

EOF


使用方法:

./new_post.sh <the new page name>

同步自 hxysayhi

posted @ 2022-02-24 23:49  hxysayhi  阅读(55)  评论(0编辑  收藏  举报