Module:Sandbox/Dat Hack3r: Difference between revisions

From Our World of Text Wiki
Jump to navigation Jump to search
(Realized you need to return the error.)
(Created a prototype of Module:Series navigation.)
Line 1: Line 1:
local p = {}
local p = {}


local horizontal = require('Module:List').horizontal
local mw_error = require('Module:Error').error
local mw_error = require('Module:Error').error


local first_date = os.time{year=2024, month=9, day=8}
function p._main(s_start, s_end, increment, title, title_format, text_format)
local curr_date = os.time()
title_format = title_format or string.gsub(title, '%d+', '%%d', 1)
local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)
text_format = text_format or '%d'
 
if title_format then
local function release(offset)
curr_num = string.match(title, string.gsub(title_format, "%%d", "(%%d+)"))
offset = offset or 0
else
 
curr_num = string.match(title, '%d+')
local release_num = math.floor(diff / 7) + offset
end
 
local end_date = os.date("*t", curr_date - (diff % 7) * 24 * 60 * 60)
end_date.day = end_date.day - (end_date.wday - 1) + offset * 7
 
local start_date = os.date("*t", os.time{year=end_date.year, month=end_date.month, day=end_date.day - 7})


return string.format("Weeskly Briefing Release %d %s - %s",
local navlist = {}
release_num,
for i=curr_num - 5,curr_num + 5 do
os.date("%b %d", os.time(start_date)):gsub(" 0", " "),
if i < s_start then
os.date("%b %d", os.time(end_date)):gsub(" 0", " ")
table.insert(navlist, '<span style="visibility: hidden;">'..i..'</span>')
)
else
end
if mw.title.new(string.format(title_format, i), "").exists then
 
table.insert(navlist, '[['..string.format(title_format, i)..'|'..string.format(text_format, i)..']]')
function p._main(link_text, offset)
else
if offset then
table.insert(navlist, '<span class="seriesNavigation-item-inactive">'..string.format(text_format, i)..'</span>')
return "[[" .. release(offset) .. "|" .. link_text .. "]]"
else
for i=1,-math.floor(diff / 7),-1 do
mw.log(release(i))
if mw.title.new(release(i), "").exists then
return "[[" .. release(i) .. "|" .. link_text .. "]]"
end
end
end
end
return mw_error{"No Releases found. Something has gone very, very wrong."}
end
end
templatestyles = mw.getCurrentFrame():extensionTag{
name = "templatestyles",
args = {src = 'Module:Series navigation/styles.css'}
}
return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..horizontal(navlist)..'</div>'
end
end


function p.main(frame)
function p.main(frame)
local link_text = frame:getParent().args[1] or "Weekly Site Information"
s_start      = frame:getParent().args['start'] or 1
local offset = tonumber(frame:getParent().args['offset'])
s_end        = frame:getParent().args['end']
return p._main(link_text, offset)
increment    = frame:getParent().args['increment'] or 1
title        = mw.title.getCurrentTitle()
title_format = frame:getParent().args['title_format']
text_format  = frame:getParent().args['text_format']
return p._main(s_start, s_end, increment, title, title_format, text_format)
end
end


return p
return p

Revision as of 16:07, 16 December 2024

Documentation for this module may be created at Module:Sandbox/Dat Hack3r/doc

local p = {}

local horizontal = require('Module:List').horizontal
local mw_error = require('Module:Error').error

function p._main(s_start, s_end, increment, title, title_format, text_format)
	title_format = title_format or string.gsub(title, '%d+', '%%d', 1)
	text_format = text_format or '%d'
	if title_format then
		curr_num = string.match(title, string.gsub(title_format, "%%d", "(%%d+)"))
	else
		curr_num = string.match(title, '%d+')
	end

	local navlist = {}
	for i=curr_num - 5,curr_num + 5 do
		if i < s_start then
			table.insert(navlist, '<span style="visibility: hidden;">'..i..'</span>')
		else
			if mw.title.new(string.format(title_format, i), "").exists then
				table.insert(navlist, '[['..string.format(title_format, i)..'|'..string.format(text_format, i)..']]')
			else
				table.insert(navlist, '<span class="seriesNavigation-item-inactive">'..string.format(text_format, i)..'</span>')
			end
		end
	end

	templatestyles = mw.getCurrentFrame():extensionTag{
		name = "templatestyles",
		args = {src = 'Module:Series navigation/styles.css'}
	}
	return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..horizontal(navlist)..'</div>'
end

function p.main(frame)
	s_start      = frame:getParent().args['start'] or 1
	s_end        = frame:getParent().args['end']
	increment    = frame:getParent().args['increment'] or 1
	title        = mw.title.getCurrentTitle()
	title_format = frame:getParent().args['title_format']
	text_format  = frame:getParent().args['text_format']
	return p._main(s_start, s_end, increment, title, title_format, text_format)
end

return p