web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit 7bb61073140c9b08da29d1d97ae61d9102d6872a
parent 3050d9930a0d793d12c3890312cf9aeed8e567e9
Author: triesap <triesap@radroots.dev>
Date:   Sun, 21 Dec 2025 01:36:11 +0000

utils-nostr: refactored location tag parsing and geotag generation, standardizing coordinate extraction and explicit geotag input construction

Diffstat:
Mutils-nostr/src/events/listing/parse.ts | 10+++++-----
Mutils-nostr/src/events/listing/tags.ts | 9+++++----
2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/utils-nostr/src/events/listing/parse.ts b/utils-nostr/src/events/listing/parse.ts @@ -161,12 +161,12 @@ export const parse_nostr_listing_event = (event: NDKEvent): RadrootsListingNostr const geohash = get_event_tags(tags, "g")[0]?.[1]; if (geohash) location_raw.geohash = geohash; - for (const locTag of get_event_tags(tags, "l")) { - if (locTag.length < 3) continue; - const coord = Number(locTag[1]); + for (const loc_tag of get_event_tags(tags, "l")) { + if (loc_tag.length < 3) continue; + const coord = Number(loc_tag[1]); if (!Number.isFinite(coord)) continue; - if (locTag[2] === "dd.lat") location_raw.lat = coord; - if (locTag[2] === "dd.lon") location_raw.lng = coord; + if (loc_tag[2] === "dd.lat") location_raw.lat = coord; + if (loc_tag[2] === "dd.lon") location_raw.lng = coord; } } diff --git a/utils-nostr/src/events/listing/tags.ts b/utils-nostr/src/events/listing/tags.ts @@ -82,11 +82,12 @@ export const tag_listing_location = (opts: NostrEventTagLocation): NostrEventTag }; export const tags_listing_location_geotags = (opts: NostrEventTagLocation): NostrEventTags => { - const { lat, lng: lon, city, region: regionName, country } = opts; + const { lat, lng: lon, city, region, country } = opts; const country_raw = country || ``; - const countryCode = country_raw && country_raw?.length <= 3 ? country_raw : undefined; - const countryName = country_raw && country_raw?.length > 3 ? country_raw : undefined; - return ngeotags({ lat, lon, city, regionName, countryCode, countryName } satisfies NostrGeotagsInputData, { geohash: true, gps: true, city: true, iso31662: true }); + const country_code = country_raw && country_raw?.length <= 3 ? country_raw : undefined; + const country_name = country_raw && country_raw?.length > 3 ? country_raw : undefined; + const input: NostrGeotagsInputData = { lat, lon, city, regionName: region, countryCode: country_code, countryName: country_name }; + return ngeotags(input, { geohash: true, gps: true, city: true, iso31662: true }); }; export const tag_listing_image = (opts: RadrootsListingImage): NostrEventTag => {