mapcomplete/Customizations/Questions/WikipediaLink.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-07-31 17:38:03 +02:00
import {TagRenderingOptions} from "../TagRenderingOptions";
2020-07-05 18:59:47 +02:00
export class WikipediaLink extends TagRenderingOptions {
private static FixLink(value: string): string {
if (value === undefined) {
return undefined;
}
2020-07-05 18:59:47 +02:00
// @ts-ignore
if (value.startsWith("https")) {
return value;
} else {
const splitted = value.split(":");
const language = splitted[0];
splitted.shift();
const page = splitted.join(":");
return 'https://' + language + '.wikipedia.org/wiki/' + page;
}
}
static options = {
priority: 10,
// question: "Wat is het overeenstemmende wkipedia-artikel?",
tagsPreprocessor: (tags) => {
if (tags.wikipedia !== undefined) {
tags.wikipedia = WikipediaLink.FixLink(tags.wikipedia);
}
},
2020-07-05 18:59:47 +02:00
freeform: {
key: "wikipedia",
template: "$$$",
renderTemplate:
"<a href='{wikipedia}' target='_blank'>" +
2020-09-05 01:40:43 +02:00
"<img style='width: 24px;height: 24px;' src='./assets/wikipedia.svg' alt='wikipedia'>" +
2020-09-13 00:53:24 +02:00
"</a>",
2020-09-05 01:40:43 +02:00
placeholder: ""
2020-07-05 18:59:47 +02:00
},
}
constructor() {
super(WikipediaLink.options);
}
}