Module:Soldier: Difference between revisions
Do not link or categorize bogus IPW labels |
Join date-only research notes and collapse duplicates |
||
| Line 571: | Line 571: | ||
s = mw.ustring.gsub(s, '%s+', ' ') | s = mw.ustring.gsub(s, '%s+', ' ') | ||
return trim(s) | return trim(s) | ||
end | |||
local function dateOnlyFragment(s) | |||
return mw.ustring.match(trim(s), '^(%d%d?/%d%d?/%d%d%d?%d?)%.?$') | |||
end | |||
local function joinDateFollowons(items) | |||
local out = {} | |||
for _, clause in ipairs(items) do | |||
local date = dateOnlyFragment(clause) | |||
if date and #out > 0 then | |||
local prev = mw.ustring.gsub(out[#out], '[ ,;]+$', '') | |||
if mw.ustring.sub(prev, -mw.ustring.len(date)) ~= date then | |||
out[#out] = prev .. ', ' .. date | |||
end | |||
elseif clause ~= '' then | |||
table.insert(out, clause) | |||
end | |||
end | |||
return out | |||
end | end | ||
| Line 760: | Line 780: | ||
:addClass('infobox-header') | :addClass('infobox-header') | ||
:wikitext(text) | :wikitext(text) | ||
end | |||
local function realCertificate(s) | |||
s = trim(s) | |||
if s == '' then | |||
return '' | |||
end | |||
-- Placeholders: *, A, 5, #, and any other single character. | |||
if mw.ustring.len(s) == 1 then | |||
return '' | |||
end | |||
return s | |||
end | end | ||
| Line 1,116: | Line 1,148: | ||
addRow(tbl, 'Arrived', parentArg(frame, 'date_arrive')) | addRow(tbl, 'Arrived', parentArg(frame, 'date_arrive')) | ||
addRow(tbl, 'Departed', parentArg(frame, 'date_depart')) | addRow(tbl, 'Departed', parentArg(frame, 'date_depart')) | ||
addRow(tbl, 'Certificate', parentArg(frame, 'certificate')) | addRow(tbl, 'Certificate', realCertificate(parentArg(frame, 'certificate'))) | ||
return tostring(tbl) | return tostring(tbl) | ||
| Line 1,265: | Line 1,297: | ||
end | end | ||
local items = {} | local items = {} | ||
for line in mw.text.gsplit(section, '\n', true) do | for line in mw.text.gsplit(section, '\n', true) do | ||
line = trim(line) | line = trim(line) | ||
| Line 1,274: | Line 1,305: | ||
clause = trim(clause) | clause = trim(clause) | ||
if clause ~= '' and not isNegativeClause(clause) then | if clause ~= '' and not isNegativeClause(clause) then | ||
table.insert(items, prettyProse(clause)) | |||
end | end | ||
end | end | ||
| Line 1,284: | Line 1,311: | ||
end | end | ||
end | end | ||
items = joinDateFollowons(items) | |||
local unique = {} | |||
local seen = {} | |||
for _, clause in ipairs(items) do | |||
local key = normalizeNoteKey(clause) | |||
if key ~= '' and not seen[key] then | |||
seen[key] = true | |||
table.insert(unique, clause) | |||
end | |||
end | |||
items = unique | |||
if #items == 0 then | if #items == 0 then | ||
return '' | return '' | ||