メニューを切り替える
個人設定メニューを切り替える
個人メニューを切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。
2026年8月6日 (木) 23:02時点におけるMifumi323 (トーク | 投稿記録)による版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

このモジュールについての説明文ページを モジュール:BasicData/doc に作成できます

local p = {}

function p.process(frame)
    local args = frame:getParent().args
    local result = p.generate(args)

    return frame:preprocess(result)
end

function p.generate(args)
    local string_utils = require('Module:StringUtils')
    
    local fields = {
        { key = 'ふりがな', val = args['ふりがな'] },
        { key = '正式名称', val = args['正式名称'] },
        { key = 'フルネーム', val = args['フルネーム'] },
        { key = '英字表記', val = args['英字表記'] },
        { key = '他の名前', val = args['他の名前'] },
        { key = '公式サイト', val = args['公式サイト'] },
        { key = '登場作品', val = args['登場作品'] },
        { key = '種族', val = args['種族'] },
        { key = '性別', val = args['性別'] },
        { key = '年齢', val = args['年齢'] },
        { key = '大きさ', val = args['大きさ'] },
        { key = '一人称', val = args['一人称'] },
        { key = '二人称', val = args['二人称'] },
    }
    
    local info_rows = {}
    local cargo_rows = {}

    for _, field in ipairs(fields) do
        -- 値が存在し、空文字列でない場合のみ行を生成
        if field.val and field.val ~= '' then
            local key = field.key
            local value = field.val
            if key == 'ふりがな' then
                local sortkey = string_utils.sortkey(value)
                table.insert(cargo_rows, string.format('Furigana = %s', value))
                table.insert(cargo_rows, string.format('FuriganaSort = %s', sortkey))
                if args['表示用ふりがな'] and args['表示用ふりがな'] ~= '' then
                    value = args['表示用ふりがな']
                end
                value = string.format('%s{{DEFAULTSORT:%s}}', value, sortkey)
            elseif key == '登場作品' then
                local titles = mw.text.split(value, '、', true)
                local converted_titles = {}
                for _, title in ipairs(titles) do
                    if title == 'ふにゃ(ゲーム)' then
                        table.insert(converted_titles, '[[ふにゃ(ゲーム)|ふにゃ]][[Category:登場作品:ふにゃ]]')
                    else
                        table.insert(converted_titles, string.format('[[%s]][[Category:登場作品:%s]]', title, title))
                    end
                end
                value = table.concat(converted_titles, '、')
            elseif key == '種族' then
                local kinds = mw.text.split(value, '、', true)
                local converted_kinds = {}
                for _, kind in ipairs(kinds) do
                    table.insert(converted_kinds, string.format('[[%s]][[Category:種族:%s]]', kind, kind))
                end
                value = table.concat(converted_kinds, '、')
            elseif key == '性別' then
                value = string.format('%s[[Category:性別:%s]]', value, value)
            end
            table.insert(info_rows, string.format('<tr><th>%s</th><td>%s</td></tr>', key, value))
        end
    end


    local result = ""
    
    if next(info_rows) then
        result = string.format("%s<table class=\"wikitable\">%s</table>", result, table.concat(info_rows, ""))
    end
    
    if next(cargo_rows) then
        result = string.format("%s{{#cargo_store:_table = BasicData|%s}}", result, table.concat(cargo_rows, "|"))
    end

    return result
end

return p