打开/关闭菜单
324
1711
132
1.2万
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Hatnote:修订间差异

来自星露谷物语扩展百科
删除的内容 添加的内容
Sizau留言 | 贡献
创建页面
 
Sizau留言 | 贡献
无编辑摘要
第2行: 第2行:
local p = {}
local p = {}


-- 获取页面类型
-- 辅助函数:检查字符串是否为维基链接
local function checkLink(s)
local function getPageType(title, hasSection)
if hasSection then return '章节' end
return s:find('[[', 1, true) and s:find(']]', 1, true)
end


local nsText = title.nsText
-- 辅助函数:获取页面类型
if nsText == '模板' then
local function getPageType(title, hasSection)
return '模板'
if hasSection then
elseif nsText == '模块' then
return '章节'
return '模块'
end
else
return '条目'
local nsText = title.nsText
end
if nsText == '模板' then
return '模板'
elseif nsText == '模块' then
return '模块'
else
return '条目'
end
end
end


-- 辅助函数:格式化链接
-- 格式化链接
local function formatLink(text)
local function formatLink(text)
if isWikilink(text) then
if text:find('[[', 1, true) and text:find(']]', 1, true) then
return "“'''" .. text .. "'''”"
return "“'''" .. text .. "'''”"
else
else
return "“'''[[" .. text .. "]]'''”"
return "“'''[[" .. text .. "]]'''”"
end
end
end
end


-- 检查是否为连接词
-- 检查是否为连接词
local function isConnector(text)
local function isConnector(text)
return text == '和' or text == '或' or text == '、'
return text == '和' or text == '或' or text == '、'
end
end


-- 获取最大数字索引
-- 获取最大数字索引
local function getMaxIndex(args)
local function getMaxIndex(args)
local maxIndex = 0
local maxIndex = 0
for key, _ in pairs(args) do
for key, _ in pairs(args) do
local index = tonumber(key)
local index = tonumber(key)
if index and index > 0 and math.floor(index) == index then
if index and index > 0 and math.floor(index) == index then
if index > maxIndex then
if index > maxIndex then maxIndex = index end
end
maxIndex = index
end
end
return maxIndex
end
end
return maxIndex
end
end


-- 处理描述和链接序列
-- 处理描述和链接序列
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
local parts = {}
local parts = {}
local state = '' -- 状态: '' | 'link' | 'end'
local state = '' -- 状态: '' | 'link' | 'end'

for i = startIndex, maxIndex do
for i = startIndex, maxIndex do
local value = args[i]
local value = args[i]
if value then
if value then
if state == 'link' then
if state == 'link' then
table.insert(parts, formatLink(value))
table.insert(parts, formatLink(value))
state = 'end'
state = 'end'
elseif isConnector(value) then
elseif isConnector(value) then
table.insert(parts, value)
table.insert(parts, value)
else
else
if state == 'end' then
if state == 'end' then table.insert(parts, ';') end
local description = (value ~= '') and value or '其他用法'
table.insert(parts, ';')
table.insert(parts, '关于' .. description .. ',请见')
end
state = 'link'
local description = (value ~= '') and value or '其他用法'
end
table.insert(parts, '关于' .. description .. ',请见')
end
state = 'link'
end
end

end
-- fallback
end
if state == 'link' then
table.insert(parts, formatLink(pagename .. '(消歧义)'))
-- fallback
end
if state == 'link' then

table.insert(parts, formatLink(pagename .. '(消歧义)'))
return parts, state
end
return parts, state
end
end


-- For
-- For
function p.about(frame)
function p.about(frame)
local args = getArgs(frame, {
local args = getArgs(frame,
{trim = true, removeBlanks = true, parentOnly = true})
trim = true,

removeBlanks = true,
local maxIndex = getMaxIndex(args)
parentOnly = true
local title = mw.title.getCurrentTitle()
})
local pagename = title.text

local maxIndex = getMaxIndex(args)
local contentParts = {'[[File:Disambig gray.svg|25px|link=]]  '}
local title = mw.title.getCurrentTitle()

local pagename = title.text
if args[1] then
local pageType = getPageType(title, args.section)
local contentParts = {
table.insert(contentParts,
'[[File:Disambig gray.svg|25px|link=]]  '
'本' .. pageType .. '介绍的是' .. args[1])
}
end

if args[1] then
local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)
local pageType = getPageType(title, args.section)

table.insert(contentParts, '本' .. pageType .. '介绍的是' .. args[1])
if maxIndex < 2 and args[1] then
end
table.insert(subsequentParts, '关于其他用法,请见' ..
formatLink(pagename .. '(消歧义)'))
local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)
end

if maxIndex < 2 and args[1] then
local finalParts = {table.concat(contentParts, '')}
table.insert(subsequentParts, '关于其他用法,请见' .. formatLink(pagename .. '(消歧义)'))

end
if #subsequentParts > 0 then
local finalParts = { table.concat(contentParts, '') }
if args[1] then table.insert(finalParts, '') end
table.insert(finalParts, table.concat(subsequentParts, ' '))
table.insert(finalParts, '。')
if #subsequentParts > 0 then
if args[1] then
elseif args[1] then
table.insert(finalParts, '。 ')
table.insert(finalParts, '。')
end
end

table.insert(finalParts, table.concat(subsequentParts, ' '))
table.insert(finalParts, '')
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
elseif args[1] then
table.insert(finalParts, '。')
end
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{ title = 'hatnote', args = { finalContent } }
end
end


-- For
-- For
function p.for2(frame)
function p.for2(frame)
local args = getArgs(frame, {
local args = getArgs(frame,
{trim = true, removeBlanks = true, parentOnly = true})
trim = true,

removeBlanks = true,
local maxIndex = getMaxIndex(args)
parentOnly = true
local title = mw.title.getCurrentTitle()
})
local pagename = title.text

local maxIndex = getMaxIndex(args)
local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}
local title = mw.title.getCurrentTitle()

local pagename = title.text
if args.R then table.insert(contentParts, args.R) end

local contentParts = {
local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)
'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'

}
if maxIndex < 1 then
table.insert(subsequentParts, '关于其他用法,请见')
if args.R then
table.insert(contentParts, args.R)
table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
end
end

local finalParts = {table.concat(contentParts, '')}
local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)

if maxIndex < 1 then
if #subsequentParts > 0 then
table.insert(subsequentParts, '关于其他用法,请见')
if args.R then table.insert(finalParts, ' ') end
table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
table.insert(finalParts, table.concat(subsequentParts, ' '))
table.insert(finalParts, '。')
end
end

local finalParts = { table.concat(contentParts, '') }
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
if #subsequentParts > 0 then
if args.R then
table.insert(finalParts, ' ')
end
table.insert(finalParts, table.concat(subsequentParts, ' '))
table.insert(finalParts, '。')
end
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{ title = 'hatnote', args = { finalContent } }
end
end



2025年10月14日 (二) 19:39的版本

[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local getArgs = require('Module:Arguments').getArgs
local p = {}

-- 获取页面类型
local function getPageType(title, hasSection)
    if hasSection then return '章节' end

    local nsText = title.nsText
    if nsText == '模板' then
        return '模板'
    elseif nsText == '模块' then
        return '模块'
    else
        return '条目'
    end
end

-- 格式化链接
local function formatLink(text)
    if text:find('[[', 1, true) and text:find(']]', 1, true) then
        return "“'''" .. text .. "'''”"
    else
        return "“'''[[" .. text .. "]]'''”"
    end
end

-- 检查是否为连接词
local function isConnector(text)
    return text == '和' or text == '或' or text == '、'
end

-- 获取最大数字索引
local function getMaxIndex(args)
    local maxIndex = 0
    for key, _ in pairs(args) do
        local index = tonumber(key)
        if index and index > 0 and math.floor(index) == index then
            if index > maxIndex then maxIndex = index end
        end
    end
    return maxIndex
end

-- 处理描述和链接序列
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
    local parts = {}
    local state = '' -- 状态: '' | 'link' | 'end'

    for i = startIndex, maxIndex do
        local value = args[i]
        if value then
            if state == 'link' then
                table.insert(parts, formatLink(value))
                state = 'end'
            elseif isConnector(value) then
                table.insert(parts, value)
            else
                if state == 'end' then table.insert(parts, ';') end
                local description = (value ~= '') and value or '其他用法'
                table.insert(parts, '关于' .. description .. ',请见')
                state = 'link'
            end
        end
    end

    -- fallback
    if state == 'link' then
        table.insert(parts, formatLink(pagename .. '(消歧义)'))
    end

    return parts, state
end

-- For
function p.about(frame)
    local args = getArgs(frame,
                         {trim = true, removeBlanks = true, parentOnly = true})

    local maxIndex = getMaxIndex(args)
    local title = mw.title.getCurrentTitle()
    local pagename = title.text

    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}

    if args[1] then
        local pageType = getPageType(title, args.section)
        table.insert(contentParts,
                     '本' .. pageType .. '介绍的是' .. args[1])
    end

    local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)

    if maxIndex < 2 and args[1] then
        table.insert(subsequentParts, '关于其他用法,请见' ..
                         formatLink(pagename .. '(消歧义)'))
    end

    local finalParts = {table.concat(contentParts, '')}

    if #subsequentParts > 0 then
        if args[1] then table.insert(finalParts, '。 ') end
        table.insert(finalParts, table.concat(subsequentParts, ' '))
        table.insert(finalParts, '。')
    elseif args[1] then
        table.insert(finalParts, '。')
    end

    local finalContent = table.concat(finalParts, '')
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
end

-- For
function p.for2(frame)
    local args = getArgs(frame,
                         {trim = true, removeBlanks = true, parentOnly = true})

    local maxIndex = getMaxIndex(args)
    local title = mw.title.getCurrentTitle()
    local pagename = title.text

    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}

    if args.R then table.insert(contentParts, args.R) end

    local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)

    if maxIndex < 1 then
        table.insert(subsequentParts, '关于其他用法,请见')
        table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
    end

    local finalParts = {table.concat(contentParts, '')}

    if #subsequentParts > 0 then
        if args.R then table.insert(finalParts, ' ') end
        table.insert(finalParts, table.concat(subsequentParts, ' '))
        table.insert(finalParts, '。')
    end

    local finalContent = table.concat(finalParts, '')
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
end

p['for'] = p.for2

return p