-
Notifications
You must be signed in to change notification settings - Fork 0
/
newcategory.sh
executable file
·44 lines (37 loc) · 959 Bytes
/
newcategory.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
#!/bin/bash
#
# This script creates a new category page with metadata in ./categories
# folder. Usage:
#
# newcategory.sh Category Label
#
title="${*:1}"
if [[ -z "$title" ]]; then
echo 'usage: newcategory.sh Category Label'
exit 1
fi
bloghome=$(cd "$(dirname "$0")" || exit; pwd)
category=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
filepath="${bloghome}/_displayed_en_categories/${category}.md"
#if [[ ! -d "${bloghome}/_displayed_en_categories ]]
#then
# echo "Categories directory does not exist: ${bloghome}/_displayed_en_categories"
# exit 1
#fi
if [[ -f "$filepath" ]]
then
echo "$filepath already exists."
exit 1
fi
cat << EOF >> "$filepath"
---
layout: category
title: ${title}
category: ${category}
sidebar:
nav: categories
comments: false
---
EOF
echo "Category page created: $filepath"
echo "Please manually edit _data/navigation.yml"