Actions

Module

Module:ArmorBreadcrumb

From Dune Awakening DB

Revision as of 22:32, 9 April 2025 by Operator (talk | contribs) (Created page with "local p = {} function p.render(frame) local Html = mw.html local titleObj = mw.title.getCurrentTitle() local currentTitle = titleObj.text local rows = mw.ext.externalData.getExternalData({ source = "externaldb", from = "data_armor", where = "page_title='" .. currentTitle:gsub("'", "''") .. "'", data = "category_1=category_1,category_2=category_2,category_3=category_3" }) local cat1, cat2, cat3 if rows and #rows > 0 then cat1 = rows[1]...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.render(frame)
  local Html = mw.html
  local titleObj = mw.title.getCurrentTitle()
  local currentTitle = titleObj.text

  local rows = mw.ext.externalData.getExternalData({
    source = "externaldb",
    from = "data_armor",
    where = "page_title='" .. currentTitle:gsub("'", "''") .. "'",
    data = "category_1=category_1,category_2=category_2,category_3=category_3"
  })

  local cat1, cat2, cat3
  if rows and #rows > 0 then
    cat1 = rows[1].category_1 or ''
    cat2 = rows[1].category_2 or ''
    cat3 = rows[1].category_3 or currentTitle
  else
    cat1 = 'Armor'
    cat2 = 'Uncategorized'
    cat3 = currentTitle
  end

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

  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()

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

  local function addCrumb(label)
    html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done()
    html:tag('a')
      :attr('href', 'https://dunedb.com/wiki/' .. mw.uri.encode(label, 'PATH'))
      :wikitext(label)
    :done()
  end

  if cat1 ~= '' then addCrumb(cat1) end
  if cat2 ~= '' then addCrumb(cat2) end
  if cat3 ~= '' then
    html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done()
    html:tag('span'):wikitext(cat3):done()
  end

  return tostring(html)
end

return p