Skip to content

Commit

Permalink
spamisi.sh: use page index instead of path for ID prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
bkil committed Mar 17, 2021
1 parent 3af26d4 commit 2cbdd79
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/web/spamisi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Test: https://bkil.gitlab.io/spamisi/

main() {
OBFUSCATEID="1"

local OUT="out"
mkdir -p "$OUT" || exit 1
local HTML="$OUT/html"
Expand Down Expand Up @@ -63,10 +65,10 @@ get_pages() {

get_file_list "$HTML" "$MAIN" |
{
local ISLOADING="1"
local PAGEIDX="0"
while read FILE; do
get_page "$FILE" "$ISLOADING"
local ISLOADING=""
get_page "$FILE" "$PAGEIDX"
local PAGEIDX="`expr $PAGEIDX + 1`"
done
} |
post_process_page "$IDREGEX" "$URLBASE"
Expand All @@ -91,7 +93,10 @@ get_file_list() {

get_page() {
local FILE="$1"
local ISLOADING="$2"
local PAGEIDX="$2"

local ISLOADING=""
[ "$PAGEIDX" = 0 ] && ISLOADING="1"

local ENDPOINT="`echo "$FILE" | sed "s~^$HTML/~~ ; s~/index.html$~~ ; s~\.html$~~"`"
local NAME="`echo "$ENDPOINT" | sed "s~/~--~g"`"
Expand All @@ -100,6 +105,10 @@ get_page() {
[ -n "$ISLOADING" ] &&
local IDNAME="SPAMISI-LOADING---$NAME"

local PRE="$PAGEIDX"
[ "$IDNAME" = "osm--housenumber-stats--hungary" ] &&
local PRE="${IDNAME}---"

local TITLE="`sed -nr "s~^.*<title>(.*)</title>.*$~\1~ ; T e; p; :e" "$FILE"`"
[ -n "$TITLE" ] || local TITLE="$IDNAME"

Expand All @@ -120,9 +129,9 @@ EOF

fgrep -v "<!DOCTYPE html>" "$FILE" |
sed -r "
s~ id=\"~ id=\"$IDNAME---~g
s~ id=\"~ id=\"${PRE}~g
s~(<a href=\"#)([^\"])~\1$IDNAME---\2~g
s~(<a href=\"#)([^\"])~\1${PRE}\2~g
s~(<a href=\"#)(\")~\1$IDNAME\2~g
Expand Down

0 comments on commit 2cbdd79

Please sign in to comment.