Modul:Geburtsort: Unterschied zwischen den Versionen
Die Seite wurde neu angelegt: „-- Modul:Geburtsort -- Verarbeitet ein Feld "Stadt, Land" zu: -- Anzeige: Stadt[, Land] (beides automatisch verlinkt, falls Seite existiert) -- Kategorien: [[Kategorie:Geboren in <Stadt>]] + [[Kategorie:Geboren in <Land (gebeugt)>]] -- Benutzung in Vorlage: {{#invoke:Geburtsort|render|value={{{Geburtsort|}}}}} local p = {} local trim = mw.text.trim local lc = mw.ustring.lower -- Helper: Link, wenn Seite existiert, sonst Plaintext local function linkI…“ |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
function p.render(frame) | function p.render(frame) | ||
local value = frame.args.value or frame:getParent() and frame:getParent().args.value | local value = frame.args.value or (frame:getParent() and frame:getParent().args.value) | ||
value = value and trim(value) or "" | value = value and trim(value) or "" | ||
if value == "" then | if value == "" then return "" end | ||
local linkMode = (frame.args.link or ""):lower() -- "page" (default) oder "category" | |||
-- Stadt/Land parsen | -- Stadt/Land parsen | ||
local city, countryRaw = splitCityCountry(value) | local city, countryRaw = splitCityCountry(value) | ||
-- Land normalisieren | |||
-- Land normalisieren | |||
local countryNorm = nil | local countryNorm = nil | ||
if countryRaw ~= "" then | if countryRaw ~= "" then | ||
countryNorm = countryNormalize[lc(countryRaw)] or countryRaw | countryNorm = countryNormalize[lc(countryRaw)] or countryRaw | ||
end | end | ||
local countryView = countryNorm and linkIfExists(countryNorm) or "" | |||
-- Anzeige-Links erzeugen | |||
local cityView, countryView | |||
if linkMode == "category" then | |||
-- Sichtbare Links direkt auf die Kategorien setzen (mit führendem :) | |||
cityView = city ~= "" and string.format("[[:Kategorie:Geboren in %s|%s]]", city, city) or "" | |||
if countryNorm and countryNorm ~= "" then | |||
local suffix = countryCatSuffix[countryNorm] or countryNorm | |||
countryView = string.format("[[:Kategorie:Geboren in %s|%s]]", suffix, countryNorm) | |||
else | |||
countryView = "" | |||
end | |||
else | |||
-- Standard: auf Artikelseiten verlinken (nur wenn existieren) | |||
cityView = linkIfExists(city) | |||
countryView = (countryNorm and linkIfExists(countryNorm)) or "" | |||
end | |||
-- Anzeige zusammensetzen | -- Anzeige zusammensetzen | ||
| Zeile 103: | Zeile 40: | ||
end | end | ||
-- Kategorien | -- Kategorien immer setzen (unsichtbar im Fließtext) | ||
if city ~= "" then | if city ~= "" then | ||
out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", city) | out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", city) | ||
end | end | ||
if countryNorm and countryNorm ~= "" then | if countryNorm and countryNorm ~= "" then | ||
local suffix = countryCatSuffix[countryNorm] or countryNorm | local suffix = countryCatSuffix[countryNorm] or countryNorm | ||
| Zeile 117: | Zeile 51: | ||
return table.concat(out) | return table.concat(out) | ||
end | end | ||