npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-navigation

v0.4.0

Published

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

Downloads

14

Readme

astro-navigation

A plugin for creating hierarchical navigation in Astro projects. Supports breadcrumbs and next/previous pagination too!

Full docs coming soon!

Basic usage

This packages adds three components useful for building hierarchical navigation in Astro. Just write your Markdown and MDX pages in src/content/pages and you're all set!

<Navigation /> builds a sorted hierarchical navigation menu, <Breadcrumbs /> adds an SEO-friendly breadcrumb list for the current page, and <Pagination /> adds next/previous navigation links.

<Navigation /> 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.

The <Navigation> component will build the list itself but leaves rendering a <nav> element to your app.

How it works

To build the menu, the <Navigation /> component:

  1. uses import.meta.glob to find all .md and .mdx files in /src/content/pages
  2. filters down to include only the files that include navigation.order frontmatter
  3. uses file-based routing similar to Astro's /src/pages directory to sort and nest pages in the menu
---
import Navigation from 'astro-navigation'
---

<nav aria-label="Navigation menu" id="navigation">
    <!-- `<ol>` is used by default, this can be overridden with the "as" prop -->
    <Navigation as="ul" />
</nav>

<style>
#navigation :global(ul) {
    padding: 0;
}

#navigation :global(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 navigation.permalink frontmatter property, if needed.

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

# My awesome page

<Breadcrumbs> component

The API surface for breadcrumbs is very similar. Pages are automatically discovered by using import.meta.glob to scan src/content/pages. 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'
---

<nav aria-label="Breadcrumbs" id="breadcrumbs">
    <Breadcrumbs aria-label="Breadcrumbs" />
</nav>

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

#breadcrumbs :global(a) {
    text-decoration: none;
}

#breadcrumbs :glboal(a:is(:hover, :focus-visible)) {
    text-decoration: underline;
}
</style>

<Pagination> component

The pagination component will build next/previous links, if available.

---
import { Pagination } from 'astro-navigation'
---

<nav aria-label="Pagination navigation">
    <Pagination prevLabel="Go to previous page" nextLabel="Go to next page" />
</nav>

<style>
nav :global(ol) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: 'prev' 'next';
}

nav :global([aria-label="Go to previous page"]) {
    grid-area: prev;
}

nav :global([aria-label="Go to next page"]) {
    grid-area: next;
}
<style>