此模块的文档可以在模块:路线图(横板)/doc创建
local p = {}
function p.render(frame)
local args = frame:getParent().args
local current = tonumber(args[1]) or 0
local stations = {}
-- 收集所有车站参数
for i = 2, 20 do -- 假设最多20个车站
if args[i] and args[i] ~= "" then
table.insert(stations, {
name = args[i],
num = i-1,
isCurrent = (i-1) == current,
isPassed = (i-1) < current
})
else
break
end
end
-- 生成车站列表HTML
local html = {}
for i = #stations, 1, -1 do -- 从右向左排列
local station = stations[i]
local color = "#000000"
if i == #stations then
color = "#0071bc"
elseif station.isCurrent then
color = "#ed1c24"
elseif station.isPassed then
color = "#808080"
end
table.insert(html, string.format([[
<div style="position: relative; writing-mode: vertical-rl;
margin-left: 15px; color: %s;">%s%s</div>]],
color,
station.name,
station.isCurrent and [[<div style="position: absolute; top: -25px; left: 50%;
width: 5px; height: 5px; background: #ffff00; border-radius: 50%;
transform: translateX(-50%);"></div>]] or ""
))
end
return table.concat(html)
end
return p