Module:Citation/BCB: Difference between revisions
NeonWabbit (talk | contribs) No edit summary |
NeonWabbit (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local mw = require('mw') | local mw = require('mw') | ||
-- Function to format the BCB reference | -- Function to format the BCB reference | ||
Line 56: | Line 20: | ||
end | end | ||
mw.log('Matched Chapter: ' .. chapter .. ', Page: ' .. page) -- Log matched values | mw.log('Matched Chapter: ' .. tostring(chapter) .. ', Page: ' .. tostring(page)) -- Log matched values | ||
-- Retrieve the chapter data using the shared approach | -- Retrieve the chapter data using the shared approach | ||
local chapters = p.getChaptersList() | local chapters = p.getChaptersList() | ||
local chapter_title = chapters[chapter] | local chapter_title = chapters[chapter] | ||
if type(chapter_title) == 'table' then | |||
mw.log('Chapter title is a table, converting to string using mw.dumpObject') -- Handle table case | |||
chapter_title = mw.dumpObject(chapter_title) | |||
end | |||
if chapter_title then | if chapter_title then | ||
local result = string.format("Chapter %s: %s, page %s", chapter, chapter_title, page) | local result = string.format("Chapter %s: %s, page %s", tostring(chapter), tostring(chapter_title), tostring(page)) | ||
mw.log('Generated Result: ' .. result) -- Log the generated result | mw.log('Generated Result: ' .. result) -- Log the generated result | ||
return result | return result | ||
end | end | ||
mw.log('No matching chapter found for Chapter: ' .. chapter) -- Log if no matching chapter | mw.log('No matching chapter found for Chapter: ' .. tostring(chapter)) -- Log if no matching chapter | ||
return nil -- Return nil if no matching chapter is found | return nil -- Return nil if no matching chapter is found | ||
end | end | ||
return p | return p |
Revision as of 15:12, 12 November 2024
Documentation for this module may be created at Module:Citation/BCB/doc
local p = {}
local mw = require('mw')
-- Function to format the BCB reference
function p.formatBCBReference(url)
mw.log('Entering formatBCBReference with URL: ' .. (url or 'nil')) -- Log entry and URL
if not url or type(url) ~= 'string' then
mw.log('Invalid URL provided') -- Log invalid URL
return nil -- Return nil if `url` is not valid
end
-- Check if the URL matches the expected pattern
local chapter, page = url:match("^https://www%.bittersweetcandybowl%.com/c(%d+)/p(%d+)")
if not chapter then
chapter, page = url:match("^https://bcb%.cat/c(%d+)/p(%d+)")
end
if not chapter or not page then
mw.log('URL did not match expected pattern') -- Log if no match
return nil -- Return nil if the URL does not match
end
mw.log('Matched Chapter: ' .. tostring(chapter) .. ', Page: ' .. tostring(page)) -- Log matched values
-- Retrieve the chapter data using the shared approach
local chapters = p.getChaptersList()
local chapter_title = chapters[chapter]
if type(chapter_title) == 'table' then
mw.log('Chapter title is a table, converting to string using mw.dumpObject') -- Handle table case
chapter_title = mw.dumpObject(chapter_title)
end
if chapter_title then
local result = string.format("Chapter %s: %s, page %s", tostring(chapter), tostring(chapter_title), tostring(page))
mw.log('Generated Result: ' .. result) -- Log the generated result
return result
end
mw.log('No matching chapter found for Chapter: ' .. tostring(chapter)) -- Log if no matching chapter
return nil -- Return nil if no matching chapter is found
end
return p