Documentation for this module may be created at Module:Header/doc
local p = {} -- p stands for package
local getArgs = require('Module:Arguments').getArgs
-- Function to generate the header HTML
local function generateHeader(args)
local header = mw.html.create('div')
:addClass('header-container') -- Add a class for CSS styling
-- Title
if args.title then
header:tag('div')
:addClass('header-title')
:tag('p')
:wikitext(args.title)
end
local content = header:tag('div')
:addClass('header-content') -- Container for image and text
-- Cover image
if args.cover then
content:tag('div')
:addClass('header-image')
:wikitext('[[File:' .. args.cover .. '|thumb|left]]')
end
local headerText = content:tag('div')
:addClass('header-text') -- Add a class for CSS styling
-- Author and translator
if args.author or args.translator then
local authorInfo = headerText:tag('p')
if args.author then
authorInfo:wikitext('Author: ' .. args.author)
end
if args.translator then
authorInfo:wikitext(' | Translator: ' .. args.translator)
end
end
-- Section
if args.section then
headerText:tag('p'):wikitext('Section: ' .. args.section)
end
-- Navigation (previous and next)
if args.previous or args.next then
local nav = headerText:tag('p')
if args.previous then
nav:tag('span'):wikitext('Previous: ' .. args.previous .. ' | ')
end
if args.next then
nav:tag('span'):wikitext('Next: ' .. args.next)
end
end
-- Notes
if args.notes then
headerText:tag('p'):wikitext('Notes: ' .. args.notes)
end
-- Year
if args.year then
headerText:tag('p'):wikitext('Year: ' .. args.year)
end
-- Add a clearing div to ensure content starts below the header
header:tag('div'):css('clear', 'both')
return tostring(header)
end
-- Function called by the template
function p.header(frame)
local args = getArgs(frame)
return generateHeader(args)
end
return p