-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
website: create html redirects for archived rvspoc 2023 challenges (#141
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Format: | ||
# <from-path> -> <to-path> | ||
# the from-path is relative to the root location. | ||
# for the to-path: | ||
# if staring with a '/', it's relative to the root location | ||
# if staring with no '/', it's relative to the from-path | ||
|
||
# challenges of 2023 archives | ||
p2301/ -> /2023/p2301/ | ||
p2303/ -> /2023/p2303/ | ||
p2304/ -> /2023/p2304/ | ||
p2307/ -> /2023/p2307/ | ||
p2308/ -> /2023/p2308/ | ||
s2302/ -> /2023/s2302/ | ||
s2305/ -> /2023/s2305/ | ||
s2306/ -> /2023/s2306/ | ||
s2309/ -> /2023/s2309/ | ||
s2310/ -> /2023/s2310/ | ||
s2311/ -> /2023/s2311/ | ||
s2312/ -> /2023/s2312/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env bash | ||
# | ||
|
||
set -e | ||
|
||
CURDIR="$(dirname "$(realpath "$0")")" | ||
PUBDIR="$(realpath "${CURDIR}/../public")" | ||
|
||
RECORDS_FROM=() | ||
RECORDS_TO=() | ||
|
||
_do() { | ||
echo ">>>" "$@" >&2 | ||
"$@" | ||
} | ||
|
||
_sed_Ei() { | ||
if [[ $IS_BSD_SED == 0 ]]; then | ||
_do sed -Ei "$@" | ||
elif [[ $IS_BSD_SED == 1 ]]; then | ||
_do sed -Ei '' "$@" | ||
else | ||
if sed --version &>/dev/null; then | ||
IS_BSD_SED=0 | ||
else | ||
IS_BSD_SED=1 | ||
fi | ||
_sed_Ei "$@" | ||
fi | ||
} | ||
|
||
read_config() { | ||
local record | ||
while read -r record; do | ||
if [[ $record =~ ^[[:space:]]*# ]] || \ | ||
[[ $record =~ ^[[:space:]]*$ ]]; then | ||
# skip comments and empty lines | ||
continue | ||
fi | ||
if [[ $record =~ ^[[:space:]]*([^[:space:]]+)\ -\>\ ([^[:space:]]+)[[:space:]]*$ ]]; then | ||
RECORDS_FROM+=( "${BASH_REMATCH[1]}" ) | ||
RECORDS_TO+=( "${BASH_REMATCH[2]}" ) | ||
else | ||
echo "unrecognized record '$record', skip it.." >&2 | ||
continue | ||
fi | ||
done <"${CURDIR}/config" | ||
} | ||
|
||
create_one() { | ||
local from="${1##/}" from_fp to="$2" | ||
from_fp="${PUBDIR}/${from}" | ||
_do mkdir -p "$from_fp" | ||
_do cp "${CURDIR}/tmpl.html" "${from_fp%%/}/index.html" | ||
if ! [[ $to =~ ^/ ]]; then | ||
to="/${from%%/}/${to}" | ||
fi | ||
_sed_Ei "s@\@TO-PATH\@@${to}@g" "${from_fp%%/}/index.html" | ||
} | ||
|
||
echo "creating html redirections..." | ||
read_config | ||
for (( i=0; i<${#RECORDS_FROM[@]}; i++ )); do | ||
create_one "${RECORDS_FROM[i]}" "${RECORDS_TO[i]}" | ||
done | ||
|
||
# vim:sw=8:ts=8:noexpandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="refresh" content="0;url=https://rvspoc.org@TO-PATH@"> | ||
<title>Redirecting...</title> | ||
<script type="text/javascript"> | ||
window.location.href = "https://rvspoc.org@TO-PATH@"; | ||
</script> | ||
</head> | ||
<body> | ||
<p>如若未自动跳转,请点击<a href="https://rvspoc.org@TO-PATH@">此链接</a>。</p> | ||
<p>If you are not redirected automatically, please follow this <a href="https://rvspoc.org@TO-PATH@">link</a>.</p> | ||
</body> | ||
</html> |