forked from MapComplete/MapComplete
Attempt to fix social image previews
This commit is contained in:
parent
25f956c808
commit
5c71bfa294
18 changed files with 147 additions and 83 deletions
|
@ -898,18 +898,20 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
class SetDefault extends DesugaringStep<LayerConfigJson> {
|
||||
private readonly value: object;
|
||||
class SetDefault<T> extends DesugaringStep<T> {
|
||||
private readonly value: any;
|
||||
private readonly key: string;
|
||||
private readonly _overrideEmptyString: boolean;
|
||||
|
||||
constructor(key: string, value: object) {
|
||||
constructor(key: string, value: any, overrideEmptyString = false) {
|
||||
super("Sets " + key + " to a default value if undefined");
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this._overrideEmptyString = overrideEmptyString;
|
||||
}
|
||||
|
||||
convert(state: DesugaringContext, json: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
||||
if (json[this.key] === undefined) {
|
||||
convert(state: DesugaringContext, json: T, context: string): { result: T; errors: string[]; warnings: string[] } {
|
||||
if (json[this.key] === undefined || (json[this.key] === "" && this._overrideEmptyString)) {
|
||||
json = {...json}
|
||||
json[this.key] = this.value
|
||||
}
|
||||
|
@ -1044,6 +1046,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
|||
super(
|
||||
"Fully prepares and expands a theme",
|
||||
new OnEveryConcat("layers", new SubstituteLayer()),
|
||||
new SetDefault("socialImage", "assets/SocialImage.png", true),
|
||||
new AddDefaultLayers(),
|
||||
new AddDependencyLayersToTheme(),
|
||||
new OnEvery("layers", new PrepareLayer()),
|
||||
|
|
|
@ -102,6 +102,11 @@ export default class LayoutConfig {
|
|||
this.descriptionTail = json.descriptionTail === undefined ? undefined : new Translation(json.descriptionTail, context + ".descriptionTail");
|
||||
this.icon = json.icon;
|
||||
this.socialImage = json.socialImage;
|
||||
if(this.socialImage === null || this.socialImage === "" || this.socialImage === undefined){
|
||||
if(official){
|
||||
throw "Theme "+json.id+" has no social image defined"
|
||||
}
|
||||
}
|
||||
this.startZoom = json.startZoom;
|
||||
this.startLat = json.startLat;
|
||||
this.startLon = json.startLon;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue