No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
function pageNews.main(frame) | function pageNews.main(frame) | ||
local currentTitle = mw.title.getCurrentTitle().text | local currentTitle = mw.title.getCurrentTitle().text | ||
local empty = true | |||
-- Check if there are any interviews for this page | -- Check if there are any interviews for this page | ||
local tables = 'News' | local tables = 'News' | ||
Line 16: | Line 17: | ||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
if #results > 0 then | if #results > 0 then | ||
empty = false | |||
local ul = mw.html.create('ul') | local ul = mw.html.create('ul') | ||
local interviews = mw.html.create('div'):node(mw.html.create('h2'):wikitext('Interviews')):node(ul) | local interviews = mw.html.create('div'):node(mw.html.create('h2'):wikitext('Interviews')):node(ul) | ||
Line 25: | Line 27: | ||
end | end | ||
return container | if empty then | ||
return '<span class="d-none"></span>' | |||
else | |||
return container | |||
end | |||
end | end | ||
Revision as of 02:36, 11 October 2022
Documentation for this module may be created at Module:PageNews/doc
local cargo = mw.ext.cargo
local News = require('Module:NewsItem')
local pageNews = {}
function pageNews.main(frame)
local currentTitle = mw.title.getCurrentTitle().text
local empty = true
-- Check if there are any interviews for this page
local tables = 'News'
local fields = 'date, title, type, author, lang, source, trans_lang, translator, event, note, targets'
local cargoArgs = {
where = 'targets HOLDS "' .. currentTitle .. '" AND type="interview"',
orderBy = 'date'
}
local results = cargo.query(tables, fields, cargoArgs)
local container = mw.html.create('div')
if #results > 0 then
empty = false
local ul = mw.html.create('ul')
local interviews = mw.html.create('div'):node(mw.html.create('h2'):wikitext('Interviews')):node(ul)
for r = 1, #results do
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
end
container:node(interviews)
end
if empty then
return '<span class="d-none"></span>'
else
return container
end
end
function pageNews.object(result)
local object = {}
object.date = result.date
object.lang = result.lang
object.url = result.url
object.author = result.author
object.source = result.source
object.event = result.event
object.trans_lang = result.trans_lang
object.translator = result.translator
object.event = result.event
return object
end
return pageNews