Attempt to fix protomaps

This commit is contained in:
Pieter Vander Vennet 2024-03-21 16:32:18 +01:00
parent 9ebf820c61
commit 1e16b9131a
2 changed files with 30 additions and 24 deletions

View file

@ -104,9 +104,9 @@ class GenerateLayouts extends Script {
if (!layout.icon.endsWith(".svg")) { if (!layout.icon.endsWith(".svg")) {
console.warn( console.warn(
"Not creating a social image for " + "Not creating a social image for " +
layout.id + layout.id +
" as it is _not_ a .svg: " + " as it is _not_ a .svg: " +
layout.icon layout.icon
) )
return undefined return undefined
} }
@ -139,9 +139,9 @@ class GenerateLayouts extends Script {
id: "icon", id: "icon",
transform: `translate(${cx - r},${cy - r}) scale(${ transform: `translate(${cx - r},${cy - r}) scale(${
(r * 2) / Number(width) (r * 2) / Number(width)
}) `, }) `
}, },
g: [svg], g: [svg]
} }
}, },
(mightBeTokenToReplace) => { (mightBeTokenToReplace) => {
@ -202,19 +202,19 @@ class GenerateLayouts extends Script {
icons.push({ icons.push({
src: name, src: name,
sizes: size + "x" + size, sizes: size + "x" + size,
type: "image/png", type: "image/png"
}) })
} }
icons.push({ icons.push({
src: path, src: path,
sizes: "513x513", sizes: "513x513",
type: "image/svg", type: "image/svg"
}) })
} else if (icon.endsWith(".png")) { } else if (icon.endsWith(".png")) {
icons.push({ icons.push({
src: icon, src: icon,
sizes: "513x513", sizes: "513x513",
type: "image/png", type: "image/png"
}) })
} else { } else {
console.log(icon) console.log(icon)
@ -233,11 +233,11 @@ class GenerateLayouts extends Script {
description: ogDescr, description: ogDescr,
orientation: "portrait-primary, landscape-primary", orientation: "portrait-primary, landscape-primary",
icons: icons, icons: icons,
categories: ["map", "navigation"], categories: ["map", "navigation"]
} }
return { return {
manifest, manifest,
whiteIcons, whiteIcons
} }
} }
@ -261,7 +261,7 @@ class GenerateLayouts extends Script {
const rasterLayers = [ const rasterLayers = [
AvailableRasterLayers.maptilerDefaultLayer, AvailableRasterLayers.maptilerDefaultLayer,
...eli.features, ...eli.features,
...eli_global.layers.map((properties) => ({ properties })), ...eli_global.layers.map((properties) => ({ properties }))
] ]
for (const feature of rasterLayers) { for (const feature of rasterLayers) {
const f = <RasterLayerPolygon>feature const f = <RasterLayerPolygon>feature
@ -278,12 +278,13 @@ class GenerateLayouts extends Script {
if (f.properties.type === "vector") { if (f.properties.type === "vector") {
// We also need to whitelist eventual sources // We also need to whitelist eventual sources
let url = f.properties.url let url = f.properties.url
if(url.startsWith("pmtiles://")){ if (url.startsWith("pmtiles://")) {
url = url.substring("pmtiles://".length) url = url.substring("pmtiles://".length)
} }
const styleSpec = await Utils.downloadJsonCached(url, 1000 * 120, { const styleSpec = await Utils.downloadJsonCached(url, 1000 * 120, {
Origin: "https://mapcomplete.org" Origin: "https://mapcomplete.org"
}) })
urls.push(...(f.properties["connect-src"]??[]))
for (const key of Object.keys(styleSpec?.sources ?? {})) { for (const key of Object.keys(styleSpec?.sources ?? {})) {
const url = styleSpec.sources[key].url const url = styleSpec.sources[key].url
if (!url) { if (!url) {
@ -325,7 +326,7 @@ class GenerateLayouts extends Script {
"https://www.openstreetmap.org", "https://www.openstreetmap.org",
"https://api.openstreetmap.org", "https://api.openstreetmap.org",
"https://pietervdvn.goatcounter.com", "https://pietervdvn.goatcounter.com",
"https://cache.mapcomplete.org", "https://cache.mapcomplete.org"
].concat(...(await this.eliUrls())) ].concat(...(await this.eliUrls()))
SpecialVisualizations.specialVisualizations.forEach((sv) => { SpecialVisualizations.specialVisualizations.forEach((sv) => {
@ -367,7 +368,7 @@ class GenerateLayouts extends Script {
const vectorSources = vectorLayers.map((l) => l.properties.url) const vectorSources = vectorLayers.map((l) => l.properties.url)
vectorSources.push(...vectorLayers.map((l) => l.properties.style)) vectorSources.push(...vectorLayers.map((l) => l.properties.style))
apiUrls.push(...vectorSources.map(url => { apiUrls.push(...vectorSources.map(url => {
if(url?.startsWith("pmtiles://")){ if (url?.startsWith("pmtiles://")) {
return url.substring("pmtiles://".length) return url.substring("pmtiles://".length)
} }
return url return url
@ -416,8 +417,8 @@ class GenerateLayouts extends Script {
"script-src": [ "script-src": [
"'self'", "'self'",
"https://gc.zgo.at/count.js", "https://gc.zgo.at/count.js",
...(options?.scriptSrcs?.map((s) => "'" + s + "'") ?? []), ...(options?.scriptSrcs?.map((s) => "'" + s + "'") ?? [])
].join(" "), ].join(" ")
} }
const content = Object.keys(csp) const content = Object.keys(csp)
.map((k) => k + " " + csp[k]) .map((k) => k + " " + csp[k])
@ -425,7 +426,7 @@ class GenerateLayouts extends Script {
return [ return [
`<meta http-equiv ="Report-To" content='{"group":"csp-endpoint", "max_age": 86400,"endpoints": [\{"url": "https://report.mapcomplete.org/csp"}], "include_subdomains": true}'>`, `<meta http-equiv ="Report-To" content='{"group":"csp-endpoint", "max_age": 86400,"endpoints": [\{"url": "https://report.mapcomplete.org/csp"}], "include_subdomains": true}'>`,
`<meta http-equiv="Content-Security-Policy" content="${content}">`, `<meta http-equiv="Content-Security-Policy" content="${content}">`
].join("\n") ].join("\n")
} }
@ -437,12 +438,12 @@ class GenerateLayouts extends Script {
) { ) {
Locale.language.setData(layout.language[0]) Locale.language.setData(layout.language[0])
const targetLanguage = layout.language[0] const targetLanguage = layout.language[0]
const ogTitle = Translations.T(layout.title).textFor(targetLanguage).replace(/"/g, '\\"') const ogTitle = Translations.T(layout.title).textFor(targetLanguage).replace(/"/g, "\\\"")
const ogDescr = Translations.T( const ogDescr = Translations.T(
layout.shortDescription ?? "Easily add and edit geodata with OpenStreetMap" layout.shortDescription ?? "Easily add and edit geodata with OpenStreetMap"
) )
.textFor(targetLanguage) .textFor(targetLanguage)
.replace(/"/g, '\\"') .replace(/"/g, "\\\"")
let ogImage = layout.socialImage let ogImage = layout.socialImage
let twitterImage = ogImage let twitterImage = ogImage
if (ogImage === LayoutConfig.defaultSocialImage && layout.official) { if (ogImage === LayoutConfig.defaultSocialImage && layout.official) {
@ -501,7 +502,7 @@ class GenerateLayouts extends Script {
og, og,
customCss, customCss,
`<link rel="icon" href="${icon}" sizes="any" type="image/svg+xml">`, `<link rel="icon" href="${icon}" sizes="any" type="image/svg+xml">`,
...apple_icons, ...apple_icons
].join("\n") ].join("\n")
let branchname = await this.getBranchName() let branchname = await this.getBranchName()
@ -524,7 +525,7 @@ class GenerateLayouts extends Script {
.replace( .replace(
/<!-- CSP -->/, /<!-- CSP -->/,
await this.generateCsp(layout, layoutJson, { await this.generateCsp(layout, layoutJson, {
scriptSrcs: [this.removeOtherLanguagesHash], scriptSrcs: [this.removeOtherLanguagesHash]
}) })
) )
.replace( .replace(
@ -555,7 +556,7 @@ class GenerateLayouts extends Script {
const imports = [ const imports = [
`import layout from "./src/assets/generated/themes/${theme.id}.json"`, `import layout from "./src/assets/generated/themes/${theme.id}.json"`,
`import { ThemeMetaTagging } from "./src/assets/generated/metatagging/${theme.id}"`, `import { ThemeMetaTagging } from "./src/assets/generated/metatagging/${theme.id}"`
] ]
for (const layerName of Constants.added_by_default) { for (const layerName of Constants.added_by_default) {
imports.push( imports.push(
@ -602,7 +603,7 @@ class GenerateLayouts extends Script {
"account", "account",
"openstreetmap", "openstreetmap",
"custom", "custom",
"theme", "theme"
] ]
// @ts-ignore // @ts-ignore
const all: LayoutConfigJson[] = all_known_layouts.themes const all: LayoutConfigJson[] = all_known_layouts.themes
@ -654,7 +655,7 @@ class GenerateLayouts extends Script {
startLon: 0, startLon: 0,
startZoom: 0, startZoom: 0,
title: { en: "MapComplete" }, title: { en: "MapComplete" },
description: { en: "A thematic map viewer and editor based on OpenStreetMap" }, description: { en: "A thematic map viewer and editor based on OpenStreetMap" }
}), }),
alreadyWritten alreadyWritten
) )

View file

@ -179,6 +179,7 @@
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/white.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/white.json?key=2af8b969a9e8b692",
"connect-src": ["https://protomaps.github.io"],
"id": "protomaps.white", "id": "protomaps.white",
"name": "Protomaps White", "name": "Protomaps White",
"type": "vector", "type": "vector",
@ -191,6 +192,7 @@
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/light.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/light.json?key=2af8b969a9e8b692",
"connect-src": ["https://protomaps.github.io"],
"id": "protomaps.light", "id": "protomaps.light",
"name": "Protomaps Light", "name": "Protomaps Light",
"type": "vector", "type": "vector",
@ -202,6 +204,7 @@
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"connect-src": ["https://protomaps.github.io"],
"style": "https://api.protomaps.com/styles/v2/grayscale.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/grayscale.json?key=2af8b969a9e8b692",
"id": "protomaps.grayscale", "id": "protomaps.grayscale",
"name": "Protomaps Grayscale", "name": "Protomaps Grayscale",
@ -214,6 +217,7 @@
}, },
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"connect-src": ["https://protomaps.github.io"],
"style": "https://api.protomaps.com/styles/v2/dark.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/dark.json?key=2af8b969a9e8b692",
"id": "protomaps.dark", "id": "protomaps.dark",
"name": "Protomaps Dark", "name": "Protomaps Dark",
@ -227,6 +231,7 @@
{ {
"url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692", "url": "pmtiles://https://api.protomaps.com/tiles/v3.json?key=2af8b969a9e8b692",
"style": "https://api.protomaps.com/styles/v2/black.json?key=2af8b969a9e8b692", "style": "https://api.protomaps.com/styles/v2/black.json?key=2af8b969a9e8b692",
"connect-src": ["https://protomaps.github.io"],
"id": "protomaps.black", "id": "protomaps.black",
"name": "Protomaps Black", "name": "Protomaps Black",
"type": "vector", "type": "vector",