-
Notifications
You must be signed in to change notification settings - Fork 17
/
refactor_page_bundles_to_pages.sh
42 lines (33 loc) · 1.13 KB
/
refactor_page_bundles_to_pages.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
#!/usr/bin/env bash
# Converts homepage page bundles to page files.
#
# E.g. an About section named `content/home/about/index.md` is converted to `content/home/about.md`
refactor_page_bundles_to_pages()
{
# Check that the command was run from the site root.
if [ ! -d ./content/ ]; then
echo "Please run the script from the root of your Academic site" >&2
exit 1
fi
# Iterate over the homepage sections (excluding Gallery as it generally requires a bundle).
local files="$(find ./content/home/*/index.md -not './content/home/gallery/index.md')"
for file in ${files}; do
local pagedir="$(dirname ${file})"
local pagename="$(dirname ${file}).md"
echo "${file} -> ${pagename}"
# Check file does not already exist.
if [ -f "${pagename}" ]; then
echo "File ${pagename} already exists!"
exit 1
fi
# For dry run, comment out `mv` and `rm` lines below.
mv "${file}" "${pagename}"
# Let user decide whether to remove dir as may contain assets.
\rm -ri "${pagedir}"
done
}
# Bash Strict Mode
set -eu
# To debug, uncomment line below:
# set -x
refactor_page_bundles_to_pages "$@"