From d974cf4abe3d97776fcdaf00a87e4261caec60df Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 5 Sep 2025 22:52:24 +0200 Subject: [PATCH 1/4] grist data import --- .vscode/launch.json | 15 +++++++ markers.js | 97 +++++---------------------------------------- 2 files changed, 25 insertions(+), 87 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2ba986f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/markers.js b/markers.js index 3f28bb3..ea5a3f4 100644 --- a/markers.js +++ b/markers.js @@ -1,91 +1,14 @@ -// === CONFIG === -const WIKI_API = 'https://wiki.arenos.danielnagel.at/api.php'; // dein Wiki-Host (mit index.php) -const CATEGORY_TITLE = 'Kategorie:Orte'; // Hauptkategorie -const MAX_PAGES = 500; // genug Luft +const url = "https://data.arenos.danielnagel.at/api/docs/rp78Zashtzfe7mgFSbeMkd"; +const apiKey = "77fc2fdb0b54a27e4da954a077a670e67f45b203"; -// Hilfsfunktion: MediaWiki API-URL bauen -function apiURL(params) { - const u = new URL(WIKI_API); - u.search = new URLSearchParams({ ...params, format: 'json', origin: '*' }).toString(); - return u.toString(); -} - -// 1) Alle Mitglieder einer Kategorie holen -async function fetchCategoryMembers(categoryTitle) { - const url = apiURL({ - action: 'query', - list: 'categorymembers', - cmtitle: categoryTitle, - cmlimit: String(MAX_PAGES) - }); - const res = await fetch(url); - if (!res.ok) throw new Error(`categorymembers failed: ${res.status}`); - const data = await res.json(); - return data?.query?.categorymembers || []; -} - -// 2) Gerendertes HTML einer Seite holen (damit
drin ist) -async function fetchPageHTML(title) { - const url = apiURL({ - action: 'parse', - page: title, - prop: 'text' - }); - const res = await fetch(url); - if (!res.ok) throw new Error(`parse failed for ${title}: ${res.status}`); - const data = await res.json(); - const html = data?.parse?.text?.['*'] || ''; - const div = document.createElement('div'); - div.innerHTML = html; - return div; -} - -// 3) Daten aus dem versteckten Div extrahieren -function extractPlaceData(container) { - const node = container.querySelector('.place-data'); - if (!node) return null; - const name = node.getAttribute('data-name') || ''; - const xStr = node.getAttribute('data-x') || ''; - const yStr = node.getAttribute('data-y') || ''; - const desc = node.getAttribute('data-description') || ''; - const link = node.getAttribute('data-link') || ''; - const x = parseFloat(xStr); - const y = parseFloat(yStr); - if (Number.isNaN(x) || Number.isNaN(y)) return null; - return { name, x, y, desc, link }; -} - -// 4) Marker laden + hinzufügen -async function loadWikiMarkers(map) { - try { - const pages = await fetchCategoryMembers(CATEGORY_TITLE); - - // Optionales Bounding, falls du später auto-fit willst - const layers = []; - for (const p of pages) { - try { - const html = await fetchPageHTML(p.title); - const d = extractPlaceData(html); - if (!d) continue; - - // Leaflet: Bei CRS.Simple = [y, x] - const m = L.marker([d.y, d.x]).addTo(map); - const wikiLink = d.link || `https://wiki.arenos.danielnagel.at/index.php/${encodeURIComponent(p.title)}`; - const popup = ` - ${d.name || p.title}
- ${d.desc ? `${d.desc}
` : ''} - Open in Wiki - `; - m.bindPopup(popup); - layers.push(m); - - } catch (e) { - console.warn('skip page due to parse error:', p.title, e); - } +async function main() { + const response = await fetch(url, { + headers: { + "Authorization": `Bearer ${apiKey}` } - - } catch (e) { - console.error('Failed to load wiki markers:', e); - } + }); + const json = await response.json(); + console.log(json); } +main(); \ No newline at end of file From 69ce35e03e2b2fe89f716b8255ae41d8aba4f858 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 7 Sep 2025 12:51:50 +0000 Subject: [PATCH 2/4] markers data test --- markers.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/markers.js b/markers.js index ea5a3f4..caa07bf 100644 --- a/markers.js +++ b/markers.js @@ -1,14 +1,13 @@ -const url = "https://data.arenos.danielnagel.at/api/docs/rp78Zashtzfe7mgFSbeMkd"; -const apiKey = "77fc2fdb0b54a27e4da954a077a670e67f45b203"; - -async function main() { - const response = await fetch(url, { - headers: { - "Authorization": `Bearer ${apiKey}` - } - }); - const json = await response.json(); - console.log(json); +// markers.js +async function testGateway() { + try { + const res = await fetch("/api/places"); // Edge-Caddy proxyt zu data_gateway + const data = await res.json(); + console.log("Antwort vom Gateway:", data); + } catch (err) { + console.error("Fehler:", err); + } } -main(); \ No newline at end of file +// Direkt beim Laden einmal ausführen: +testGateway(); From 0716ca3d9f54912ecbd216d48b503749b2e0fc24 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 7 Sep 2025 12:53:28 +0000 Subject: [PATCH 3/4] test --- markers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/markers.js b/markers.js index caa07bf..d7199e6 100644 --- a/markers.js +++ b/markers.js @@ -1,6 +1,7 @@ // markers.js async function testGateway() { try { + console.log ("test test"); const res = await fetch("/api/places"); // Edge-Caddy proxyt zu data_gateway const data = await res.json(); console.log("Antwort vom Gateway:", data); From 8e936c3fb8ad90052ea2ac67572782b411645bad Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 7 Sep 2025 12:56:31 +0000 Subject: [PATCH 4/4] jlj --- markers.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/markers.js b/markers.js index d7199e6..33a8b26 100644 --- a/markers.js +++ b/markers.js @@ -1,14 +1,4 @@ -// markers.js -async function testGateway() { - try { - console.log ("test test"); - const res = await fetch("/api/places"); // Edge-Caddy proxyt zu data_gateway - const data = await res.json(); - console.log("Antwort vom Gateway:", data); - } catch (err) { - console.error("Fehler:", err); - } -} - -// Direkt beim Laden einmal ausführen: -testGateway(); +fetch('/api/places') + .then(r => r.json()) + .then(data => console.log('Gateway-Antwort:', data)) + .catch(err => console.error('Fehler:', err));