Module:Year Link

被永久保护的模块
維基文庫,自由的圖書館
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

此模板可將紀年轉換為所對應的公元,在鼠標移動到紀年時顯示公元,並加上公元的分類。

不過需要注意的是:年初和年末並非一一對應,且年號有重複的情況。此時,需指定本模板的第二個參數。如:

{{YL|天復元年|901年}}

{{YL|康熙壬寅|1662年}}

可參考:

欲修订年号转换错误或新增年号转换,参见Year Link/data

將年號鏈接至公元紀年分類

模板参数[编辑模板数据]

此模板首选参数不换行的行内格式。

参数描述类型状态
年號1

无描述

示例值
天復元年
字符串必需
公元年份2

无描述

示例值
901年
字符串可选

local export = {}
local data = mw.loadData("Module:Year Link/data")

function normalize(raw)
	local r = raw
	for key, val in pairs(data.nMap) do
		r = r:gsub(key, val)
	end
	return r
end

function switch_convert(input)
    local year_text = input.args[1]
    return data.ref_switch[normalize(year_text or "NA")]
end

function specify_convert(input)
    local year_text= input.args[1]
    return data.ref_specify[normalize(year_text or "NA")]
end

function export.gl(frame)
	local result = ''
	local specified = mw.text.trim(frame.args[2])
	local name = mw.text.trim(frame.args[1])
	local subpagetitle = string.gsub(mw.title.getCurrentTitle().subpageText, "[0-9]", "")
	if specified ~= '' then
		result = '[[:Category:' .. specified  .. ' (提及)|<span id="' .. specified .. '" title="' .. specified .. '">' .. name .. '</span>]]'
		if subpagetitle ~= '全覽' then
			result = result .. '[[Category:' .. specified .. ' (提及)]]'
		end
		return result
	end
	local converted = switch_convert(frame)
	if converted ~= nil then
		result = '[[:Category:' .. converted .. ' (提及)|<span id="' .. converted .. '" title="' .. converted .. '">' .. name .. '</span>]]'
		if subpagetitle ~= '全覽' then
			result = result .. '[[Category:' .. converted .. ' (提及)]]'
		end
		return result
	end
	local notetext = specify_convert(frame)
	if notetext ~= nil then
		result = '[[:Category:需要指定公元的紀年|<span title="' .. notetext .. '">' .. name .. '</span>]]'
		if subpagetitle ~= '全覽' then
			result = result .. '[[Category:需要指定公元的紀年]]'
		end
		return result
	end
	return name
end

return export