Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
自动生成blog 模板
#! /bin/bash
#cd current path
cd `dirname $0`
#get post name
postName=$1
#split post name with '-'
array=(${postName//,/})
printf -v var "%s-" "${array[@]}"
var=${var%?}
#get date
dateName=$(date +%Y-%m-%d-)
#create .md file
fileName=$dateName$var'.md'
touch $fileName
#get post time
postTime=$(date +%Y-%m-%d%t%H:%M:%S)
#write template into .md file
cat > $fileName << EOF
---
layout: post
title: "$postName"
date: $postTime
categories: []
tags: []
---
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment