Module:CitationLite: Difference between revisions
From Chalo Chatu, Zambia online encyclopedia
Chalochatu (talk | contribs) No edit summary |
Chalochatu (talk | contribs) No edit summary |
||
| Line 19: | Line 19: | ||
local function list_from(s) | local function list_from(s) | ||
-- Accept lists split by ";", "," or " | -- Accept lists split by ";", "," or "," | ||
if isempty(s) then return nil end | if isempty(s) then return nil end | ||
local items = {} | local items = {} | ||
| Line 25: | Line 25: | ||
table.insert(items, trim(part)) | table.insert(items, trim(part)) | ||
end | end | ||
if #items == 1 and items[1]:find(",") then | if #items == 1 and items[1]:find(",") then | ||
items = {} | items = {} | ||
for part in s:gmatch("[^,]+") do table.insert(items, trim(part)) end | for part in tostring(s):gmatch("[^,]+") do | ||
table.insert(items, trim(part)) | |||
end | |||
end | end | ||
return (#items > 0) and items or nil | return (#items > 0) and items or nil | ||
| Line 64: | Line 65: | ||
local function render_archive(url, date) | local function render_archive(url, date) | ||
if isempty(url) then return nil end | if isempty(url) then return nil end | ||
local label = isempty(date) and "Archived" or ("Archived " .. date) | local label = isempty(date) and "Archived" or ("Archived " .. tostring(date)) | ||
return extlink(url, label) | return extlink(url, label) | ||
end | end | ||
| Line 73: | Line 74: | ||
if not isempty(url) then table.insert(bits, extlink(url, "URL")) end | if not isempty(url) then table.insert(bits, extlink(url, "URL")) end | ||
if not isempty(archive_url) then table.insert(bits, render_archive(archive_url, archive_date)) end | if not isempty(archive_url) then table.insert(bits, render_archive(archive_url, archive_date)) end | ||
if not isempty(url_status) then table.insert(bits, "(" .. url_status .. ")") end | if not isempty(url_status) then table.insert(bits, "(" .. tostring(url_status) .. ")") end | ||
return join(bits, " • ") | return join(bits, " • ") | ||
end | end | ||
| Line 94: | Line 95: | ||
end | end | ||
if #authors == 0 then return nil end | if #authors == 0 then return nil end | ||
if #authors == 1 then | if #authors == 1 then | ||
return authors[1] | return authors[1] | ||
| Line 107: | Line 107: | ||
local function render_lang(lang) | local function render_lang(lang) | ||
if isempty(lang) then return nil end | if isempty(lang) then return nil end | ||
return "(" .. lang .. ")" | return "(" .. tostring(lang) .. ")" | ||
end | end | ||
| Line 118: | Line 118: | ||
end | end | ||
-- | -- Safe prefix helper to avoid nil concatenation | ||
local function prefixed(prefix, v) | local function prefixed(prefix, v) | ||
if isempty(v) then return nil end | if isempty(v) then return nil end | ||
| Line 126: | Line 126: | ||
-- ========== Core builders ========== | -- ========== Core builders ========== | ||
local function cite_web_like(kind, args) | local function cite_web_like(kind, args) | ||
-- author. "Title". ''Website/Work''. Publisher. Date. URL-Block. Accessed access-date. Quote | -- author. "Title". ''Website/Work''. Publisher. Date. URL-Block. Accessed access-date. Quote | ||
local author | local author = render_authors(args) | ||
local title | local title = quoted(args.title or args.chapter or args.article) | ||
local work | local work = italic(args.website or args.work or (kind == "news" and args.newspaper) or nil) | ||
local publisher= args.publisher | local publisher = args.publisher | ||
local date | local date = args.date or args["publication-date"] | ||
local urlblk | local urlblk = render_url_block(args.url, args["archive-url"], args["archive-date"], args["url-status"]) | ||
local access | local access = prefixed("Accessed ", args["access-date"]) | ||
local lang | local lang = render_lang(args.language or args.lang) | ||
local quote | local quote = isempty(args.quote) and nil or ("“" .. tostring(args.quote) .. "”") | ||
local body = punct_concat({ | local body = punct_concat({ | ||
| Line 153: | Line 152: | ||
local function cite_book(args) | local function cite_book(args) | ||
-- author. ''Title''. Edition. Publisher, Year. Place. ISBN. Pages. URL-Block. Accessed access-date. | -- author. ''Title''. Edition. Publisher, Year. Place. ISBN. Pages. URL-Block. Accessed access-date. | ||
local author | local author = render_authors(args) | ||
local title | local title = italic(args.title) | ||
local edition | local edition = args.edition | ||
local year | local year = args.year or args.date | ||
local place | local place = args.place or args.location | ||
local publisher= args.publisher | local publisher = args.publisher | ||
local isbn | local isbn = args.isbn | ||
local pages | local pages = args.pages or args.page | ||
local urlblk | local urlblk = render_url_block(args.url, args["archive-url"], args["archive-date"], args["url-status"]) | ||
local access | local access = prefixed("Accessed ", args["access-date"]) | ||
local lang | local lang = render_lang(args.language or args.lang) | ||
local publine | local publine | ||
if not isempty(publisher) and not isempty(year) then | if not isempty(publisher) and not isempty(year) then | ||
publine = publisher .. ", " .. year | publine = publisher .. ", " .. tostring(year) | ||
else | else | ||
publine = publisher or year | publine = publisher or year | ||
| Line 177: | Line 176: | ||
publine, | publine, | ||
place, | place, | ||
prefixed("ISBN ", isbn), | |||
pages and ("pp. " .. pages) or nil, | pages and ("pp. " .. tostring(pages)) or nil, | ||
urlblk, | urlblk, | ||
access, | access, | ||
| Line 196: | Line 195: | ||
local pages = args.pages or args.page | local pages = args.pages or args.page | ||
local year = args.year or args.date | local year = args.year or args.date | ||
local doi = | local doi = prefixed("doi:", args.doi) | ||
local urlblk = render_url_block(args.url, args["archive-url"], args["archive-date"], args["url-status"]) | local urlblk = render_url_block(args.url, args["archive-url"], args["archive-date"], args["url-status"]) | ||
local access = prefixed("Accessed ", args["access-date"]) | local access = prefixed("Accessed ", args["access-date"]) | ||
| Line 203: | Line 202: | ||
local voliss | local voliss | ||
if not isempty(volume) and not isempty(issue) then | if not isempty(volume) and not isempty(issue) then | ||
voliss = volume .. " (" .. issue .. ")" | voliss = tostring(volume) .. " (" .. tostring(issue) .. ")" | ||
else | else | ||
voliss = volume or issue | voliss = volume or issue | ||
end | end | ||
local pagestr = not isempty(pages) and (pages) or nil -- e.g., 12–34 | local pagestr = not isempty(pages) and tostring(pages) or nil -- e.g., 12–34 | ||
local after = join({ | local after = join({ | ||
