跳转到内容

模块:Test:修订间差异

来自SS唯基
攸萨留言 | 贡献
无编辑摘要
标签已被回退
攸萨留言 | 贡献
无编辑摘要
标签已被回退
第16行: 第16行:


         -- 获取页面内容
         -- 获取页面内容
         local content = pageTitle:getContent() or "内容无法加载"
         local content = pageTitle:getContent()


         -- 如果内容包含模板,使用 expandTemplate 处理
         -- 检查内容是否有效
         if content:find("{{") then
         if content then
            local expandedContent = frame:expandTemplate{ title = pageTitle.text } or "内容无法加载"
             output = output .. content .. "\n\n" -- 添加页面内容
             output = output .. expandedContent .. "\n\n"
         else
         else
             output = output .. content .. "\n\n"  -- 添加页面内容
             output = output .. "内容无法加载\n\n"  -- 错误处理
         end
         end
     end
     end

2025年9月13日 (六) 00:21的版本

Documentation icon 模块文档 [-查看-] [编辑] [历史] [刷新]

这个模块是干什么用的?

该模块用于测试,测试完请清空模块内的内容

基本用法

local p = {}

function p.函数名()
return '返回内容'
end

function p.函数名2()
return '返回内容2'
end

return

以上为最基本的用法,其他请自行学习Lua语言

其他

同样也有一个用于测试模板的模板,点这里进入


local p = {}

function p.paginate(frame)
    -- 获取参数
    local pages = frame.args.pages or ""
    local pageList = mw.text.split(pages, ",")
    local output = ""

    -- 生成内容
    for _, page in ipairs(pageList) do
        page = mw.text.trim(page)  -- 去掉前后空格
        local pageTitle = mw.title.new(page)

        -- 添加标题
        output = output .. string.format("=== %s ===\n", pageTitle.text)

        -- 获取页面内容
        local content = pageTitle:getContent()

        -- 检查内容是否有效
        if content then
            output = output .. content .. "\n\n"  -- 添加页面内容
        else
            output = output .. "内容无法加载\n\n"  -- 错误处理
        end
    end

    return output
end

return p