Module:Citation/CS1
Documentation for this module may be created at Module:Citation/CS1/doc
local p = {}
-- Helper function to gather arguments
local function get_args(frame)
local args = {}
for k, v in pairs(frame:getParent().args) do
if v ~= "" then args[k] = v end
end
return args
end
function p.citation(frame)
local args = get_args(frame)
-- 1. AUTHOR LOGIC
local last = args.last or args.last1 or args.author or args.author1 or ""
local first = args.first or args.first1 or ""
local author_link = args['author-link'] or args['authorlink'] or args['author-link1']
local author_str = ""
if last ~= "" then
author_str = last .. (first ~= "" and (", " .. first) or "")
if author_link then
author_str = "[[" .. author_link .. "|" .. author_str .. "]]"
end
author_str = author_str .. ". "
end
-- 2. TITLE & URL
local title = args.title or "No Title"
local url = args.url or args.URL
local title_str = "''" .. title .. "''"
if url then
title_str = "[" .. url .. " " .. title_str .. "]"
end
-- 3. METADATA
local journal = args.journal or args.work or args.periodical or args.website
local series = args.series
local year = args.year or args.date or ""
local location = args.location or args.place or ""
local publisher = args.publisher or args.institution or ""
local vol = args.volume
local issue = args.issue or args.number
local pages = args.pages or args.page or args.p or args.pp
local lang = args.language or args.lang
-- 4. ASSEMBLY
local res = author_str .. title_str
if lang then res = res .. " (in " .. lang .. ")" end
if series then res = res .. ". " .. series end
if journal then res = res .. ". ''" .. journal .. "''" end
if vol then res = res .. " '''" .. vol .. "'''" end
if issue then res = res .. " (" .. issue .. ")" end
if year ~= "" then res = res .. " (" .. year .. ")" end
if location ~= "" then res = res .. ". " .. location end
if publisher ~= "" then
if location ~= "" then res = res .. ": " end
res = res .. publisher
end
if pages then res = res .. ". p. " .. pages end
-- 5. IDENTIFIERS & ACCESS DATE
if args.isbn then
local isbn_clean = args.isbn:gsub("[^%d%-X]", "")
res = res .. ". [[ISBN]] [[Special:BookSources/" .. isbn_clean .. "|" .. args.isbn .. "]]"
end
if args.doi then
res = res .. ". [[Digital object identifier|doi]]:[https://doi.org/" .. args.doi .. " " .. args.doi .. "]"
end
if args.oclc then
res = res .. ". [[OCLC]] [https://www.worldcat.org/oclc/" .. args.oclc .. " " .. args.oclc .. "]"
end
if args['access-date'] or args.accessdate then
res = res .. ". Retrieved " .. (args['access-date'] or args.accessdate)
end
res = res .. "."
return frame:extensionTag('cite', res, {class = "citation"})
end
return p