Module:BookInfo

From Little Tail Wiki
Revision as of 17:44, 2 March 2025 by Zoltier (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Book title

Book cover (IMAGE REQUIRED)
Info.
Japanese name Optional
Romanized name Optional
Author(s) Optional
Illustrator(s) Optional
Designer(s) Optional
Genre(s) Optional
Release date Optional
Chapters Optional
Pages Optional
ISBN Optional
Publisher Optional
Medium Optional
Website Optional


The BookInfo infobox lists basic facts about the article's featured book.

Infoboxes are put together via Capiunto, which calls upon a Lua-based module. This keeps infoboxes clean and easy to form.

In source editor, excluding any optional row will make that row not render. Leaving out any required fields will throw an error over the page. HTML tags can be used within the infobox if necessary.

Specific rows

  • Japanese name: The book's original title in Japanese
  • Romanized name: The book's Japanese title romanized
  • Author(s): The author(s) of the book
  • Illustrator(s): The illustrator(s) of the book
  • Designer(s): The designer(s) of the book's cover
  • Genre(s): The book's genre(s)
  • Release date: The date the book released
  • Chapters: The number of chapters in the book
  • Pages: The number of pages in the book
  • ISBN: The book's ISBN. Separate ISBNs by line and indicate the country of origin if necessary.
  • Publisher: The book's publisher
  • Medium: The type of book, such as artbook or light novel
  • Website: Website of the book

Usage

{{BookInfo
| title       = Infobox title
| headerstyle = (defaults to background-color:grey)
| image       = [[File:Unknown.png|200px]]
| caption     =  Book cover (IMAGE REQUIRED)
| ("Info.")
| ja_kanji = Optional
| ja_romaji = Optional
| authors = Optional
| illustrators = Optional
| designers = Optional
| genre = Optional
| date = Optional
| chapters = Optional
| pages = Optional
| isbn = Optional
| publisher = Optional
| medium = Optional
| website = Optional
}}



local capiunto = require 'capiunto'

local p = {}

function p.main(frame)
    local args = frame:getParent().args

    -- Set header style, defaulting to 'background-color:grey' if not provided
    local headerStyle = args.headerstyle and args.headerstyle ~= '' and
        string.format('background-color:%s;', args.headerstyle) or 'background-color:grey;'

    -- Create the infobox
    local retval = capiunto.create({
        title = args.title,--tostring(mw.title.getCurrentTitle()),
        headerStyle = headerStyle,
    })

    -- Add image and caption
    if args.image then
        retval:addImage(args.image, args.caption or '')
    end

    -- Add a general header
    retval:addHeader('Info.')

    -- Add rows only for fields that are not empty
    local rows = {
        { 'Japanese name', args.ja_kanji },
        { 'Romanized name', args.ja_romaji },
        { 'Author(s)', args.authors },
        { 'Illustrator(s)', args.illustrators },
        { 'Designer(s)', args.designers },
        { 'Genre(s)', args.genre },
        { 'Release date', args.date },
        { 'Chapters', args.chapters },
        { 'Pages', args.pages },
        { 'ISBN', args.isbn },
        { 'Publisher', args.publisher },
        { 'Medium', args.medium },
        { 'Website', args.website },

    }

    for _, row in ipairs(rows) do
        local label, value = row[1], row[2]
        if value and value ~= '' then
            retval:addRow(label, value)
        end
    end

    return retval
end

return p