forked from MapComplete/MapComplete
Add some hardening against non-generated layouts
This commit is contained in:
parent
5bb6a6bf63
commit
1853af06a0
3 changed files with 38 additions and 7 deletions
|
@ -9,12 +9,22 @@ echo "Starting build"
|
|||
# sanity check
|
||||
if [[ -f "bookcases.html" ]]
|
||||
then
|
||||
echo "Bookcases exists"
|
||||
echo "Bookcases theme exists"
|
||||
else
|
||||
echo "Bookcases.html does not exist - aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# sanity check
|
||||
if [[ -f "waste.html" ]]
|
||||
then
|
||||
echo "Waste theme exists"
|
||||
else
|
||||
echo "waste.html does not exist - aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export NODE_OPTIONS=--max-old-space-size=16000
|
||||
which vite
|
||||
vite --version
|
||||
|
|
|
@ -806,6 +806,9 @@ class LayerOverviewUtils extends Script {
|
|||
try {
|
||||
ScriptUtils.ReadSvgSync(themeFile.icon, (svg) => {
|
||||
const width: string = svg["$"].width
|
||||
if (width === undefined) {
|
||||
throw "The logo at " + themeFile.icon + " does not have a defined width"
|
||||
}
|
||||
const height: string = svg["$"].height
|
||||
const err = themeFile.hideFromOverview ? console.warn : console.error
|
||||
if (width !== height) {
|
||||
|
@ -815,6 +818,11 @@ class LayerOverviewUtils extends Script {
|
|||
err(e)
|
||||
}
|
||||
|
||||
|
||||
if (width?.endsWith("%")) {
|
||||
throw "The logo at " + themeFile.icon + " has a relative width; this is not supported"
|
||||
}
|
||||
|
||||
const w = parseInt(width)
|
||||
const h = parseInt(height)
|
||||
if (w < 370 || h < 370) {
|
||||
|
|
|
@ -89,8 +89,8 @@ class GenerateLayouts extends Script {
|
|||
|
||||
try {
|
||||
// We already read to file, in order to crash here if the file is not found
|
||||
let img = await sharp(iconPath)
|
||||
let resized = await img.resize(size)
|
||||
const img = await sharp(iconPath)
|
||||
const resized = await img.resize(size)
|
||||
await resized.toFile(targetpath)
|
||||
console.log("Created png version at ", newname)
|
||||
} catch (e) {
|
||||
|
@ -457,16 +457,29 @@ class GenerateLayouts extends Script {
|
|||
let ogImage = layout.socialImage
|
||||
let twitterImage = ogImage
|
||||
if (ogImage === LayoutConfig.defaultSocialImage && layout.official) {
|
||||
ogImage = (await this.createSocialImage(layout, "")) ?? layout.socialImage
|
||||
twitterImage = (await this.createSocialImage(layout, "Wide")) ?? layout.socialImage
|
||||
try{
|
||||
ogImage = (await this.createSocialImage(layout, "")) ?? layout.socialImage
|
||||
twitterImage = (await this.createSocialImage(layout, "Wide")) ?? layout.socialImage
|
||||
}catch (e) {
|
||||
console.error("Could not generate image:", e)
|
||||
}
|
||||
}
|
||||
if (twitterImage.endsWith(".svg")) {
|
||||
try{
|
||||
|
||||
// svgs are badly supported as social image, we use a generated svg instead
|
||||
twitterImage = await this.createIcon(twitterImage, 512, alreadyWritten)
|
||||
}catch (e) {
|
||||
console.error("Could not generate image:", e)
|
||||
}
|
||||
}
|
||||
|
||||
if (ogImage.endsWith(".svg")) {
|
||||
ogImage = await this.createIcon(ogImage, 512, alreadyWritten)
|
||||
try{
|
||||
ogImage = await this.createIcon(ogImage, 512, alreadyWritten)
|
||||
}catch (e) {
|
||||
console.error("Could not generate image:", e)
|
||||
}
|
||||
}
|
||||
|
||||
let customCss = ""
|
||||
|
@ -506,7 +519,7 @@ class GenerateLayouts extends Script {
|
|||
apple_icons.push(`<link rel="apple-touch-icon" sizes="${size}x${size}" href="${icon}">`)
|
||||
}
|
||||
|
||||
let themeSpecific = [
|
||||
const themeSpecific = [
|
||||
`<title>${ogTitle}</title>`,
|
||||
`<link rel="manifest" href="${this.enc(layout.id)}.webmanifest">`,
|
||||
og,
|
||||
|
|
Loading…
Reference in a new issue