Skip to content

Commit

Permalink
Add support for header nav menu
Browse files Browse the repository at this point in the history
  • Loading branch information
durera committed Oct 24, 2024
1 parent f54dab6 commit 8b47c09
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
clean:
rm -rf dist/mkdocs_carbon-*

build: clean
. .venv/bin/activate && python -m build .

release: build
. .venv/bin/activate && python -m twine upload dist/*

serve:
. .venv/bin/activate && mkdocs serve -w docs -w mkdocs_carbon_theme
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
mkdocs-carbon
===============================================================================
[![PyPI - Version](https://img.shields.io/pypi/v/mkdocs-carbon)](https://pypi.org/project/mkdocs-carbon/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mkdocs-carbon)](https://pypi.org/project/mkdocs-carbon/)
[![PyPI - Downloads](https://pepy.tech/badge/mkdocs-carbon)](https://pepy.tech/project/mkdocs-carbon)

[Carbon Design System](https://github.com/carbon-design-system/carbon) theme for [mkdocs](https://github.com/mkdocs/mkdocs).

Very much in beta state right now, contributions welcomed.

- `v1.2` Support for Header Navigation Menu
- `v1.1` Support for Search
- `v1.0` Initial Release


Examples
-------------------------------------------------------------------------------
Expand All @@ -26,12 +34,20 @@ theme:
prefix: Durera
theme_header: g100
theme_sidenav: g90
header_nav_items:
- title: View on Github
url: https://github.com/durera/mkdocs-carbon
active: true
- title: View on PyPi
url: https://pypi.org/project/mkdocs-carbon/
target: _new

markdown_extensions:
- toc:
permalink: "¤"
```
Theme Configuration
-------------------------------------------------------------------------------
### Prefix
Expand All @@ -43,6 +59,11 @@ Easily switch between Carbon themes using `theme_sidenav` and `theme_header`, th
![alt text](docs/images/themes-1.png)
![alt text](docs/images/themes-2.png)

### Header Navigation Menu
The header navigation menu can be enabled by defining `header_nav_items` as a list of objects with `url` and `title`. Optionally control where the links open using `target`, or set a navigation item as active by adding `active` set to `true`.

![alt text](docs/images/header-nav-items.png)


Optional Page Metadata
-------------------------------------------------------------------------------
Expand All @@ -62,5 +83,7 @@ An orphaned page can be connected to the navigation structure by setting the `na

Fonts
-------------------------------------------------------------------------------
- https://fonts.google.com/specimen/IBM+Plex+Sans
- https://fonts.google.com/specimen/IBM+Plex+Mono
Fonts are packaged in the theme itself:

- [IBM Plex Sans (Light)](https://fonts.google.com/specimen/IBM+Plex+Sans)
- [IBM Plex Mono (Light)](https://fonts.google.com/specimen/IBM+Plex+Mono)
Binary file added docs/images/header-nav-items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ theme:
theme_header: g100
theme_sidenav: g90
include_search_page: true
header_nav_items:
- title: View on Github
url: https://github.com/durera/mkdocs-carbon
active: true
- title: View on PyPi
url: https://pypi.org/project/mkdocs-carbon/
target: _new

markdown_extensions:
- toc:
Expand Down
8 changes: 8 additions & 0 deletions mkdocs_carbon_theme/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
<cds-header-menu-button button-label-active="Close menu" button-label-inactive="Open menu"></cds-header-menu-button>
<cds-header-name href="{{ base_url }}" prefix="{{ config.theme.prefix }}">{{ config.site_name }}</cds-header-name>

{%- if config.theme.header_nav_items and config.theme.header_nav_items | length > 0 %}
<cds-header-nav menu-bar-label="{{ config.theme.prefix }} {{ config.site_name }}">
{%- for nav_item in config.theme.header_nav_items %}
<cds-header-nav-item {{ 'is-active' if nav_item.active }} target="{{ nav_item.target }}" href="{{ nav_item.url }}">{{ nav_item.title }}</cds-header-nav-item>
{%- endfor %}
</cds-header-nav>
{%- endif %}

<div class="cds--header__global">
<cds-search id="header-search" label-text="Search" cds-search-input="search-event" expandable></cds-search>
</div>
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "mkdocs-carbon"
version = "1.1.0"
version = "1.2.1"
description = "Carbon theme for MkDocs"
readme = "README.md"
license = "EPL-2.0"
Expand All @@ -18,6 +18,10 @@ classifiers = [
"Intended Audience :: Information Technology",
"License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Documentation",
]
dependencies = [
Expand Down

0 comments on commit 8b47c09

Please sign in to comment.