模块:SongPlayer:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第17行: | 第17行: | ||
local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH') | local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH') | ||
local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}') | local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}') | ||
local songUrl = 'http://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3' | |||
local | -- 构建一个带有 data-* 属性的 div 来存储信息 | ||
local data_div = mw.html.create('div') | |||
:attr('id', 'song-player-data') | |||
:attr('style', 'display:none;') | |||
:attr('data-name', title) | |||
:attr('data-artist', artist or 'Unknown Artist') | |||
:attr('data-url', songUrl) | |||
:attr('data-cover', imagePath) | |||
:done() | |||
local html = { | local html = { | ||
'<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">', | '<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">', | ||
'<div id="song-player-fixed"></div>', | '<div id="song-player-fixed"></div>', | ||
'<script src="/aplayer/dist/APlayer.min.js"></script>' | tostring(data_div), | ||
'<script src="/aplayer/dist/APlayer.min.js"></script>' | |||
} | } | ||
2025年11月29日 (六) 18:58的版本
此模块的文档可以在模块:SongPlayer/doc创建
local p = {}
function p.player(frame)
local args = frame:getParent().args
local title = args.title
local artist = args.artist
local imageName = args.image
if not title or title == '' or not imageName or imageName == '' then
return ''
end
local sanitizedTitle = title
sanitizedTitle = sanitizedTitle:gsub(' ', '_')
sanitizedTitle = sanitizedTitle:gsub('[\\/:*?"<>|]', '-')
local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}')
local songUrl = 'http://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'
-- 构建一个带有 data-* 属性的 div 来存储信息
local data_div = mw.html.create('div')
:attr('id', 'song-player-data')
:attr('style', 'display:none;')
:attr('data-name', title)
:attr('data-artist', artist or 'Unknown Artist')
:attr('data-url', songUrl)
:attr('data-cover', imagePath)
:done()
local html = {
'<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">',
'<div id="song-player-fixed"></div>',
tostring(data_div),
'<script src="/aplayer/dist/APlayer.min.js"></script>'
}
return table.concat(html, '\n')
end
return p