모듈:Outline
보이기
다른 문서의 문단 개요를 생성합니다.
getSectionOutline[원본 편집]
특정 문서의 최상위 문단으로 생성된 개요를 테이블 형식으로 얻습니다. 반환되는 테이블에는 각 문단 제목이 문자열로 들어있습니다.
local Outline = require('모듈:Outline')
return Outline.getSectionOutline('모듈:Outline/설명문서')
----
{
"getSectionOutline",
"bulletOutline"
}
bulletOutline[원본 편집]
특정 문서의 최상위 문단으로 생성된 개요를 목록으로 출력합니다. 또한 목록의 각 항목은 해당 문단으로 이동하는 링크가 걸립니다.
code_blocks 코드
{{#invoke:Outline|bulletOutline|모듈:Outline/설명문서}}
code
description 결과
quarterForumOutline[원본 편집]
분기로 나뉘는 포럼 문서의 주제(문단)들의 제목을 목록으로 출력합니다. 또한 각 주제로 이동하는 링크를 추가합니다.
code_blocks 코드
{{#invoke:Outline|quarterForumOutline|사용자:Hsl0/리버티게임:업데이트|8}}
code
description 결과
9번째 줄에서 Lua 오류: 사용자:Hsl0/리버티게임:업데이트/2025년 3분기 is not existing page.
| 위 설명은 모듈:Outline/설명문서의 내용을 가져와 보여주고 있습니다. (편집 | 역사) 이 모듈에 대한 수정 연습과 시험은 연습장 (만들기 | 미러)과 시험장 (만들기)에서 할 수 있습니다. 분류는 /설명문서에 넣어주세요. 이 모듈에 딸린 문서. |
local p = {}
local contentLang = mw.language.getContentLanguage()
local sp = require('모듈:SectionParser')
function p.getSectionOutline(title)
local titleObj = mw.title.new(title)
if not titleObj.exists then
error(title .. ' is not existing page')
end
local content = titleObj:getContent()
local sectionTbl = sp.tree(content)
local sectionOutline = {}
for n, section in ipairs(sectionTbl) do
table.insert(sectionOutline, section.name)
end
return sectionOutline
end
function imap(tbl, fun)
local newtbl = {}
for k, v in ipairs(tbl) do
table.insert(newtbl, fun(k, v))
end
return newtbl
end
function createLink(title, section, display)
return '[[' .. title .. '#' .. mw.uri.anchorEncode(section) .. '|' .. display .. ']]'
end
function bulletList(tbl)
return '* ' .. table.concat(tbl, '\n* ') .. '\n'
end
function p.bulletOutline(frame)
local title = frame.args[1]
local outline = p.getSectionOutline(title)
local outlineLinks = imap(outline, function(n, section)
return createLink(title, section, section)
end)
return bulletList(outlineLinks)
end
function getQuarter(now)
return math.ceil(tonumber(contentLang:formatDate('n', now)) / 3)
end
function prevQuarter(year, quarter)
if quarter > 1 then
return year, quarter - 1
else
return year - 1, 4
end
end
function p.quarterForumOutline(frame)
local prefix = frame.args[1] -- 포럼 문서 접두어
local length = tonumber(frame.args[2]) -- 최대 개요 개수
local now = frame.args[3] -- 지정된 기준 날짜
-- 현재 분기 문서
local quarter = getQuarter(now) -- 분기
local year = tonumber(contentLang:formatDate('Y', now)) -- 연도
local page = prefix .. '/' .. year .. '년 ' .. quarter .. '분기'
-- 현재 분기가 없다면 이전 분기 (문서가 아직 생성되지 않은 경우를 위해)
if not mw.title.new(page).exists then
year, quarter = prevQuarter(year, quarter)
page = prefix .. '/' .. year .. '년 ' .. quarter .. '분기'
end
local outline = p.getSectionOutline(page)
outline = imap(outline, function(n, section)
-- 개요에 문단 링크
-- return createLink(page, section, section)
return section .. ' (' .. createLink(page, section, '자세히') .. ')'
end)
-- 최대 개요 개수에 미달시, 이전 분기에서 개요 가져옴
while #outline < length do
year, quarter = prevQuarter(year, quarter)
page = prefix .. '/' .. year .. '년 ' .. quarter .. '분기'
-- 이전 분기 문서가 없으면 종료
if not mw.title.new(page).exists then
break
end
local prevOutline = p.getSectionOutline(page)
prevOutline = imap(prevOutline, function(n, section)
-- return createLink(page, section, section)
return section .. ' (' .. createLink(page, section, '자세히') .. ')'
end)
outline = {unpack(prevOutline), unpack(outline)}
end
-- 최대 개요 개수 초과시, 앞(오래된) 문단부터 지우기
while #outline > length do
table.remove(outline, 1)
end
-- 문단 개요를 목록으로 출력
return bulletList(outline)
end
return p