Skip to content

Instantly share code, notes, and snippets.

@bumaociyuan
Created October 25, 2014 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumaociyuan/fb1a5ba9d29f22bb0709 to your computer and use it in GitHub Desktop.
Save bumaociyuan/fb1a5ba9d29f22bb0709 to your computer and use it in GitHub Desktop.
自动生成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