A plugin for creating hierarchical navigation in Astro projects. Supports breadcrumbs too!

Overview

astro-navigation

A plugin for creating hierarchical navigation in Astro projects. Supports breadcrumbs too!

Full docs coming soon!

Basic usage

This packages adds two components useful for building hierarchical navigation in Astro.

Just use Astro.glob() to find your local Markdown and MDX pages, pass them to the <Navigation /> component and you're all set!

component

This is the main component, building the HTML for a sorted navigation menu. Include a bit of frontmatter on each .md or .mdx page and the component will handle sorting and nesting pages automatically.

In your layout or page, use Astro.glob() to find all Markdown or MDX pages that should be included in the navigation menu. The <Navigation> component will build the list itself but leaves rendering a <nav> element to your app.

---
import Navigation from 'astro-navigation'
import type { PageFrontmatter } from 'astro-navigation'

const pages = await Astro.glob<PageFrontmatter>('../content/**/*.md')
---

<nav aria-label="Navigation menu" id="navigation">
    <Navigation pages={pages} />
</nav>

<style is:global>
#navigation ol {
    padding: 0;
}

#navigation li {
    line-height: 2;
}
<style>

Each markdown or MDX file should include navigation.order in its frontmatter. This order is used to sort sibling pages. Nesting is based on the url provided by Astro.glob() and can be overridden with a permalink frontmatter property, if needed.

---
title: Example site # text used in the menu, if `navigation.title` is not provided
permalink: /post-1 # URL for the page, if `url` is not provided by `Astro.glob()`
navigation:
  order: 1 # used to sort sibling pages
  title: My Awesome page # (optional) overrides the `title` frontmatter used above
---

# My awesome page

component

The API surface for breadcrumbs is very similar. Astro.glob() your pages and pass them to the component, it will automatically generate a list of breadcrumbs for the current page. Again, this doesn't render the <nav> element since the specific use case varies between sites.

The <Breadcrumbs> component will automatically include ld+json structured data for your breadcrumbs! This information is often used by search engines to add breadcrumbs to search results.

---
import { Breadcrumbs } from 'astro-navigation'
import type { PageFrontmatter } from 'astro-navigation'

const pages = await Astro.glob<PageFrontmatter>('../content/**/*.md')
---

<nav aria-label="Breadcrumbs" id="breadcrumbs">
    <!-- `<ul>` is used by default, this can be overridden with the "as" prop -->
    <Breadcrumbs pages={pages} as="ol" />
</nav>

<style is:global>
#breadcrumbs ol {
    list-style: none;
    display: flex;
    column-gap: 2ch;
}

#breadcrumbs a {
    text-decoration: none;
}

#breadcrumbs a:is(:hover, :focus-visible) {
    text-decoration: underline;
}
</style>
Comments
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    • 384f316: Upgrades to the latest version of Astro and uses the new astro/types interfaces

    Patch Changes

    • fbd6bb8: Fixing formatting error of readme file in npm
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    • a4f11af: feat: adds support for .astro pages :rocket:
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • f5192e2: fix: fixes dependency graph
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    • 3b7ca3d: fixes a mismatch between "name" and "title" frontmatter naming.

    Patch Changes

    • ee4fd2b: chore: linter fixes
    • 51c0395: @type is now defaulted to "WebPage" when not provided in a page's frontmatter
    • d44cff3: Fixes a link in the package.json metadata
    • 881aef2: fix: navigation.permalink frontmatter was being ignored
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • 0f8d703: Updates package metadata for NPM deployments
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Patch Changes

    • 1e98d8a: Always include the WebPage ld+json schema in
    opened by github-actions[bot] 0
  • [ci] release

    [ci] release

    This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

    Releases

    [email protected]

    Minor Changes

    • 21ec11c: Updates the components to handle globbing /src/content/pages internally, no more passing your own Astro.glob() results!
    • e1076b9: Adds a new <Pagination> component for next/previous links
    opened by github-actions[bot] 0
  • Possible to override the directory structure?

    Possible to override the directory structure?

    I'm not sure if this is the right place to bring this up. But I was wondering if there can be a setting that allows us to define the directory structure that astro navigation should follow to look for content?

    So instead of /src/content/pages/, can we tell it to look for content in /src/pages/*/

    opened by mayankguptadotcom 0
Releases(v0.4.0)
  • v0.4.0(Nov 2, 2022)

    Minor Changes

    • 384f316: Upgrades to the latest version of Astro and uses the new astro/types interfaces

    Patch Changes

    • fbd6bb8: Fixing formatting error of readme file in npm
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Oct 30, 2022)

  • v0.2.1(Oct 30, 2022)

  • v0.2.0(Oct 30, 2022)

    Minor Changes

    • 3b7ca3d: fixes a mismatch between "name" and "title" frontmatter naming.

    Patch Changes

    • ee4fd2b: chore: linter fixes
    • 51c0395: @type is now defaulted to "WebPage" when not provided in a page's frontmatter
    • d44cff3: Fixes a link in the package.json metadata
    • 881aef2: fix: navigation.permalink frontmatter was being ignored
    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Sep 25, 2022)

  • v0.1.1(Sep 25, 2022)

  • v0.1.0(Sep 25, 2022)

    Minor Changes

    • 21ec11c: Updates the components to handle globbing /src/content/pages internally, no more passing your own Astro.glob() results!
    • e1076b9: Adds a new <Pagination> component for next/previous links
    Source code(tar.gz)
    Source code(zip)
Owner
Tony Sullivan
Tony Sullivan
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Auto-import components in Astro projects

Astro Auto Import ?? Looking for the main package? Jump to astro-auto-import → ?? Project Structure This project uses workspaces to develop a single p

Chris Swithinbank 22 Dec 30, 2022
Hierarchical Converter for Array of Objects

Conversor Hierárquico para Array de Objetos - Hierarchical Converter to Array of Objects Docker-compose Cria a interface network e containers indicado

Victor Vinícius Eustáquio de Almeida 2 Jan 27, 2022
Neo: Hierarchical Confusion Matrix Visualization

Neo: Hierarchical Confusion Matrix The confusion matrix, a ubiquitous visualization for helping people evaluate machine learning models, is a tabular

Apple 252 Dec 15, 2022
The Easel Javascript library provides a full, hierarchical display list, a core interaction model, and helper classes to make working with the HTML5 Canvas element much easier.

EaselJS EaselJS is a library for building high-performance interactive 2D content in HTML5. It provides a feature-rich display list to allow you to ma

CreateJS 8k Dec 29, 2022
Minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets

micro-ed25519-hdkey Secure, minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets. Uses audited @noble/ed25519 under the hood. B

Paul Miller 11 Dec 25, 2022
JSPro is nothing but JavaScript Prototypes! The publisher is too lazy to write full name that's why it's just JSPro.

JSPro is nothing but JavaScript Prototypes! The publisher is too lazy to write full name that's why it's just JSPro. Whatever, it's a library of hundreds of awesome JavaScript Prototypes (you may know it as dot function) for lazy programmers. Just install the package with a little effort and leave the blames for the publisher.

Jafran Hasan 2 Mar 10, 2022
A custom select dropdown. This is something that is not too difficult to make.

Custom-Dropdown-JS A custom select dropdown using basic JS fucntionality. This is something that is not too difficult to make. But it shows that you h

Devanshu Vashishtha 2 Mar 26, 2022
Is your site too light? Make it heavy with a single script!

heavy.js Is your site too light? Need more pizzaz? Make it heavy with a single, zero dependency script. How to? Just add this snippet to your HTML: <s

Akshit Garg 59 Dec 18, 2022
A mini figure Doctor Strange platformer game with doctor strange variants to fight monsters. Give a star and fork too.

Doctor Strange : The Game This is a Doctor Strange variants based platformer game made in GDevelop. This game have 5 levels where you fight monsters a

Chandula Janith 6 Nov 5, 2022
I want to catch the best scene of my life. The browser wants to, too.

Scroll Cat I want to catch the best scene of my life. The browser wants to, too. There are too many good works in the world that are a hundred times b

木杉 14 Sep 6, 2022
A good looking help command made with discord.js with select menus. Works with prefix and slash commands too!

fancy-help-command A good looking help command made with discord.js with select menus. Works with prefix and slash commands too! Dependencies: Select

LunarCodes 11 Dec 12, 2022
This site compares your GitHub Profile to your friends, and analyses and tells your GitHub profile score too.

GitHub ⚔️ Duel Deployed at ?? : https://githubduel.vercel.app/ Compare your GitHub profiles with your friends It gives score to GitHub profile based o

Anshuman swain 17 Nov 21, 2022
A tiny script and component intended to be used with Astro for generating images with eleventy-img.

Astro + eleventy-img A tiny script and component intended to be used with Astro for generating images with eleventy-img. It also supports creating blu

Erika 36 Dec 16, 2022
Astro 1.0 Hackathon submission

title published description tags cover_image Trying out Astro SSR & Astro 1.0 Hackaton false astro, ssr, webcomponents, hackathon https://imgur.com/lV

Pascal Schilp 26 Jan 2, 2023
🦔 AstroJS GoogleChromeLabs critters integration. Inline your critical CSS with Astro.

astro-critters ?? This Astro integration brings critters to your Astro project. Critters is a plugin that inlines your app's critical CSS and lazy-loa

Nikola Hristov 33 Dec 11, 2022