diff --git a/.gitignore b/.gitignore index cb30975..8990430 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ kleingebaeck releases t/out .bak +t/httproot/out +t/httproot/kleinanzeigen +t/httproot/favicon.ico diff --git a/t/httproot/README.md b/t/httproot/README.md new file mode 100644 index 0000000..64a244a --- /dev/null +++ b/t/httproot/README.md @@ -0,0 +1,13 @@ +# Mock http server + +Install ehfs from https://github.com/mjpclab/extra-http-file-server/. + +Install p2cli from https://github.com/wrouesnel/p2cli. + +Run `templates/render.sh` to build the file structure. + +Run `server.sh` to start the http server. + +To scrape an ad from it, use such a URL: + +http://localhost:8080/s-anzeige/first-ad/111-11-111 diff --git a/t/httproot/img/cdas4sd5-5258-42c2-bf58-as43as5d43as b/t/httproot/img/cdas4sd5-5258-42c2-bf58-as43as5d43as new file mode 100644 index 0000000..0521c28 Binary files /dev/null and b/t/httproot/img/cdas4sd5-5258-42c2-bf58-as43as5d43as differ diff --git a/t/httproot/img/cdas4sd5-5258-42c2-bf58-d1b8e9221574 b/t/httproot/img/cdas4sd5-5258-42c2-bf58-d1b8e9221574 new file mode 100644 index 0000000..75c508d Binary files /dev/null and b/t/httproot/img/cdas4sd5-5258-42c2-bf58-d1b8e9221574 differ diff --git a/t/httproot/img/fcf6d664-5258-42c2-bf58-as43as5d43as b/t/httproot/img/fcf6d664-5258-42c2-bf58-as43as5d43as new file mode 100644 index 0000000..d37ac06 Binary files /dev/null and b/t/httproot/img/fcf6d664-5258-42c2-bf58-as43as5d43as differ diff --git a/t/httproot/img/fcf6d664-5258-42c2-bf58-d1b8e9221574 b/t/httproot/img/fcf6d664-5258-42c2-bf58-d1b8e9221574 new file mode 100644 index 0000000..97e500d Binary files /dev/null and b/t/httproot/img/fcf6d664-5258-42c2-bf58-d1b8e9221574 differ diff --git a/t/httproot/serve.sh b/t/httproot/serve.sh new file mode 100755 index 0000000..9f6a816 --- /dev/null +++ b/t/httproot/serve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +ehfs -a :/s-anzeige:./kleinanzeigen \ + -a :/api/v1/prod-ads/images/fc:./img \ + -l localhost:8080 -I index.html diff --git a/t/httproot/templates/ad.tpl b/t/httproot/templates/ad.tpl new file mode 100644 index 0000000..34635c7 --- /dev/null +++ b/t/httproot/templates/ad.tpl @@ -0,0 +1,50 @@ + + + + Ad Listing + + + +
+
+ + +
+
+ + {% for image in images %} +
+ +
+ {% endfor %} + +

+ {{ title }}

+
+

+ {{ price }}

+
+ +
+
{{ created }}
+
+ +
+ +
+ +
+

+ {{ text }} +

+
+ + diff --git a/t/httproot/templates/index.tpl b/t/httproot/templates/index.tpl new file mode 100644 index 0000000..2d2a7ac --- /dev/null +++ b/t/httproot/templates/index.tpl @@ -0,0 +1,15 @@ + + + + Ads + + + {% for ad in ads %} +

+ {{ ad.title }} +

+ {% endfor %} + + + diff --git a/t/httproot/templates/render.sh b/t/httproot/templates/render.sh new file mode 100755 index 0000000..f1d4cb5 --- /dev/null +++ b/t/httproot/templates/render.sh @@ -0,0 +1,13 @@ +#!/bin/sh -x +base="../kleinanzeigen" +mkdir -p $base + +echo "Generating /s-bestandsliste.html" +p2cli -t index.tpl -i vars.yaml > $base/s-bestandsliste.html + +for idx in 0 1; do + slug=$(cat vars.yaml | yq ".ads[$idx].slug") + id=$(cat vars.yaml | yq ".ads[$idx].id") + mkdir -p $base/$slug/$id + cat vars.yaml | yq ".ads[$idx]" | p2cli -t ad.tpl -f yaml > $base/$slug/$id/index.html +done diff --git a/t/httproot/templates/vars.yaml b/t/httproot/templates/vars.yaml new file mode 100644 index 0000000..4406782 --- /dev/null +++ b/t/httproot/templates/vars.yaml @@ -0,0 +1,27 @@ +ads: + - slug: first-ad + id: 111-11-111 + title: First Ad + price: "19 €" + condition: "Sehr gut" + category: "Weitere Elektronik" + created: 21.12.2023 + images: + - id: fcf6d664-5258-42c2-bf58-d1b8e9221574 + - id: fcf6d664-5258-42c2-bf58-as43as5d43as + text: | + Zu Verkaufen. + Zahlung nur Paypal. + - slug: second-ad + id: 222-22-222 + title: Second Ad + price: "200 €" + condition: "Sehr gut" + category: "Elektronik" + created: 21.12.2023 + images: + - id: cdas4sd5-5258-42c2-bf58-d1b8e9221574 + - id: cdas4sd5-5258-42c2-bf58-as43as5d43as + text: | + Zu Verkaufen. + Zahlung nur Überweisung.