-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_post.sh
69 lines (54 loc) · 1.28 KB
/
create_post.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Colors and styles
Green='\033[0;32m'
Blue='\033[0;34m'
ColorReset='\033[0m'
bold=$(tput bold)
normal=$(tput sgr0)
echo -e "${Blue}${bold}Script to create new Jekyll posts easily.${normal}${ColorReset}"
# The post directory
POSTS_DIR='./_posts/'
# Post title
# Trim leading spaces
read -rp "${bold}Title:${normal} " -a TITLE
TITLE="$(echo "${TITLE[@]}" | sed -e 's/^[ \t]*//')"
# Date
read -rp "${bold}Date${normal}(NULL==today): " -a DATE
if [ -z "${DATE[*]}" ]; then
DATE=$(date +%Y-%m-%d)
fi
# Post extension
EXT='.md'
# File name should be lowercase
FILENAME=$(echo "$TITLE" | tr ' ' '_')
DIRNAME=${DATE}-${FILENAME}
FILENAME=${DATE}-${FILENAME}${EXT}
mkdir -p ./images/${DIRNAME}
# Go to _posts and create a file
cd ${POSTS_DIR}
touch ${FILENAME}
# Add YAML front matter and excerpt space
# (해당부분은 각자의 Jekyll 테마에 맞추어 변경이 필요하다)
tee -a $FILENAME >/dev/null <<END
---
layout: post
title: ${TITLE}
image: ${DIRNAME}/banner.png
date: ${DATE}
tags:
categories:
comments: true #Disqus코멘트 허용여부
---
# ${TITLE}
<br>
# 1. 개요
---
개요본문
<br>
# 2. 내용
---
## 2.1 내용하위제목
내용본문
END
echo -e "${Green}${bold}File was successfully created!
❯${ColorReset}${normal} ${POSTS_DIR}${FILENAME}"