Module:Book: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
Line 14: 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']  or ''
local authors    = args['author'] or ''
local authors    = args['author'] or ''
local publisher   = args.publisher
local publisher   = args['publisher'] or ''
local releaseDate = args.released or args['release date']
local releaseDate = args['released'] or args['release date'] or ''
local genre   = args.genre
local genre   = args['genre']  or ''
local isbn        = args.ISBN
local isbn        = args['ISBN']  or ''
local lcc        = args.LCC
local lcc        = args['LCC']  or ''
local bookformat  = args['format']
local bookformat  = args['format'] or ''
local country    = args.country
local country    = args['country']  or ''
local language   = args.language
local language   = args['language']  or ''


if not booktitle or booktitle == '' then
if not booktitle or booktitle == '' then

Revision as of 11:47, 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']  or ''
	local authors     = args['author'] or ''
	local publisher	  = args['publisher'] or ''
	local releaseDate = args['released'] or args['release date']  or ''
	local genre		  = args['genre']  or ''
	local isbn        = args['ISBN']  or ''
	local lcc         = args['LCC']  or ''
	local bookformat  = args['format']  or ''
	local country     = args['country']  or ''
	local language	  = args['language']  or ''

	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