This wiki has been automatically closed because there have been no edits or log actions made within the last 60 days. If you are a user (who is not the bureaucrat) that wishes for this wiki to be reopened, please request that at Requests for reopening wikis. If this wiki is not reopened within 6 months it may be deleted. Note: If you are a bureaucrat on this wiki, you can go to Special:ManageWiki and uncheck the "Closed" box to reopen it.

Module:Series

From RoAPI

Documentation for this module may be created at Module:Series/doc

local p = {}

-- Returns the index of a given value in a table, if it exists
function getPosInTable(tbl, val)
	for i,v in ipairs(tbl) do
		if v == val then
			return i
		end
	end
	return nil
end

-- Returns a page footer in wikitext with links to the previous and next pages in the series, if they exist
function p.main(frame)
	local args = frame.args

	local series_name = args.title
	local title = mw.title.getCurrentTitle().fullText

	local curPos = getPosInTable(args, title)
	local prev = curPos and args[curPos - 1]
	local next = curPos and args[curPos + 1]

	local html = ""

	html = html .. "<div class=\"article-series\" data-nosnippet>"
	html = html .. "<div class=\"series-header\">"
	html = html .. "This article is a part of " .. (series_name and "the " .. series_name or "a") .. " series."
	html = html .. "</div>"
	html = html .. "<div class=\"series-list\">"
	html = html .. (prev and "[[" .. prev .. "|< " .. prev .. "]] | " or "") .. "'''" .. title .. "'''" .. (next and " | [[" .. next .. "|" .. next .. " >]]" or "")
	html = html .. "</div>"
	html = html .. "</div>"

	return html
end

return p