Skip to content

Commit 46d267d

Browse files
committed
add create_static_site.sh
1 parent 8a0aa9a commit 46d267d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This static copy was created by:
2323
- [GNU Wget Manual](http://www.gnu.org/software/wget/manual/wget.html)
2424
2. Updating the files using GNU sed
2525
```shell
26-
./bin/update_for_static.sh
26+
./bin/create_static_site.sh
2727
```
2828
- [sed, a stream editor](https://www.gnu.org/software/sed/manual/sed.html)
2929
(manual)

bin/create_static_site.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -o errtrace
3+
set -o nounset
4+
5+
6+
if command -v gsed >/dev/null; then
7+
SED=gsed
8+
elif sed --version >/dev/null; then
9+
SED=sed
10+
else
11+
echo 'GNU sed is required. If on macOS install `gnu-sed` via brew.' 1>&2
12+
exit 1
13+
fi
14+
15+
16+
function _change_to_repo_dir {
17+
cd "${0%/*}/.." >/dev/null
18+
}
19+
20+
21+
function _recreate_docs_dir {
22+
rm -rf docs
23+
cp -a temp_download docs
24+
touch docs/.nojekyll
25+
printf 'stateof.creativecommons.org' > docs/CNAME
26+
}
27+
28+
29+
function _convert_urls_to_absolute_paths {
30+
# Non-escaped URLs
31+
for _pattern in 'http://stateof\.creativecommons\.org/' \
32+
'https://stateof\.creativecommons\.org/'
33+
do
34+
for _file in $(grep --files-with-matches --max-count=1 \
35+
--recursive "${_pattern}" docs)
36+
do
37+
gsed --in-place -e"s#${_pattern}#/#g" "${_file}"
38+
done
39+
done
40+
# Escaped URL
41+
for _file in $(grep --fixed-strings --files-with-matches --max-count=1 \
42+
--recursive 'https:\/\/stateof.creativecommons.org\/' docs)
43+
do
44+
gsed --in-place \
45+
-e's#https:\\/\\/stateof\.creativecommons\.org\\/#\\/#g' "${_file}"
46+
done
47+
}
48+
49+
50+
_change_to_repo_dir # must be called first
51+
_recreate_docs_dir
52+
_convert_urls_to_absolute_paths

0 commit comments

Comments
 (0)