このモジュールについての説明文ページを モジュール:RelatedByCategory/doc に作成できます
local p = {} function p.show(frame) local title = mw.title.getCurrentTitle() local categories = title:getParentCategories() local results = {} local limit = tonumber(frame.args[1]) or 5 for catTitle, _ in pairs(categories) do if mw.title.new(catTitle).namespace == 14 then -- Category namespace local cat = mw.title.new(catTitle):getContent() local pages = mw.site.stats.pagesInCategory(catTitle, false) for _, page in ipairs(pages) do if page.prefixedText ~= title.prefixedText and #results < limit then table.insert(results, '[[' .. page.prefixedText .. ']]') end end end end if #results == 0 then return '<div class="related-footer"><small>関連記事はまだありません。</small></div>' end return '<div class="related-footer"><strong>📚 関連記事:</strong><ul><li>' .. table.concat(results, '</li><li>') .. '</li></ul></div>' end return p