Docs: improve documentation with quick overview table of the most important questions

This commit is contained in:
Pieter Vander Vennet 2025-04-10 04:52:38 +02:00
parent 4078b33a87
commit aa5c309887
6 changed files with 78 additions and 20 deletions

View file

@ -376,6 +376,59 @@ export default class LayerConfig extends WithContextLoader {
return this.mapRendering.some((r) => r.location.has("point"))
}
/**
* A quick overview table of all the elements in the popup-box
* @private
*/
private generateDocumentationQuickTable(): string {
return MarkdownUtils.table(
["id", "question", "labels", "freeform key"],
this.tagRenderings
.filter(tr => tr.labels.indexOf("ignore_docs") < 0)
.map(tr => {
let key = "_Multiple choice only_"
if (tr.freeform) {
const type = `[${tr.freeform.type}](../SpecialInputElements.md#${tr.freeform.type})`
key = `*[${tr.freeform.key}](https://wiki.osm.org/wiki/Key:${tr.freeform.key})* (${type})`
}
let origDef = ""
if (tr._definedIn) {
let [layer, id] = tr._definedIn
if (layer == "questions") {
layer = "./BuiltinQuestions"
} else {
layer = "./" + layer
}
origDef = `<br/> _(Original in [${tr._definedIn[0]}](${layer}.md#${id}))_`
}
const q = tr.question?.Subs(this.baseTags)?.txt?.trim()
let r = tr.render?.txt
if (r && r !== "") {
r = `_${r}_`
}
let options: string = undefined
if (tr.mappings?.length > 0) {
options = `${tr.mappings.length} options`
}
return [
`[${tr.id}](#${tr.id}) ${origDef}`,
Utils.NoNull([q, r, options]).join("<br/>"),
tr.labels.join(", "),
key
]
})
)
}
public generateDocumentation(
usedInThemes: string[],
layerIsNeededBy?: Map<string, string[]>,
@ -530,8 +583,7 @@ export default class LayerConfig extends WithContextLoader {
let quickOverview: string[] = []
if (tableRows.length > 0) {
quickOverview = [
"**Warning:**",
"this quick overview is incomplete",
"**Warning:**: this quick overview is incomplete",
MarkdownUtils.table(
["attribute", "type", "values which are supported by this layer"],
tableRows
@ -603,7 +655,9 @@ export default class LayerConfig extends WithContextLoader {
...presets,
...tagsDescription,
"## Supported attributes",
quickOverview,
...quickOverview,
"## Featureview elements and TagRenderings",
this.generateDocumentationQuickTable(),
...this.tagRenderings
.filter((tr) => tr.labels.indexOf("ignore_docs") < 0)
.map((tr) => tr.GenerateDocumentation()),