-
Notifications
You must be signed in to change notification settings - Fork 6
/
build-redirects.sh
executable file
·53 lines (41 loc) · 1.02 KB
/
build-redirects.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
#!/bin/bash
LATEST="latest"
INDEX_FILE="_index"
DOMAIN="$1"
set -eu
function fprint_index() {
local url="$1"
local file="$2"
echo "<!DOCTYPE html>
<html>
<head>
<title>$url</title>
<link rel='canonical' href='$url'/>
<meta name='robots' content='noindex'>
<meta http-equiv='content-type' content='text/html; charset=utf-8'/>
<meta http-equiv='refresh' content='0; url=$url'/>
</head>
</html>" > "$2"
}
function redirect_file() {
local newPath="$1"
local url="$DOMAIN/$LATEST/$newPath"
echo "creating redirect for $newPath"
mkdir -p "../../$newPath"
fprint_index "$url" "../../$newPath/index.html"
}
fprint_index "$DOMAIN/$LATEST" "index.html"
rm -rf docs
cd content/en
mdFiles=$(find docs -name "*.md")
for file in $mdFiles; do
name=$(basename "$file" .md)
path=$(dirname "$file" | awk '{print tolower($0)}')
if [[ "$name" == "$INDEX_FILE" ]]; then
redirect_file "$path"
else
name="$(echo "$name"| awk '{print tolower($0)}')"
redirect_file "$path/$name"
fi
done
cd -