forked from letsencrypt/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-page.sh
executable file
·71 lines (63 loc) · 1.6 KB
/
new-page.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
70
71
#!/usr/bin/env bash
if [ -z "${1}" ] || [ -z "${2}" ] || [ "${1}" = "-h" ] || [ "${1}" = "-help" ] || [ "${1}" = "--help" ]
then
echo "Usage: "${0}" <page-path> <page title>"
echo "Examples:"
echo "${0} my-page \"My Page Title\""
echo "${0} post/my-post \"My Post Title\""
exit 1
fi
path=$(dirname "${1}")
slug=$(basename "${1}")
filename="${slug}.md"
title="${2}"
date=$(date +%Y-%m-%d)
for i in $(find . -type d -path './content/*' -maxdepth 2)
do
# If the directory doesn't exist, create it.
if ! [ -d "${i}/${path}" ] && ! [ "${path}" = post ]
then
mkdir -p "${i}/${path}"
echo "Created directory: ${i}/${path}"
fi
# Actions only for English (e.g. blog posts, etc.)
if [ ${i} = "./content/en" ]
then
# Create the new page.
if ! [ -f "${i}/${path}/${filename}" ]
then
cat > "${i}/${path}/${filename}" << EOF
---
title: ${title}
slug: ${slug}
top_graphic: 1
lastmod: ${date}
show_lastmod: false
---
EOF
echo "Created page: ${i}/${path}/${filename}"
fi
else
# Actions only for non-English (e.g. no-translation stubs, etc.)
# Blog posts are only created for the "en" directory.
if [ "${path}" = post ]
then
continue
fi
# Create the stub (untranslated) page.
if ! [ -f "${i}/${path}/${filename}" ]
then
cat > "${i}/${path}/${filename}" << EOF
---
title: ${title}
slug: ${slug}
top_graphic: 1
lastmod: ${date}
show_lastmod: false
untranslated: 1
---
EOF
echo "Created page: ${i}/${path}/${filename}"
fi
fi
done