-
Notifications
You must be signed in to change notification settings - Fork 29
/
merge_pages.sh
executable file
·117 lines (101 loc) · 3.5 KB
/
merge_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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
set -eu
srcdir="$(dirname "$(realpath "$0")")"
. ./_conf.env
if [ $# -gt 0 ] && [ "$1" = "-no-help" ]; then
shift
NO_HELP=1
VERS="$(echo "$VERS"|grep :dev:)"
else
NO_HELP=0
fi
NL="
"
cd "$srcdir"
mkdir -p _tmp
rm -fr _tmp/site || :
[ -d jekyll/_site ] || { echo "The Jekyll part of the website was not built! Cannot continue"; exit 1; }
[ -d _build/main/"$SPHINXTYPE" ] || { echo "The Sphinx part of the website was not built! Cannot continue"; exit 1; }
[ $NO_HELP -eq 1 ] || [ -d _build/dev/"$SPHINXTYPE" ] || { echo "The Sphinx part of the website was not built! Cannot continue"; exit 1; }
cp -a jekyll/_site _tmp/site
OIFS=$IFS
IFS=$NL
clean_placeholder=$(grep -FxRl '# sphinx' _tmp/site || :)
if [ -n "$clean_placeholder" ]; then
rm -v $clean_placeholder
fi
# need to investigate...
fix_source_link=$(grep -FRl '/tree/gh-pages/' _tmp/site || :)
if [ -n "$fix_source_link" ]; then
sed -i -e 's|/tree/gh-pages/|/tree/main/jekyll/|g' $fix_source_link
fi
IFS=$OIFS
mv _tmp/site/sitemap.xml _tmp/site/sitemap2.xml
rm -fr gh-pages || :
mkdir -p gh-pages
rsync -aC _build/main/"$SPHINXTYPE"/ gh-pages/
if [ $NO_HELP -eq 1 ]; then
: # skip help versions, for quick preview only
else
rm -fr gh-pages/documentation/help gh-pages/_sources/documentation/help
cp -r _build/dev/"$SPHINXTYPE"/documentation/help gh-pages/documentation/
cp -r _build/dev/"$SPHINXTYPE"/_sources/documentation/help gh-pages/_sources/documentation/
fi
for vtn in $VERS; do
tag=$(echo "$vtn" | cut -d: -f3)
ver=$(echo "$vtn" | cut -d: -f2)
if [ "$ver" != "dev" ]; then
cp -r _build/"$ver"/"$SPHINXTYPE"/documentation/help/"$ver" gh-pages/documentation/help
cp -r _build/"$ver"/"$SPHINXTYPE"/_sources/documentation/help/"$ver" gh-pages/_sources/documentation/help
else
rm -fr _tmp/sphinx-for-"$tag"
fi
done
# fix sphinx_sitemap for sphinx 5
sed -i \
-e 's|<loc>'"$BASEURL$ABS_BASE"'en/|<loc>'"$BASEURL$ABS_BASE"'|g' \
gh-pages/sitemap.xml
if [ "$SPHINXTYPE" = "dirhtml" ]; then
mv gh-pages/404/index.html gh-pages/404.html
rmdir gh-pages/404
rm -fr gh-pages/genindex
sed -i \
-e 's|<url><loc>'"$BASEURL$ABS_BASE"'404/</loc></url>||g' \
-e 's|<url><loc>'"$BASEURL$ABS_BASE"'genindex/</loc></url>||g' \
gh-pages/sitemap.xml
else
rm -f gh-pages/genindex.html
sed -i \
-e 's|<url><loc>'"$BASEURL$ABS_BASE"'404.html</loc></url>||g' \
-e 's|<url><loc>'"$BASEURL$ABS_BASE"'genindex.html</loc></url>||g' \
gh-pages/sitemap.xml
fi
mv gh-pages/sitemap.xml gh-pages/sitemap1.xml
# special fix for 404 as it can appear anywhere on the site
perl -i -p -e 's{\b(href|src)="([^"]+?)"}{
my ($attr, $link) = ($1, $2);
$link =~ s{^[.][.]/}{} if "dirhtml" eq "'"$SPHINXTYPE"'";
$link = "'"$ABS_BASE"'/$link"
unless $link =~ m{://} || $link =~ m{^[/#]};
qq{$attr="$link"}
}ge;
s{\b(data-url_root)="[^"]+?"}{$1="'"$ABS_BASE"'/"}g;
$_="" if / rel="canonical" /' gh-pages/404.html
OIFS=$IFS
IFS=$NL
fix_base=$(grep -RlF "@@ABS_BASE@@" gh-pages | grep -v '^gh-pages/_sources')
if [ -n "$fix_base" ]; then
sed -i -e 's|@@ABS_BASE@@|'"$ABS_BASE"'|g' $fix_base
fi
IFS=$OIFS
rsync -aC _tmp/site/ gh-pages/
rm -fr _tmp/site
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">
<sitemap>
<loc>$BASEURL${ABS_BASE}sitemap1.xml</loc>
</sitemap>
<sitemap>
<loc>$BASEURL${ABS_BASE}sitemap2.xml</loc>
</sitemap>
</sitemapindex>" >gh-pages/sitemap.xml