Actions

Module

BuildingBreadcrumb: Difference between revisions

From Dune Awakening DB

mNo edit summary
mNo edit summary
 
Line 10: Line 10:
     source = "externaldb",
     source = "externaldb",
     from = "data_buildings",
     from = "data_buildings",
     where = "page_title='" .. currentTitle:gsub("'", "''") .. "'",
     where = "name='" .. currentTitle:gsub("'", "''") .. "'",
     data = "category_1=category_1,category_2=category_2,category_3=category_3"
     data = "category_1=category_1,category_2=category_2,category_3=category_3"
   })
   })

Latest revision as of 23:00, 9 April 2025

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

local p = {}

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

  -- Try to get categories from the data_buildings table
  local rows = mw.ext.externalData.getExternalData({
    source = "externaldb",
    from = "data_buildings",
    where = "name='" .. currentTitle:gsub("'", "''") .. "'",
    data = "category_1=category_1,category_2=category_2,category_3=category_3"
  })

  -- Default values if nothing is found
  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 = 'Buildings'
    cat2 = 'Uncategorized'
    cat3 = currentTitle
  end

  -- Create HTML breadcrumb
  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()

  -- Add each breadcrumb level
  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