forked from redhat-cop/uncontained.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate-doc.sh
executable file
·44 lines (37 loc) · 1.48 KB
/
migrate-doc.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
PLAYBOOKS_SITE=~/src/openshift-playbooks/playbooks/
UNCONTAINED_SITE=~/src/uncontained.io/site/
PLAYBOOK=${1}
DOC=${2}
# Grab content from existing playbook
content="$(cat ${PLAYBOOKS_SITE}${PLAYBOOK})"
# Migrate images in content
images=$(echo "${content}" | awk '/image::/' | sed 's/image:://' | sed 's/\[.*\]//')
for i in ${images}; do
echo "Migrating image ${PLAYBOOKS_SITE}/../$i to ${UNCONTAINED_SITE}/static/$i";
cp ${PLAYBOOKS_SITE}/../$i ${UNCONTAINED_SITE}/static/$i
done
# Strip existing frontmatter
content=$(echo "${content}" | sed -n '/^= .*/,$p')
# Do some reformatting of content
content=$(echo "${content}" | sed 's/include::..\/..\/_includes\/variables.adoc\[\]/include::site\/layouts\/variables.adoc\[\]/')
# TODO: Reformat anchor tags.
# Old format: link:#syncing-images-using-satellite-6
# new format: link:#_syncing_images_using-satellite-6
# regex: link:#[a-z0-9]+[a-z-]*[a-z0-9]+
anchors=$(echo "${content}" | grep -o 'link:#[a-z0-9-]*')
for anchor in ${anchors}; do
content=$(echo "${content}" | sed "s/${anchor}/${anchor//-/_}/g")
done
content=${content//link:#/link:#_}
# Create uncontained doc
rm -f ${UNCONTAINED_SITE}/content/${DOC}
pushd ${UNCONTAINED_SITE}
hugo new ${DOC}
popd
# Grab frontmatter and combine with content
frontmatter=$(cat ${UNCONTAINED_SITE}/content/${DOC})
frontmatter=$(echo "${frontmatter}" | sed "s/draft: true/draft: false/")
cat > ${UNCONTAINED_SITE}/content/${DOC} <<zz_uncontained_content
${frontmatter}
${content}
zz_uncontained_content