BuildingBreadcrumb: Difference between revisions
From Dune Awakening DB
Created page with "local p = {} function p.render(frame) local title = mw.title.getCurrentTitle().text local rows = mw.ext.externalData.getExternalData({ source = "externaldb", from = "data_buildings", where = "page_title='" .. title:gsub("'", "''") .. "'", data = "category_1=category_1,category_2=category_2,category_3=category_3" }) if not rows or #rows == 0 then return '' end local cat1 = rows[1].category_1 or '' local cat2 = rows[1].category_2 or ''..." |
mNo edit summary |
||
| Line 2: | Line 2: | ||
function p.render(frame) | function p.render(frame) | ||
local | 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({ | local rows = mw.ext.externalData.getExternalData({ | ||
source = "externaldb", | source = "externaldb", | ||
from = "data_buildings", | from = "data_buildings", | ||
where = "page_title='" .. | where = "page_title='" .. 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" | ||
}) | }) | ||
if | -- 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 | end | ||
-- Create HTML breadcrumb | |||
local html = Html.create('div'):addClass('dune-breadcrumb-nav') | local html = Html.create('div'):addClass('dune-breadcrumb-nav') | ||
| Line 38: | Line 45: | ||
:done() | :done() | ||
local function | -- Add each breadcrumb level | ||
local function addCrumb(label) | |||
html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done() | html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done() | ||
html:tag('a'):attr('href', | html:tag('a') | ||
:attr('href', 'https://dunedb.com/wiki/' .. mw.uri.encode(label, 'PATH')) | |||
:wikitext(label) | |||
:done() | |||
end | end | ||
if cat1 ~= '' then | if cat1 ~= '' then addCrumb(cat1) end | ||
if cat2 ~= '' then addCrumb(cat2) end | |||
if cat2 ~= '' then | |||
if cat3 ~= '' then | if cat3 ~= '' then | ||
html:tag('span'):addClass('dune-breadcrumb-separator'):wikitext('/'):done() | |||
html:tag('span'):wikitext(cat3):done() | |||
end | end | ||
Revision as of 22:28, 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 = "page_title='" .. 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
