Fix nfc-web geohash_tools plugin dependency

This commit is contained in:
randogoth 2026-02-07 21:28:00 +02:00
parent b3416915fd
commit 6a9ba0dd94

View file

@ -26,6 +26,48 @@ let
# Drop draft content before building (Pelican draft detection can be inconsistent). # Drop draft content before building (Pelican draft detection can be inconsistent).
grep -RIl '^status:[[:space:]]*draft' content | xargs -r rm -f grep -RIl '^status:[[:space:]]*draft' content | xargs -r rm -f
fi fi
# nfc-web's `geohash` Pelican plugin imports `geohash_tools`, but that module
# isn't shipped in the repo. Provide a tiny implementation at build time.
if [ -d plugins ] && [ -f plugins/geohash/geohash.py ] && [ ! -f plugins/geohash_tools.py ]; then
cat > plugins/geohash_tools.py <<'PY'
BASE32 = "0123456789bcdefghjkmnpqrstuvwxyz"
def encode(latitude, longitude, precision=12):
lat_interval = [-90.0, 90.0]
lon_interval = [-180.0, 180.0]
geohash = []
bit = 0
ch = 0
even = True
bits = [16, 8, 4, 2, 1]
while len(geohash) < precision:
if even:
mid = (lon_interval[0] + lon_interval[1]) / 2.0
if longitude >= mid:
ch |= bits[bit]
lon_interval[0] = mid
else:
lon_interval[1] = mid
else:
mid = (lat_interval[0] + lat_interval[1]) / 2.0
if latitude >= mid:
ch |= bits[bit]
lat_interval[0] = mid
else:
lat_interval[1] = mid
even = not even
if bit < 4:
bit += 1
else:
geohash.append(BASE32[ch])
bit = 0
ch = 0
return "".join(geohash)
PY
fi
if [ -f pelicanconf.py ]; then if [ -f pelicanconf.py ]; then
${pythonEnv}/bin/pelican content -o "$out" -s pelicanconf.py ${pythonEnv}/bin/pelican content -o "$out" -s pelicanconf.py
else else