Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22e1a327a0c227c

Jump to content

Module:Graphic novel list

Permanently protected module
From Wikipedia, the free encyclopedia

local p = {}

local getArgs = require('Module:Arguments').getArgs

local function notBlank(v)
	return (v or '') ~= ''
end

local function firstNotBlank(...)
	for i = 1, select('#', ...) do
		local v = select(i, ...)
		if notBlank(v) then
			return v
		end
	end
end

local function eq(a, b)
	return notBlank(a) and a == b
end

local function isbn(frame, code)
	return frame:expandTemplate{
		title = 'ISBNT',
		args = { code }
	}
end

function p._header(args)
	local out = setmetatable({}, {
		__call = function(t, s) table.insert(t, s) end
	})

	local width = firstNotBlank(args.Width, args.width)
	out('{|class="wikitable" style="width:' .. firstNotBlank(width, '100%') .. ';')
	if not notBlank(width) then
		out('margin:auto;')
	end
	if not (notBlank(width) or notBlank(args.Clear)) then
		out('clear:both;')
	end
	out('"')

	if notBlank(args.Caption) then
		out('|+ ' .. args.Caption)
	end

	out('|-style="border-bottom:3px solid #' .. (args.LineColor or 'CCF') .. '"')
	out('!width=4%|<abbr title="Number">No.</abbr>')

	local withTitle = args.WithTitle == 'yes'
	if withTitle then
		out('!width=48%|Title')
	end
	if args.OneLanguage == 'yes' then
		out('!width=' .. (withTitle and 24 or 48) .. '%|' .. (notBlank(args.Language) and (args.Language .. ' r') or 'R') .. 'elease date')
		out('!width=' .. (withTitle and 24 or 48) .. '%|' .. (args.Language or '') .. ' ISBN')
	else -- two languages
		out('!width=24%|Original release date')

		if not withTitle then
			out('!width=24%|Original ISBN')
		end

		out('!width=24%|' .. firstNotBlank(args.SecondLanguage, 'English') .. ' release date')

		if not withTitle then
			out('!width=24%|' .. firstNotBlank(args.SecondLanguage, 'English') .. ' ISBN')
		end
	end

	if notBlank(args[1]) or notBlank(args.episodes) then
		out('<nowiki />')
		out(args[1] or '')
		out(args.episodes or '')
	end

	return table.concat(out, '|}\n')
end
function p.header(frame)
	return p._header(getArgs(frame))
end

function p._row(args, frame)
	if frame == nil then
		frame = mw.getCurrentFrame()
	end
	
	local out = setmetatable({}, {
		__call = function(t, s) table.insert(t, s) end
	})

	out('<tr style="text-align:center;">')
	out(
		string.format(
			'<th scope="row" id="%svol%s" style="text-align:center;font-weight:normal;background-color:transparent;color:var(--color-base);">%s</th>',
			args.Series or '',
			args.VolumeNumber or '',
			args.VolumeNumber or ''
		)
	)

	-- Title --
	local hasTitle =
		notBlank(args.LicensedTitle)
		or notBlank(args.TranslitTitle)
		or notBlank(args.OriginalTitle)
		or notBlank(args.Title)
	
	if hasTitle then
		out('<td style="text-align:left;">')
		if notBlank(args.LicensedTitle) or notBlank(args.Title) then
			out('<i>' .. (firstNotBlank(args.LicensedTitle, args.Title) or '') .. '</i>')
			if notBlank(args.TranslitTitle) or notBlank(args.OriginalTitle) then
				out('<br/>')
			end
		end

		if notBlank(args.TranslitTitle) then
			out('<i>' .. args.TranslitTitle .. '</i>')
			if notBlank(args.OriginalTitle) then
				out(' (' .. args.OriginalTitle .. ')')
			end
		elseif notBlank(args.OriginalTitle) then
			out(args.OriginalTitle)
		end

		out('</td>')
	else
		out('<td>')
		out(firstNotBlank(args.OriginalRelDate, args.RelDate) or '&mdash;')
		out('</td>')
	end

	-- Release/ISBN slot 1 --
	local relDate = firstNotBlank(args.OriginalRelDate, args.RelDate)
	local ISBNcode = firstNotBlank(args.OriginalISBN, args.ISBN)
	local hasLicensed =	notBlank(args.LicensedRelDate) or notBlank(args.LicensedISBN)
	local function renderISBN(code, note, alt)
		return notBlank(code) and (isbn(frame, code) .. (notBlank(note) and (' ' .. note) or '')) or (alt or '&mdash;')
	end
	
	out('<td>')	
	if hasTitle then
		if notBlank(relDate) or notBlank(ISBNcode) then
			if eq(relDate, ISBNcode) then
				out(relDate)
			else
				if notBlank(relDate) then
					out(relDate)
					if hasLicensed and notBlank(ISBNcode) then
						out('<br/>')
					end
				end
	
				if hasLicensed then
					out(renderISBN(ISBNcode, args.ISBN_note, ''))
				elseif not notBlank(relDate) then
					out('&mdash;')
				end
			end
		else
			out('&mdash;')
		end
	else
		out(renderISBN(ISBNcode, args.ISBN_note))
	end
	out('</td>')

	-- Release/ISBN slot 2 --
	if hasTitle then
		out('<td>')
		if hasLicensed then
			if eq(args.LicensedRelDate, args.LicensedISBN) then
				out(args.LicensedRelDate)
			else
				if notBlank(args.LicensedRelDate) then
					out(args.LicensedRelDate)
					if notBlank(args.LicensedISBN) then
						out('<br/>')
					end
				end
				out(renderISBN(args.LicensedISBN, args.LicensedISBN_note, ''))
			end
		else
			out(renderISBN(firstNotBlank(args.OriginalISBN, args.ISBN), args.ISBN_note))
		end
		out('</td>')
	elseif hasLicensed then
		out('<td>' .. firstNotBlank(args.LicensedRelDate, '&mdash;') .. '</td>')
		out('<td>' .. renderISBN(args.LicensedISBN, args.LicensedISBN_note) .. '</td>')
	end
	
	out('</tr>')

	-- chapter list/summary --
	if args.SublistOf ~= mw.title.getCurrentTitle().text then
		local colspan =
			hasTitle and 4
			or hasLicensed and 5
			or 3

		if notBlank(args.ChapterListCol1) or notBlank(args.ChapterList) then
			out(
				string.format(
					'<tr style="vertical-align:top;%s"><td colspan="%d"><table border="0" cellspacing="0" cellpadding="0" style="width:100%%;background-color:transparent;color:var(--color-base);table-layout:fixed;text-align:left;"><tr style="vertical-align:top;"><caption>%s</caption><td style="border:black;">\n',
					notBlank(args.Summary) and '' or 'border-bottom:3px solid #' .. (args.LineColor or 'CCF') .. ';',
					colspan,
					args.Caption or ''
				)
			)

			out(firstNotBlank(args.ChapterListCol1, args.ChapterList) or '')

			if notBlank(args.ChapterListCol2) then
				out('</td>\n<td style="border:black;width:48%;">\n' .. args.ChapterListCol2)
			end

			out('</td></tr></table>\n</td></tr>')
		end

		if notBlank(args.Summary) then
			out(
				string.format(
					'<tr style="border-bottom:3px solid #%s;text-align:left;"><td colspan="%d">%s</td></tr>',
					args.LineColor or 'CCF',
					colspan,
					args.Summary
				)
			)
		end
	end

	return table.concat(out)
end
function p.row(frame)
	return p._row(getArgs(frame), frame)
end

function p.footer()
	return '</table>'
end

return p