Module:Glossary: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 3:
 
function p.generate(frame)
local maxEntries = tonumber(frame.args[1]) or 30
local current = mw.title.getCurrentTitle()
local content = current:getContent() or ""
Line 8 ⟶ 9:
local seen = {}
local entries = {}
local debugcount = {}0
for link in content:gmatch("%[%[([^%]|]+)") do
if count >= if not pagemaxEntries then
elsebreak
))end
local title = link:match("^(.-)#") or link
title = mw.text.trim(title)
Line 17 ⟶ 22:
seen[title] = true
local defTitle = "Definition:" .. title
localif page = mw.title.new:match(defTitle"^Definition:") then
defTitle = title
if not page then
table.insert(debug, "FAIL mw.title.new: " .. defTitle)
elseif not page.exists then
table.insert(debug, "NOT FOUND: " .. defTitle)
else
defTitle = "Definition:" .. elsetitle
end
local page table.insert(debug, "FAIL= mw.title.new: " .. (defTitle)
elseif notif page.exists then
local text = page:getContent()
if not text then
table.insert(debug, "NO CONTENT: " .. defTitle)
else
text = text:gsub("%b{}", "")
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:gsub("^Definition:", ""),
summary = sentence
})
table.insert(debug,count "OK:= "count ..+ defTitle)1
end
end
Line 51 ⟶ 53:
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, stringe.format(summary)
"'''%s''': %s", e.title, e.summary
))
end