跳转到内容
打开/关闭搜索
搜索
打开/关闭菜单
451
条目
798
文件
22
用户
8955
编辑
Blockland Wiki
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
打开/关闭外观设置菜单
无法加载外观设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
查看“︁模块:CharacterJsonLD”︁的源代码
来自Blockland Wiki
查看
阅读
查看源代码
查看历史
相关页面
模块
讨论
更多操作
更多
工具
链入页面
相关更改
页面信息
Cargo数据
←
模块:CharacterJsonLD
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local p = {} -- ========================================== -- Blockland Wiki - Character JSON-LD -- Universal character structured data module -- ========================================== local function clean(value) if type(value) ~= 'string' then return nil end value = mw.text.trim(value) if value == '' then return nil end return value end -- Build a direct MediaWiki file URL local function fileUrl(filename) filename = clean(filename) if not filename then return nil end filename = filename:gsub('^文件:', '') filename = filename:gsub('^[Ff]ile:', '') filename = mw.text.trim(filename) return 'https://blockland.wiki/wiki/Special:FilePath/' .. mw.uri.encode(filename, 'PATH') end -- Get DynamicJsonLD Lua library local function getJsonLD() if mw.ext and mw.ext.JsonLD then return mw.ext.JsonLD end local ok, lib = pcall( require, 'mw.ext.JsonLD' ) if ok and type(lib) == 'table' then return lib end return nil end function p.main(frame) -- Parameters from template or #invoke local args = frame.args local parent = frame:getParent() if not clean(args['名称']) and parent then args = parent.args end local title = mw.title.getCurrentTitle() -- Only main namespace articles if title.namespace ~= 0 then return '' end local name = clean(args['名称']) or title.text local pageUrl = tostring(title:fullUrl()) -- ========================================== -- Main character entity -- ========================================== local entity = { ["@type"] = "Person", ["@id"] = pageUrl .. '#character', ["name"] = name, ["url"] = pageUrl } -- Description local description = clean(args['简介']) if description then entity.description = description end -- ========================================== -- Alternate names -- Avoid Lua arrays for DynamicJsonLD -- ========================================== local aliases = {} local seen = {} for _, key in ipairs({ '本名', '英文名', '别名', '其他名称' }) do local value = clean(args[key]) if value and value ~= name and not seen[value] then table.insert(aliases, value) seen[value] = true end end if #aliases > 0 then entity.alternateName = table.concat( aliases, '、' ) end -- ========================================== -- Primary avatar -- ========================================== local avatar = fileUrl(args['头像']) if avatar then entity.image = { ["@type"] = "ImageObject", ["name"] = name .. '的头像', ["url"] = avatar, ["contentUrl"] = avatar } end -- ========================================== -- Full-body illustration -- ========================================== local artwork = fileUrl(args['立绘']) if artwork then local illustration = { ["@type"] = "ImageObject", ["name"] = name .. '的角色立绘', ["url"] = artwork, ["contentUrl"] = artwork, ["about"] = { ["@id"] = pageUrl .. '#character' } } -- Keep main image as avatar -- Associate illustration with character if avatar then entity.subjectOf = illustration else entity.image = illustration end end -- ========================================== -- Optional music group -- ========================================== local group = clean(args['所属组合']) if group then local musicGroup = { ["@type"] = "MusicGroup", ["name"] = group } local groupUrl = clean(args['组合链接']) if groupUrl then musicGroup.url = groupUrl end entity.memberOf = musicGroup end -- ========================================== -- DynamicJsonLD integration -- ========================================== local JsonLD = getJsonLD() if not JsonLD then return '<strong class="error">' .. 'CharacterJsonLD: DynamicJsonLD Lua API unavailable' .. '</strong>' end if type(JsonLD.setMainEntity) ~= 'function' then return '<strong class="error">' .. 'CharacterJsonLD: setMainEntity unavailable' .. '</strong>' end local ok, err = pcall(function() JsonLD.setMainEntity(entity) end) if not ok then return '<strong class="error">' .. 'CharacterJsonLD: ' .. mw.text.encode(tostring(err)) .. '</strong>' end -- Optional debugging if clean(args['调试']) == '1' then return 'JSONLD_SUCCESS: ' .. name end return '' end return p
此页面嵌入的页面:
模块:CharacterJsonLD/doc
(
查看源代码
)
返回
模块:CharacterJsonLD
。
查看“︁模块:CharacterJsonLD”︁的源代码
来自Blockland Wiki