mapcomplete/Customizations/Questions/WikipediaLink.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-07-31 15:38:03 +00:00
import {TagRenderingOptions} from "../TagRenderingOptions";
2020-07-05 16:59:47 +00:00
export class WikipediaLink extends TagRenderingOptions {
private static FixLink(value: string): string {
if (value === undefined) {
return undefined;
}
2020-07-05 16:59:47 +00: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 16:59:47 +00:00
freeform: {
key: "wikipedia",
template: "$$$",
renderTemplate:
"<a href='{wikipedia}' target='_blank'>" +
2020-09-04 23:40:43 +00:00
"<img style='width: 24px;height: 24px;' src='./assets/wikipedia.svg' alt='wikipedia'>" +
2020-09-12 22:53:24 +00:00
"</a>",
2020-09-04 23:40:43 +00:00
placeholder: ""
2020-07-05 16:59:47 +00:00
},
}
constructor() {
super(WikipediaLink.options);
}
}