Module:WeeklyEvent: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
Mcint (talk | contribs)
create module
 
Mcint (talk | contribs)
m update joiner, calling/docs
Line 11: Line 11:
end
end


-- args: prefix=Meeting  weekday=Tuesday  text_this, text_prev, text_next, preload
-- args: prefix=Meeting joiner=" " weekday=Tuesday  text_this, text_prev, text_next, preload
function p.links(frame)
function p.links(frame)
   local args = frame:getParent().args
   local args = frame:getParent().args
Line 25: Line 25:
   local nextdate = d('Y-m-d', 'next ' .. weekday)
   local nextdate = d('Y-m-d', 'next ' .. weekday)


   local thisTitle = prefix .. '/' .. thisdate
   local thisTitle = prefix .. args.joiner .. thisdate
   local prevTitle = prefix .. '/' .. prevdate
   local prevTitle = prefix .. args.joiner .. prevdate
   local nextTitle = prefix .. '/' .. nextdate
   local nextTitle = prefix .. args.joiner .. nextdate


   local latestTitle, latestText
   local latestTitle, latestText

Revision as of 15:43, 22 October 2025

docs

mw:Extension:Scribunto

mw:Module:Arguments

https://dev.fandom.com/wiki/Lua_reference_manual/Scribunto_libraries

https://en.wikipedia.org/wiki/Wikipedia:Comparable_Lua_functions_to_wikitext


local p = {}

local function d(fmt, rel)
  -- uses site content language date parser (Parsoid-safe)
  return mw.getContentLanguage():formatDate(fmt, rel)
end

local function page_exists(title)
  local t = mw.title.new(title)
  return t and t.exists
end

-- args: prefix=Meeting  joiner=" "  weekday=Tuesday  text_this, text_prev, text_next, preload
function p.links(frame)
  local args = frame:getParent().args
  local prefix  = args.prefix  or 'Meeting'
  local weekday = args.weekday or 'Tuesday'
  local text_this = args.text_this or 'This week'
  local text_prev = args.text_prev or 'Last week'
  local text_next = args.text_next or 'Next week'
  local preload   = args.preload   -- optional

  local thisdate = d('Y-m-d', 'this ' .. weekday)
  local prevdate = d('Y-m-d', 'last ' .. weekday)
  local nextdate = d('Y-m-d', 'next ' .. weekday)

  local thisTitle = prefix .. args.joiner .. thisdate
  local prevTitle = prefix .. args.joiner .. prevdate
  local nextTitle = prefix .. args.joiner .. nextdate

  local latestTitle, latestText
  if page_exists(thisTitle) then
    latestTitle, latestText = thisTitle, text_this
  elseif page_exists(prevTitle) then
    latestTitle, latestText = prevTitle, text_prev
  else
    latestTitle, latestText = nil, "no recent page"
  end

  local buf = {}

  if latestTitle then
    table.insert(buf, string.format('[[%s|%s]]', latestTitle, latestText))
  else
    table.insert(buf, "''no recent page''")
  end

  table.insert(buf, ' · ')
  table.insert(buf, string.format('[[%s|%s]]', nextTitle, text_next))

  if preload then
    local url = mw.uri.canonicalUrl(nextTitle, { action='edit', preload=preload })
    table.insert(buf, ' · ')
    table.insert(buf, string.format('[%s create next]', tostring(url)))
  end

  return table.concat(buf)
end

return p