Module:VideoGallery
From Dune Awakening DB
Documentation for this module may be created at Module:VideoGallery/doc
-- Module:VideoGallery (no LuaSQLite required)
local p = {}
local json = mw.text.jsonEncode
local ed = mw.ext.externaldata
-----------------------------------------------------------------
-- collectRows()
-- Returns: (rowsList , id→row table)
-----------------------------------------------------------------
local function collectRows()
local rows = ed.getExternalData()
local byId = {}
for _, r in ipairs( rows ) do
byId[ r.id ] = r
end
return rows, byId
end
-----------------------------------------------------------------
-- renderVideos( frame )
-- Renders the cards for one category (passed as |category=...)
-----------------------------------------------------------------
function p.renderVideos( frame )
local category = ( frame.args.category or '' ):lower()
local rows = ed.getExternalData()
local out = { '<div class="video-grid">' }
for _, v in ipairs( rows ) do
if ( v.category or '' ):lower() == category then
out[#out+1] = string.format(
'<div class="video-card" data-video-id="%s">' ..
'<div class="video-thumbnail" style="background-image:url(%s)"></div>' ..
'<div class="video-info"><span class="video-title">%s</span></div>' ..
'</div>',
v.id,
mw.uri.encode( v.thumbnail_url or '', 'PATH' ),
mw.text.nowiki( v.title or '' )
)
end
end
out[#out+1] = '</div>'
return table.concat( out )
end
-----------------------------------------------------------------
-- getVideoData()
-- Emits one big JSON blob keyed by id → row (for JS)
-----------------------------------------------------------------
function p.getVideoData()
local _, byId = collectRows()
return json( byId )
end
return p
