Module:SongsTable

From Angelina Jordan Wiki
Revision as of 12:59, 29 July 2024 by Most2dot0 (talk | contribs) (Module to handle songs data)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The code for this module can be found below its documentation. You can edit the code, edit the documentation, or purge the cache.

Work in Progress!!

This module is supposed to provide access to the list of song titles Angelina did. To (most of) the song titles also a selection of videos was attached (now removed). This list is stored in JSON format in the Data:Songs.json page.

The song data has initially be derived from the listing on the Songs page. The intention is, that listing can be instead genereated by this module. But in addition, it should be possible to use the data on other pages.

For example, a page for a song could use it to list the most relevant example renditions of that song.

The idea is not, that all details of the songs data, like the song info box on the songs page, is stored in this list.

In the past, the videos were stored in the Data:SongsToVideos.json JSON data together with the songs listing, which is assumed to be alphabetic. That was not the long term solution, and in the meantime the videos were removed and the page renamed to Data:Songs.json. It's envisioned, that this will later be generated from more generic tables. See User:Most2dot0/Ideas for more ideas on this.

ToDo

  • Add more representations of data, e.g. like on the "Songs" page.
  • Consider to have a seperate reference field ( or a list of references )
  • Either integrate AtoZ bar in table section headers, or a link to jump to it above
  • Add access with filters, e.g.
- for song title
- for orginals
  • Don't rely on videos included, but generate by using a seperate performances table, which links performances to songs, events, locations and videos.
  • Present some sort of "quality" indication

Examples

Complete Table

A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z

Script error: The function "renderCollapsibleTable" does not exist.

A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z

Code

[Edit module code]


local p = {}

local function fetchData()
    local json = mw.ext.data.get('Data:SongsToVideos')
    if not json then
        return nil, "Error fetching data"
    end
    local data = mw.text.jsonDecode(json)
    if not data then
        return nil, "Error decoding JSON"
    end
    return data
end

local function generateTableRow(song)
    local title = song.title
    local type = song.type or "cover"
    local typeDescription = (type == "original") and "Original" or "Cover"
    if type == "redirect" and song.actual then
        title = song.actual .. " (Redirect: " .. song.title .. ")"
    end

    local row = "|-\n| " .. title .. " || " .. typeDescription .. "\n"

    if song.videos and #song.videos > 0 then
        for _, video in ipairs(song.videos) do
            row = row .. "|-\n| colspan=\"2\" style=\"padding-left: 1em;\" | ["
                .. video.url .. " " .. video.title .. "] (" .. video.user
                .. ", accessed " .. video.accessed .. ")\n"
        end
    end

    return row
end

function p.renderTable(frame)
    local data, err = fetchData()
    if not data then
        return '<div class="error">Error: ' .. err .. '</div>'
    end

    local wikitable = '{| class="wikitable sortable"\n|-\n! Song Title !! Type\n'

    for _, song in ipairs(data) do
        wikitable = wikitable .. generateTableRow(song)
    end

    wikitable = wikitable .. "|}"

    return wikitable
end

return p