Module:Glossary: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 6:
local content = current:getContent() or ""
-- find all [[internal links]]
local seen = {}
local entries = {}
local debug = {}
for link in content:gmatch("%[%[([^%]|]+)") do
Line 17:
seen[title] = true
-- look up the Definition: namespace version
local defTitle = "Definition:" .. title
local page = mw.title.new(defTitle)
if page andnot page.exists then
localtable.insert(debug, text"FAIL = pagemw.title.new:getContent() or "" .. defTitle)
elseif not page.exists -- strip templates, get first sentencethen
texttable.insert(debug, ="NOT textFOUND:gsub("%b{}", "" .. defTitle)
text = text:gsub("^%s+", "")else
local sentencetext = textpage:match("^getContent(.-%.)")
if sentencenot text then
table.insert(entriesdebug, {"NO CONTENT: " .. defTitle)
title = title,else
text = text:gsub("%b{}", summary = sentence"")
}text = text:gsub("^%s+", "")
local sentence = text:match("^(.-%.)")
if not sentence then
table.insert(debug, "NO SENTENCE: " .. defTitle)
else
table.insert(debug, "OK: " .. defTitle)
table.insert(entries, {
title = title,
summary = sentence
})
end
end
end
Line 37 ⟶ 46:
end
-- sort alphabetically
table.sort(entries, function(a, b)
return a.title < b.title
end)
-- render
local out = {}
-- debug output (remove once working)
table.insert(out, "=== DEBUG ===")
for _, d in ipairs(debug) do
table.insert(out, d)
end
table.insert(out, "=== END DEBUG ===")
for _, e in ipairs(entries) do
table.insert(out, string.format(