Module:WeeklyEvent: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
Mcint (talk | contribs)
complete this / next transition
Mcint (talk | contribs)
remove next & s/this/next/
 
(One intermediate revision by the same user not shown)
Line 15: Line 15:
   local joiner  = args.joiner  or ' '
   local joiner  = args.joiner  or ' '
   local weekday  = args.weekday  or 'Tuesday'
   local weekday  = args.weekday  or 'Tuesday'
   local t_this   = args.text_this or 'Next week' -- 'This week'
   local t_next   = args.text_next or 'Next week' -- 'This week'
   local t_prev  = args.text_prev or 'Last week'
   local t_prev  = args.text_prev or 'Last week'
  -- local t_next  = args.text_next or 'Next week'
   local preload  = args.preload
   local preload  = args.preload


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


   local thisTitle = table.concat({prefix, thisdate}, joiner)
   local nextTitle = table.concat({prefix, nextdate}, joiner)
   local prevTitle = table.concat({prefix, prevdate}, joiner)
   local prevTitle = table.concat({prefix, prevdate}, joiner)
  -- local nextTitle = table.concat({prefix, nextdate}, joiner)


   local latestTitle, latestText
   local latestTitle, latestText
   --if exists(thisTitle) then
   --if exists(thisTitle) then
   --  latestTitle, latestText = thisTitle, t_this
   --  latestTitle, latestText = thisTitle, t_next
   -- elseif
   -- elseif
   if exists(prevTitle) then
   if exists(prevTitle) then
Line 45: Line 42:
   end
   end


  -- out = out .. ' · ' ..
  --      string.format('[[%s|%s]]', nextTitle, t_next)
   out = out .. ' · ' ..
   out = out .. ' · ' ..
         string.format('[[%s|%s]]', thisTitle, t_next)
         string.format('[[%s|%s]]', nextTitle, t_next)


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

Latest revision as of 18:40, 23 February 2026

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)
  return mw.getContentLanguage():formatDate(fmt, rel)
end

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

function p.links(frame)
  local args = frame:getParent().args
  local prefix   = args.prefix   or 'Meeting Notes'
  local joiner   = args.joiner   or ' '
  local weekday  = args.weekday  or 'Tuesday'
  local t_next   = args.text_next or 'Next week' -- 'This week'
  local t_prev   = args.text_prev or 'Last week'
  local preload  = args.preload

  local nextdate = d('Y m d', 'this ' .. weekday) -- 'this ' arg expected & needed
  local prevdate = d('Y m d', 'last ' .. weekday)

  local nextTitle = table.concat({prefix, nextdate}, joiner)
  local prevTitle = table.concat({prefix, prevdate}, joiner)

  local latestTitle, latestText
  --if exists(thisTitle) then
  --  latestTitle, latestText = thisTitle, t_next
  -- elseif
  if exists(prevTitle) then
    latestTitle, latestText = prevTitle, t_prev
  end

  -- build inline wikitext
  local out = ''

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

  out = out .. ' · ' ..
        string.format('[[%s|%s]]', nextTitle, t_next)

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

  --[[
  return frame:preprocess(out)
  ]]
  -- no leading/trailing whitespace

  out = mw.text.trim(out)

  -- force inline rendering; content is parsed as wikitext inside a <span>
  return frame:extensionTag{
    name = 'span',
    content = out,
    args = { class = 'weekly-event-inline' } -- optional
  }
end

return p