Content added Content deleted
(Created page with "local getArgs = require('Module:Arguments').getArgs local StoryInfo = require('Module:Story info')._main local p = {} 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 title = string.format( "%s: %s", utils.editIfNil(chapter), utils.editIfNil(english) ) if japanese or romaji then title = title .. string....") |
mNo edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
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 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 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) |
function p.main(frame) |
||
Line 11: | Line 86: | ||
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( |
||
"%s: %s", |
"Chapter %s: %s", |
||
utils.editIfNil(chapter), |
utils.editIfNil(chapter), |
||
utils.editIfNil(english) |
utils.editIfNil(english) |
||
Line 27: | Line 105: | ||
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( |
|||
-- "%s Chapter %s: %s - %s", |
|||
-- event, |
|||
-- chapter, |
|||
-- english or japanese, |
|||
-- mw.site.siteName |
|||
-- ), |
|||
-- title_mode = 'replace', |
|||
-- } |
|||
end |
|||
return StoryInfo(args) |
return StoryInfo(args) |
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