Module:Book: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
Line 1: Line 1:
local p = {}
local p = {}


local p = {}
local function splitValues(str, sep)
  local result = {}
  for part in raw:gmatch("[^" .. sep .. "]+") do
    part = part:match("^%s*(.-)%s*$")
    table.insert(result, part)
  end
  return result
end


function p.semanticStore(frame)
function p.semanticStore(frame)
Line 7: Line 14:
local titleObj = mw.title.getCurrentTitle()
local titleObj = mw.title.getCurrentTitle()
local args  = frame:getParent().args or {}
local args  = frame:getParent().args or {}
local booktitle = args.booktitle
local booktitle   = args.booktitle
local authors    = args.author
local publisher   = args.publisher
local releaseDate = args.released or args['release date']
local genre   = args.genre
local isbn        = args.ISBN
local lcc        = args.LCC
local bookformat  = args['format']
local country    = args.country
local language   = args.language


if not booktitle or booktitle == '' then
if not booktitle or booktitle == '' then
Line 14: Line 30:


mw.smw.set{
mw.smw.set{
     ['Has title'] = booktitle
     ['Has Title']   = booktitle,
    ['Author']      = authors,
    '+sep=,',
    ['Publisher']    = publisher,
    ['Release Date'] = releaseDate,
    ['Genre']        = genre,
    ['ISBN']        = isbn,
    ['LCC']          = lcc,
    ['Book Format']  = bookformat,
    ['Country']      = country,
    ['Language']    = language
}
}



Revision as of 11:31, August 19, 2025

Documentation for this module may be created at Module:Book/doc

local p = {}

local function splitValues(str, sep)
  local result = {}
  for part in raw:gmatch("[^" .. sep .. "]+") do
    part = part:match("^%s*(.-)%s*$")
    table.insert(result, part)
  end
  return result
end

function p.semanticStore(frame)

	local titleObj = mw.title.getCurrentTitle()
	local args   = frame:getParent().args or {}
	local booktitle   = args.booktitle
	local authors     = args.author
	local publisher	  = args.publisher	
	local releaseDate = args.released or args['release date']
	local genre		  = args.genre
	local isbn        = args.ISBN
	local lcc         = args.LCC
	local bookformat  = args['format']
	local country     = args.country
	local language	  = args.language	

	if not booktitle or booktitle == '' then
		booktitle = titleObj.text
	end

	mw.smw.set{
    	['Has Title']    = booktitle,
    	['Author']       = authors,
    	'+sep=,',
    	['Publisher']    = publisher,
    	['Release Date'] = releaseDate,
    	['Genre']        = genre,
    	['ISBN']         = isbn,
    	['LCC']          = lcc,
    	['Book Format']  = bookformat,
    	['Country']      = country,
    	['Language']     = language
	}

end

return p