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