Actions

Module

Module:Breadcrumbs

From Dune Awakening DB

Documentation for this module may be created at Module:Breadcrumbs/doc

local p = {}

function p.render(frame)
  local title = mw.title.getCurrentTitle().text

  -- Fetch breadcrumb rows for the current page
  local rows = mw.ext.externalData.getExternalData({
    source = "externaldb",
    from = "site_breadcrumbs",
    where = "page_title='" .. title:gsub("'", "''") .. "'",
    data = "level=level,label=label,url=url",
  })

  if not rows or #rows == 0 then return '' end

  -- Sort by breadcrumb level
  table.sort(rows, function(a, b)
    return tonumber(a.level) < tonumber(b.level)
  end)

  local html = mw.html.create('div')
    :addClass('dune-breadcrumb-nav')

  -- Home icon
  html:tag('a')
    :attr('id', 'duneLogoBtn')
    :addClass('dune-logo-btn')
    :tag('img')
      :attr('src', 'https://dunedb.com/images/9/99/HomeNavIcon.png')
      :attr('alt', 'DuneDB Logo')
      :addClass('dune-logo')
    :done()
  :done()

  -- Home link
  html:tag('a')
    :attr('href', 'https://dunedb.com/Main_Page')
    :addClass('breadcrumb-home-link')
    :wikitext('<span>Home</span>')
  :done()

  -- Add breadcrumb items
  for i, row in ipairs(rows) do
    html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done()
    if row.url and row.url ~= '' then
      html:tag('a'):attr('href', row.url):wikitext(row.label):done()
    else
      html:tag('span'):wikitext(row.label):done()
    end
  end

  return tostring(html)
end

return p