mapcomplete/scripts/generateWikiPage.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-03-16 14:14:59 +01:00
import { writeFile } from "fs"
import Translations from "../UI/i18n/Translations"
2021-12-21 18:35:31 +01:00
import * as themeOverview from "../assets/generated/theme_overview.json"
2021-03-16 14:14:59 +01:00
2022-01-26 21:40:38 +01:00
function generateWikiEntry(layout: {
hideFromOverview: boolean
id: string
shortDescription: any
}) {
2021-03-16 14:14:59 +01:00
if (layout.hideFromOverview) {
return ""
}
2022-01-26 21:40:38 +01:00
2021-12-21 18:35:31 +01:00
const languagesInDescr = []
for (const shortDescriptionKey in layout.shortDescription) {
languagesInDescr.push(shortDescriptionKey)
2021-03-16 14:14:59 +01:00
}
2022-01-26 21:40:38 +01:00
const languages = languagesInDescr.map((ln) => `{{#language:${ln}|en}}`).join(", ")
2021-12-21 18:35:31 +01:00
let auth = "Yes"
2021-03-16 14:14:59 +01:00
return `{{service_item
|name= [https://mapcomplete.osm.be/${layout.id} ${layout.id}]
|region= Worldwide
|lang= ${languages}
|descr= A MapComplete theme: ${Translations.T(layout.shortDescription)
2021-09-28 22:33:09 +02:00
.textFor("en")
2021-03-16 14:14:59 +01:00
.replace("<a href='", "[[")
.replace(/'>.*<\/a>/, "]]")}
|material= {{yes|[https://mapcomplete.osm.be/ ${auth}]}}
|image= MapComplete_Screenshot.png
|genre= POI, editor, ${layout.id}
}}`
}
2021-03-16 14:14:59 +01:00
let wikiPage =
'{|class="wikitable sortable"\n' +
"! Name, link !! Genre !! Covered region !! Language !! Description !! Free materials !! Image\n" +
"|-"
2021-12-21 18:35:31 +01:00
for (const layout of themeOverview) {
if (layout.hideFromOverview) {
2021-03-16 14:14:59 +01:00
continue
}
wikiPage += "\n" + generateWikiEntry(layout)
}
wikiPage += "\n|}"
writeFile("Docs/wikiIndex.txt", wikiPage, (err) => {
if (err !== null) {
console.log("Could not save wikiindex", err)
}
})