Module:Librivox book: Difference between revisions

Content deleted Content added
No edit summary
update image display for dark mode per TPER
 
(42 intermediate revisions by 5 users not shown)
Line 1:
local p = {}
 
function p.book(frame)
 
 
local pframe = frame:getParent()
 
 
local args = pframe.args
 
 
local tname = "Librivox book" -- name of calling template. Change if template rename.
 
local stitletitle = nil -- display and search title (default: titlearticle name w/out fielddab)
if 1 == 1 then
local name dtitle = nil -- authordisplay nametitle (default: niltitle)
return "Hello"
local stitle = nil -- search title (default: title)
end
local lname = nil -- last name
 
local titleid = nil -- book title (default: currentunsupported page)argument
local dtitleauthor = nil -- display title (default: title field)author
local stitle = nil -- search title (default: title field)
local name = nil -- author name (default: nil)
local tagline = "public ___domain audiobook at [[LibriVox]]"
local urlhead = "https://librivox.org/search?"
local italic = "''"
 
id = trimArg(args.id)
if 1 == 1id then
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," ", "+") -- replace "<space>" with "+"
--- Split name into words, count words, set name to last word
local N = mw.text.split(name, " ")
local l, count = mw.ustring.gsub(name, "%S+", "")
name = N[count]
 
author = trimArg(args.author)
local url = "[" .. urlhead .. "title=" .. stitle .. "&author=" .. name .. "&reader=&keywords=&genre_id=0&status=all&project_type=either&recorded_language=&sort_order=catalog_date&search_page=1&search_form=advanced" .. " " .. tagline
if not author then
lname = ""
else
--- Split name into words, count words, set name to last word
local N = mw.text.split(nameauthor, " ")
stitle local l, count = mw.ustring.gsub(stitleauthor, "%s%(.*%)S+", "")
name lname = N[count]
end
 
local url = "[[File:Speaker Icon.svg|15px|class=skin-invert-image|link=|alt=]] " .. "[" .. urlhead .. "title=" .. stitle .. "&author=" .. namelname .. "&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 arg == "" or arg == nil then
return "Hello"nil
else
title =return mw.text.trim(args.titlearg)
end
end