「モジュール:SignalinstWiki」の版間の差分

修正
編集の要約なし
 
(同じ利用者による、間の11版が非表示)
74行目: 74行目:
     return finalOutput
     return finalOutput
end
end


function p.categoriesToTemplate(frame)
function p.categoriesToTemplate(frame)
-- 返すべき内容を保持する
    local args = {
local output = "{{ナビゲーションボックス|title=カテゴリ別ページ一覧|opened=False|"
        title = "カテゴリ一覧",
        opened = "False"
-- パーサーを呼び出し、Semantec MediaWikiからカテゴリ一覧を取得
    }
local result = frame:callParserFunction("#ask", "[[TopCategory::true]]|?PAGENAME|format=plainlist")
 
    local categories = mw.text.trim(
-- 中身を正規化したうえで分割し、各カテゴリごとに回す
        frame:expandTemplate{ title = "カテゴリ一覧" } or ""
local i = 1
    )
for line in mw.text.gsplit(result, "\n", true) do
 
if line ~= '' then
    local i = 1
-- line = 名前空間を除いたタイトル => カテゴリ名称
    for category in mw.text.gsplit(categories, ",", true) do
-- このカテゴリに対して意味的検索を用いてさらにページ一覧を取得
        category = mw.text.trim(category)
local result = frame:callParserFunction("#ask", "[[カテゴリ:"..line.."]]|?PAGENAME|format=list|sep=,")
        if category ~= "" then
            local categoryName = mw.text.trim(
-- カンマ区切りで出力されるのでこれをテンプレートに埋め込む
                category:gsub("^カテゴリ:", "")
output = output .. "header"..i.."="..line.."|content"..i.."="..result.."|"
            )
 
-- iのインクリメント
            local pages = mw.text.trim(
i = i + 1
                frame:expandTemplate{
end
                    title = "カテゴリ別ページ一覧",
end
                    args = { category }
                } or ""
-- 閉じて返す
            )
output = output .. "}}"
 
            args["header" .. i]  = "[[:カテゴリ:"..categoryName.."|"..categoryName.."]]"
return output
            args["content" .. i] = pages
 
            i = i + 1
        end
    end
 
    return frame:expandTemplate{
        title = "ナビゲーションボックス",
        args  = args
    }
end
end


return p
return p