Content added Content deleted
mNo edit summary |
mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 37: | Line 37: | ||
if result then |
if result then |
||
return result.event_name |
return result.event_name |
||
end |
|||
return nil |
|||
end |
|||
function makePossessive(noun) |
|||
if noun then |
|||
local lastChar = string.sub(noun, -1) |
|||
⚫ | |||
if lastChar == 's' then |
|||
return noun .. "'" |
|||
else |
|||
return noun .. "'s" |
|||
end |
|||
end |
end |
||
Line 47: | Line 61: | ||
if (english or japanese) and chapter and event then |
if (english or japanese) and chapter and event then |
||
description = string.format( |
description = string.format( |
||
"\"%s\" is the %s chapter of % |
"\"%s\" is the %s chapter of %s story.", |
||
english or japanese, |
english or japanese, |
||
numberToString[chapter], |
numberToString[chapter], |
||
event |
makePossessive(event) |
||
) |
) |
||
Line 93: | Line 107: | ||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
local event = getEventName(eventId) |
-- local event = getEventName(eventId) |
||
mw.ext.seo.set{ |
-- mw.ext.seo.set{ |
||
description = makeSeoDescription(english, japanese, chapter, event, characters), |
-- description = makeSeoDescription(english, japanese, chapter, event, characters), |
||
-- title = string.format( |
|||
-- "%s Chapter %s: %s - %s", |
|||
-- event, |
|||
-- chapter, |
|||
-- english or japanese |
|||
-- english or japanese, |
|||
⚫ | |||
⚫ | |||
-- ), |
|||
⚫ | |||
⚫ | |||
⚫ | |||
-- } |
|||
end |
end |
||
Latest revision as of 23:20, 4 May 2023
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 makePossessive(noun)
if noun then
local lastChar = string.sub(noun, -1)
if lastChar == 's' then
return noun .. "'"
else
return noun .. "'s"
end
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 story.",
english or japanese,
numberToString[chapter],
makePossessive(event)
)
if characters then
description = description ..
string.format(
" It features %s.",
mw.text.listToText(utils.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(
-- "%s Chapter %s: %s - %s",
-- event,
-- chapter,
-- english or japanese,
-- mw.site.siteName
-- ),
-- title_mode = 'replace',
-- }
end
return StoryInfo(args)
end
return p