Content added Content deleted
No edit summary |
(add description based on input to template) |
||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local StoryInfo = require('Module:Story info')._main |
local StoryInfo = require('Module:Story info')._main |
||
local |
local QueryBuilder = require('Module:QueryBuilder') |
||
local utils = require('Module:Utilities') |
|||
local p = {} |
local p = {} |
||
local numberToString = { |
|||
['1'] = 'first', |
|||
['2'] = 'second', |
|||
['3'] = 'third', |
|||
['4'] = 'fourth', |
|||
['5'] = 'fifth', |
|||
['6'] = 'sixth', |
|||
['7'] = 'seventh', |
|||
['8'] = 'eight', |
|||
['9'] = 'ninth', |
|||
['10'] = 'tenth', |
|||
['11'] = 'eleventh', |
|||
['12'] = 'twelfth', |
|||
} |
|||
function getEventName(eventId) |
|||
local qb = QueryBuilder.new() |
|||
qb |
|||
:setTables('events') |
|||
:setFields([[ |
|||
_pageName, |
|||
event_name, |
|||
]]) |
|||
:setGroupBy('_pageName') |
|||
:setLimit(1) |
|||
:addWhere('event_id', '=', eventId) |
|||
local result = qb:query()[1] |
|||
if result then |
|||
return result.event_name |
|||
end |
|||
return nil |
|||
end |
|||
function makeSeoDescription(english, japanese, chapter, event, characters) |
|||
local description = nil |
|||
if (english or japanese) and chapter and event then |
|||
description = string.format( |
|||
"\"%s\" is the %s chapter of %s's story.", |
|||
english or japanese, |
|||
numberToString[chapter], |
|||
event |
|||
) |
|||
if characters then |
|||
description = description .. |
|||
string.format( |
|||
" It features %s", |
|||
mw.text.listToText(util.splitWithDelim(';')(characters)) |
|||
) |
|||
end |
|||
end |
|||
return description |
|||
end |
|||
function p.main(frame) |
function p.main(frame) |
||
Line 12: | Line 72: | ||
local japanese = args['japanese'] |
local japanese = args['japanese'] |
||
local romaji = args['romaji'] |
local romaji = args['romaji'] |
||
local characters = args['characters'] |
|||
local eventId = args['event id'] |
|||
local title = string.format( |
local title = string.format( |
||
Line 29: | Line 92: | ||
args['title'] = title |
args['title'] = title |
||
if mw.title.getCurrentTitle().namespace == 0 then |
|||
local event = getEventName(eventId) |
|||
mw.ext.seo.set{ |
|||
description = makeSeoDescription(english, japanese, chapter, event, characters), |
|||
-- title = string.format( |
-- title = string.format( |
||
-- "Chapter %s: %s", |
-- "Chapter %s: %s", |
||
Line 38: | Line 103: | ||
-- title_mode = 'replace', |
-- title_mode = 'replace', |
||
-- site_name = mw.site.siteName |
-- site_name = mw.site.siteName |
||
} |
|||
end |
|||
return StoryInfo(args) |
return StoryInfo(args) |
Revision as of 02:48, 22 April 2022
This module depends on the following other modules: |
This module uses the following Cargo tables: |
To generate {{Event story chapter info}}, invoke using the main function.
local getArgs = require('Module:Arguments').getArgs
local StoryInfo = require('Module:Story info')._main
local QueryBuilder = require('Module:QueryBuilder')
local utils = require('Module:Utilities')
local p = {}
local numberToString = {
['1'] = 'first',
['2'] = 'second',
['3'] = 'third',
['4'] = 'fourth',
['5'] = 'fifth',
['6'] = 'sixth',
['7'] = 'seventh',
['8'] = 'eight',
['9'] = 'ninth',
['10'] = 'tenth',
['11'] = 'eleventh',
['12'] = 'twelfth',
}
function getEventName(eventId)
local qb = QueryBuilder.new()
qb
:setTables('events')
:setFields([[
_pageName,
event_name,
]])
:setGroupBy('_pageName')
:setLimit(1)
:addWhere('event_id', '=', eventId)
local result = qb:query()[1]
if result then
return result.event_name
end
return nil
end
function makeSeoDescription(english, japanese, chapter, event, characters)
local description = nil
if (english or japanese) and chapter and event then
description = string.format(
"\"%s\" is the %s chapter of %s's story.",
english or japanese,
numberToString[chapter],
event
)
if characters then
description = description ..
string.format(
" It features %s",
mw.text.listToText(util.splitWithDelim(';')(characters))
)
end
end
return description
end
function p.main(frame)
local args = getArgs(frame)
local chapter = args['chapter']
local english = args['english']
local japanese = args['japanese']
local romaji = args['romaji']
local characters = args['characters']
local eventId = args['event id']
local title = string.format(
"Chapter %s: %s",
utils.editIfNil(chapter),
utils.editIfNil(english)
)
if japanese or romaji then
title = title .. string.format(
"<br>%s (%s)",
utils.editIfNil(japanese),
utils.editIfNil(romaji)
)
end
args['title'] = title
if mw.title.getCurrentTitle().namespace == 0 then
local event = getEventName(eventId)
mw.ext.seo.set{
description = makeSeoDescription(english, japanese, chapter, event, characters),
-- title = string.format(
-- "Chapter %s: %s",
-- chapter,
-- english or japanese
-- ),
-- title_mode = 'replace',
-- site_name = mw.site.siteName
}
end
return StoryInfo(args)
end
return p