Skip to content

Commit 3a312e0

Browse files
NetdocsCopilot
andcommitted
feat(theme): render repository source link in header
Add a Material-style .md-header__source block (icon + repo name) to the header, shown when repo_url is configured. New partials/source.html resolves the glyph via config.theme.icon.repo (default fontawesome/brands/git-alt) using the bundled icon set, and falls back to a URL-derived label when repo_name is unset. Overridable per site via custom_dir. The vendored Material CSS already ships the .md-header__source / .md-source styles (hidden below 60em). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 28abc4c commit 3a312e0

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/Netdocs.Theme.Material/templates/partials/header.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
</div>
2525
</div>
2626
</div>
27+
{{~ # Repository source link (icon + name) at the right — see partials/source.html.
28+
# Rendered only when config.repo_url is set; hidden on narrow viewports. ~}}
29+
{{~ if config.repo_url && (config.repo_url | string.strip) != "" ~}}
30+
<div class="md-header__source">
31+
{{ include "partials/source.html" }}
32+
</div>
33+
{{~ end ~}}
2734
{{~ # Version selector (versioning plugin) — see partials/version-select.html. ~}}
2835
{{ include "partials/version-select.html" }}
2936
{{~ # Social links (right) — see partials/social.html. ~}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{~ # ---------------------------------------------------------------------------
2+
# partials/source.html — Repository link (icon + name) shown at the top-right of
3+
# the header, mirroring Material for MkDocs' `.md-source`. Rendered only when a
4+
# repository URL is configured; hidden on narrow viewports by the theme CSS.
5+
#
6+
# Data: config.repo_url — link target (required; nothing renders without it)
7+
# config.repo_name — display text (falls back to the URL host/path)
8+
# config.theme.icon.repo — mkdocs-style icon name for the glyph
9+
# (default "fontawesome/brands/git-alt")
10+
#
11+
# Override: drop a file at `<custom_dir>/partials/source.html` to change how the
12+
# repository link renders. Return nothing to hide it.
13+
# --------------------------------------------------------------------------- ~}}
14+
{{~ repo_url = config.repo_url ~}}
15+
{{~ if repo_url && (repo_url | string.strip) != "" ~}}
16+
{{~ repo_icon = config.theme.icon.repo ~}}
17+
{{~ if !repo_icon || (repo_icon | string.strip) == "" ~}}{{~ repo_icon = "fontawesome/brands/git-alt" ~}}{{~ end ~}}
18+
{{~ repo_label = config.repo_name ~}}
19+
{{~ if !repo_label || (repo_label | string.strip) == "" ~}}{{~ repo_label = repo_url | string.replace "https://" "" | string.replace "http://" "" ~}}{{~ end ~}}
20+
<a href="{{ repo_url }}" title="{{ repo_label }}" class="md-source" data-md-component="source" target="_blank" rel="noopener">
21+
<div class="md-source__icon md-icon">
22+
{{ nav_icon repo_icon }}
23+
</div>
24+
<div class="md-source__repository">
25+
{{ repo_label }}
26+
</div>
27+
</a>
28+
{{~ end ~}}

0 commit comments

Comments
 (0)