词条 | Module:Signpost/index |
释义 | -- This module processes data from Signpost/index, to be loaded from-- Signpost with mw.loadData. local PAGE_FORMAT = 'Wikipedia:Wikipedia Signpost/%s/%s' local INDEX_START_YEAR = 2005 local INDEX_BASE = 'Module:Signpost/index/' local ALIASES_MODULE = 'Module:Signpost/aliases' local insert = table.insert local format = string.format local function makePageName(date, subpage) return format(PAGE_FORMAT, date, subpage) end local function addSubtable(tIn, tOut, key) tOut[key] = tOut[key] or {} insert(tOut[key], tIn) end local function maybeRequire(page) local success, module = pcall(require, page) if success then return module end end local function getYearIndexes() local ret = {} for i = INDEX_START_YEAR, os.date('*t').year + 1 do local module = maybeRequire(INDEX_BASE .. tostring(i)) insert(ret, module) end return ret end local function makeAliases() local aliasData = require(ALIASES_MODULE) local ret = {} for key, aliases in pairs(aliasData) do for i, alias in ipairs(aliases) do ret[alias] = key end end return ret end local function main() local list, dates, tags, pages = {}, {}, {}, {} local i = 0 for j, index in ipairs(getYearIndexes()) do for k, t in ipairs(index) do i = i + 1 t.sortKey = i local date = t.date local page = makePageName(date, t.subpage) t.page = page list[i] = t addSubtable(t, dates, date) for l, tag in ipairs(t.tags) do addSubtable(t, tags, tag) end pages[page] = t end end return { list = list, dates = dates, tags = tags, pages = pages, aliases = makeAliases() } end return main() |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。