Modul:NewsArtikel: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 146: Zeile 146:
  local sy, sm, sd = datum:match('^(%d%d%d%d)%-(%d%d)%-(%d%d)')
  local sy, sm, sd = datum:match('^(%d%d%d%d)%-(%d%d)%-(%d%d)')
  if sy then
  if sy then
    local smi = tonumber(sm)
    local smname = monate[tonumber(sm)] or sm
    local smname = monate[smi] or sm
    local sortKey = string.format('%s. %s %s', sd, smname, sy)
    local sortKey = string.format('%s. %s %s', sd, smname, sy)
    table.insert(out, '[[Kategorie:Archiv-News/' .. monat .. '|' .. sortKey .. ']]')
    table.insert(out, '[[Kategorie:Archiv-News/' .. monat .. '|' .. sortKey .. ']]')
Zeile 198: Zeile 197:


return table.concat(out, '\n')
return table.concat(out, '\n')
end
function p.archivListe(frame)
  local year  = trim(frame.args[1] or '')
  local month = trim(frame.args[2] or '')
  if year == '' or month == '' then return '' end
  local catName = 'Archiv-News/' .. year .. '-' .. month
  local dplResult = frame:callParserFunction('#dpl', {
    ['category']          = catName,
    ['format']            = ',\n%PAGE%,,',
    ['ordermethod']        = 'title',
    ['order']              = 'ascending',
    ['count']              = '200',
    ['suppresserrors']    = 'true',
    ['allowcachedresults'] = 'true',
  })
  local items = {}
  for page in dplResult:gmatch('[^\n]+') do
    page = page:match('^%s*(.-)%s*$')
    if page ~= '' then
      local titleObj = mw.title.new(page)
      if titleObj then
        local content = titleObj:getContent() or ''
        local datum  = content:match('|%s*datum%s*=%s*([%d%-]+)') or ''
        local dateStr = formatDatum(datum)
        local label  = titleObj.text
        local line
        if dateStr ~= '' then
          line = '* ' .. dateStr .. ': [[' .. page .. '|' .. label .. ']]'
        else
          line = '* [[' .. page .. '|' .. label .. ']]'
        end
        table.insert(items, {datum = datum, display = line})
      end
    end
  end
  table.sort(items, function(a, b) return a.datum < b.datum end)
  local lines = {}
  for _, item in ipairs(items) do table.insert(lines, item.display) end
  return table.concat(lines, '\n')
end
end


return p
return p