Module:Breadcrumb
Module:Breadcrumb
This module generates a breadcrumb navigation component for MediaWiki pages. The breadcrumb provides users with a visual representation of the page's hierarchy, linking back to the main page and a relevant category before displaying the current page.
Usage
The module is intended to be used in templates or directly in wiki pages via `#invoke`.
{{#invoke:Breadcrumb|breadcrumb | CategoryLink=Category:Example | CategoryName=Example Category | PAGENAME=Current Page }}
Parameters
- CategoryLink - The wiki link to the relevant category (without brackets, e.g., `Category:Example`).
- CategoryName - The display name of the category.
- PAGENAME - The name of the current page.
Behavior
The module generates a structured breadcrumb navigation with three levels: 1. **Home Link**: Links back to the main page, displaying a home icon. 2. **Category Link**: Displays the category as an intermediate step in the hierarchy. 3. **Current Page**: Displays the current page as non-clickable text.
It utilizes Bootstrap 4 classes for styling and includes SVG icons for a modern visual appearance.
Example Output
If the following invocation is used:
{{#invoke:Breadcrumb|breadcrumb | CategoryLink=Category:Manuscripts | CategoryName=Manuscripts | PAGENAME=Codex ABC }}
The output will be:
Home > Manuscripts > Codex ABC
(with appropriate HTML styling and icons)
Notes
- The CategoryLink parameter should not include square brackets.
- The breadcrumb styling relies on Bootstrap 4.
- The home link is hardcoded to `/Main Page`.
This module improves navigation usability, especially in structured content like Semantic MediaWiki categories.
local p = {}
function p.breadcrumb(frame)
local args = frame.args
local categoryLink = args["CategoryLink"] or ""
local categoryName = args["CategoryName"] or ""
local pageName = args["PAGENAME"] or ""
-- Create the html container
local html = mw.html.create('html')
-- Create the main container
local div = html:tag('div')
:attr('aria-label', 'breadcrumb')
local ol = div:tag('ol')
:addClass('breadcrumb bg-transparent p-0 m-0 d-flex align-items-center')
:css('list-style', 'none')
-- Home item
local li1 = ol:tag('li')
:addClass('breadcrumb-item d-flex align-items-center border-0 p-0')
local homeLink = li1:tag('a')
:attr('href', '/Main Page')
:addClass('text-dark d-flex align-items-center')
:css('text-decoration', 'none')
:css('font-size', '0.875rem')
:css('font-weight', 'normal')
:css('transition', 'font-weight 0.2s')
homeLink:wikitext([[
<svg style="width: 0.75rem; height: 0.75rem;" class="mr-2 mb-1" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="m19.707 9.293-2-2-7-7a1 1 0 0 0-1.414 0l-7 7-2 2a1 1 0 0 0 1.414 1.414L2 10.414V18a2 2 0 0 0 2 2h3a1 1 0 0 0 1-1v-4a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v4a1 1 0 0 0 1 1h3a2 2 0 0 0 2-2v-7.586l.293.293a1 1 0 0 0 1.414-1.414Z"/>
</svg>
Home
]])
-- Category item
local li2 = ol:tag('li')
:addClass('breadcrumb-item d-flex align-items-center border-0 p-0')
li2:wikitext([[
<svg style="width: 0.75rem; height: 0.75rem; margin: 0 0.5rem;" class="text-muted" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4"/>
</svg>
]])
local categoryLinkTag = li2:tag('a')
:attr('href', "/" .. categoryLink)
:addClass('text-dark')
:css('text-decoration', 'none')
:css('font-size', '0.875rem')
:css('font-weight', 'normal')
:css('transition', 'font-weight 0.2s')
categoryLinkTag:wikitext(categoryName)
-- Current page item
local li3 = ol:tag('li')
:addClass('breadcrumb-item d-flex align-items-center border-0 p-0')
:attr('aria-current', 'page')
li3:wikitext([[
<svg style="width: 0.75rem; height: 0.75rem; margin: 0 0.5rem;" class="text-muted" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4"/>
</svg>
]])
li3:tag('span')
:addClass('text-muted')
:css('font-size', '0.875rem')
:wikitext(pageName)
-- Return the parsed HTML
return frame:preprocess(tostring(html))
end
return p