Module:Librivox book: Difference between revisions

Content deleted Content added
No edit summary
update image display for dark mode per TPER
 
(26 intermediate revisions by 5 users not shown)
Line 1:
local p = {}
 
function p.book(frame)
 
 
local pframe = frame:getParent()
Line 9 ⟶ 8:
local tname = "Librivox book" -- name of calling template. Change if template rename.
 
local dtitletitle = nil -- display and search title (default: titlearticle name w/out fielddab)
local stitledtitle = nil -- searchdisplay title (default: title field)
local stitle = nil -- search title (default: title)
local lname = nil -- last name
local id = nil -- unsupported argument
local author = nil -- author
local tagline = "public ___domain audiobook at [[LibriVox]]"
local urlhead = "https://librivox.org/search?"
local italic = "''"
 
if args.id ~= "" and trimArg(args.id ~= nil then)
if id then
return "Error in " .. tname .. "}}. Please use {{tl|Librivox author}}"
error("Error in Template:" .. tname .. " - id argument not supported - please see documentation at [[Template:Librivox author]]")
end
 
if args.title == "" or trimArg(args.title == nil then)
if not title then
title = mw.title.getCurrentTitle().text
dtitle = title
stitle = dtitle
else
title = mw.text.trim(args.title)
dtitle = title
stitle = dtitle
end
dtitle = mw.ustring.gsub(dtitletitle,"'%s+%(.*[^%(]-%)"$', ""'') -- removeRemove disambiguationthe ()final disambig paren
stitle = dtitle
 
if trimArg(args.stitle ~= nil and args.stitle ~= "") then
stitle = mw.text.trimtrimArg(args.stitle)
if not trimArg(args.title) then -- For when used outside main article space
dtitle = titlestitle
end
end
if trimArg(args.dtitle ~= nil and args.dtitle ~= "") then
dtitle = mw.text.trimtrimArg(args.dtitle)
italic = ""
end
dtitle = mw.ustring.gsub(dtitle,"%s%(.*%)", "") -- remove disambiguation ()
stitle = mw.ustring.gsub(stitle,"%s%(.*%)", "")
stitle = mw.ustring.gsub(stitle," ", "+") -- replace "<space>" with "+"
 
local stitle = mw.ustring.gsub(stitle,"%s%(.*%) ", "+") -- replace "<space>" with "+"
if args.author == "" or args.author == nil then
 
author = trimArg(args.author)
if not author then
lname = ""
else
--- Split name into words, count words, set name to last word
local N = mw.text.split(mw.text.trim(args.author), " ")
local l, count = mw.ustring.gsub(mw.text.trim(args.author), "%S+", "")
lname = N[count]
end
 
local url = "[[ImageFile:Speaker Icon.svg|20px15px|class=skin-invert-image|link=|alt=]] " .. "[" .. urlhead .. "title=" .. stitle .. "&author=" .. lname .. "&reader=&keywords=&genre_id=0&status=all&project_type=either&recorded_language=&sort_order=catalog_date&search_page=1&search_form=advanced" .. " " .. italic .. dtitle .. italic .. "]" .. " " .. tagline
 
return url
 
end
 
function trimArg(arg)
if args.authorarg == "" or args.authorarg == nil then
return nil
else
title =return mw.text.trim(args.titlearg)
end
end