Git Product home page Git Product logo

felix-berlin / astro-breadcrumbs Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 6.0 2.84 MB

Well configurable breadcrumb component for Astro.js. Create breadcrumbs completely dynamically or specify exactly how they should look.

Home Page: https://docs.astro-breadcrumbs.kasimir.dev

License: GNU General Public License v3.0

Astro 15.29% TypeScript 71.25% SCSS 12.79% JavaScript 0.67%
a11y astrojs breadcrumbs breadcrumbs-generator css navigation sass scss structured-data ui withastro zero-config

astro-breadcrumbs's Introduction

Metrics

Daily.dev profile

Felix Scholze's Dev Card

astro-breadcrumbs's People

Contributors

dependabot[bot] avatar felix-berlin avatar renovate[bot] avatar semantic-release-bot avatar sudovanilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

astro-breadcrumbs's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v4
  • pnpm/action-setup v2
  • actions/setup-node v4
.github/workflows/unit-test.yml
  • pnpm/action-setup v2
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
npm
demo/package.json
  • @astrojs/mdx ^3.0.1
  • astro ^4.9.2
  • sass ^1.77.4
  • pnpm 9.4.0
docs/package.json
  • @astrojs/starlight ^0.24.0
  • astro ^4.9.2
  • astro-breadcrumbs ^2.3.1
  • astro-matomo ^1.6.0
  • sharp ^0.33.4
  • starlight-links-validator ^0.9.0
  • sass ^1.77.4
  • pnpm 9.4.0
package.json
  • @semantic-release/changelog ^6.0.3
  • @semantic-release/git ^10.0.1
  • @vitest/coverage-v8 ^1.6.0
  • jsdom ^24.1.0
  • prettier ^3.3.0
  • prettier-plugin-astro ^0.14.0
  • semantic-release ^23.1.1
  • vitest ^1.6.0
  • astro ^2.0.0-beta.0 || ^3.0.0 || ^4.0.0
  • pnpm 9.4.0

  • Check this box to trigger a request for Renovate to run again on this repository

Slash in base breaks breadcrumbs

Describe the bug
I need to set a base in astro.config.mjs that contains a slash, like foo/bar.
This unfortunately is not handled correctly, as it generates both a "Home" and homepage-name link on the home page (same for deeper pages). The "Home" link also goes back one level too deep, i.e. it links to /foo.

To Reproduce
Set the base property in astro.config.mjs to foo/bar.

Expected behavior
The "Home" crumb links to foo/bar and there is not an additional link for the home page.

baseurl for headless sites

Can you add this feature back please?
My is a headless frontend for Drupal and Strapi.
I have basicly 2 baseurls for the breadcrums:
/strapi/en/about-us
/drupal/en/about-us

But both should only show About Us as the breadcrumb. With the remove of the baseUrl parameter this is not possible anymore. @felix-berlin

Originally posted by @DavithkbY in #187 (comment)

Add optional schema.org markup

https://schema.org/BreadcrumbList - description of the markup. It helps for SEO.

It would be nice to have this markup as an option in your package.

Breadcrumbs without markup:

<ol>
  <li>
    <a href="https://example.com/dresses">Dresses</a>
  </li>
  <li>
    <a href="https://example.com/dresses/real">Real Dresses</a>
  </li>
</ol>

Breadcrumbs with Microdata markup:

<ol itemscope itemtype="https://schema.org/BreadcrumbList">
  <li itemprop="itemListElement" itemscope
      itemtype="https://schema.org/ListItem">
    <a itemprop="item" href="https://example.com/dresses">
    <span itemprop="name">Dresses</span></a>
    <meta itemprop="position" content="1" />
  </li>
  <li itemprop="itemListElement" itemscope
      itemtype="https://schema.org/ListItem">
    <a itemprop="item" href="https://example.com/dresses/real">
    <span itemprop="name">Real Dresses</span></a>
    <meta itemprop="position" content="2" />
  </li>
</ol>

Wrong behavior when using a base URL different from /

Describe the bug
When modifying the base parameter, the breadcrumbs crumbles.

You should drop the baseUrl prop and use import.meta.env.BASE_URL instead ?

To Reproduce
Steps to reproduce the behavior:

  1. npm run dev -- --base /astro/
  2. Gives : Home > astro > my page when browsing http://localhost:4321/astro/my-page/
    Home is linked to http://localhost:4321/ (which gives an error of course).

Expected behavior
Home > my page when base is set to /astro and browsing http://localhost:4321/astro/my-page/
Home should be linked to http://localhost:4321/astro/

Additional context
I'm using 'trailingSlash': 'always' which report a warning :

Astro Breadcrumbs Base URL should not have a trailing slash. Falling back to relative URL.

I don't understand why a base URL should not have a trailing slash.

Thank you for your job ๐Ÿ‘

Thanx and - how to install?

After the CLI-Installation and the copy and pasting as described, no output is occuring. Does it need two additional lines in astro.config.mjs like this?

import breadcrumbs from "@astrojs/breadcrumbs"; 
...
 breadcrumbs()

Is it possible to put the Component into the Layout or does it have to be in the page? Can it handle paths generated with getStaticPaths() too?

Thanks a lot for the work!!

Last Breadcrumb Custom Text Option

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚
Today I used patch-package to patch [email protected] for the project I'm working on.

I was having an issue where if the URL for example is products/category1/123, I wanted the breadcrumbs to be as follows with sentence case enabled:

Products > Category1 > Product Name

But by default, I get:

Products > Category1 > 123

So I only wanted to change the lastItem text, so I added variable lastText to fix such a scenario

Here is the small fix that solved my problem:

diff --git a/node_modules/astro-breadcrumbs/src/Breadcrumbs.astro b/node_modules/astro-breadcrumbs/src/Breadcrumbs.astro
index bc494bc..622e140 100644
--- a/node_modules/astro-breadcrumbs/src/Breadcrumbs.astro
+++ b/node_modules/astro-breadcrumbs/src/Breadcrumbs.astro
@@ -13,6 +13,7 @@ export interface BreadcrumbsProps {
   ellipsisAriaLabel?: string;
   truncated?: boolean;
   linkTextFormat?: "lower" | "capitalized" | "sentence";
+  lastText?: string;
   customBaseUrl?: string;
   excludeCurrentPage?: boolean;
 }
@@ -32,6 +33,7 @@ const {
   ellipsisAriaLabel = "Show hidden navigation",
   truncated = false,
   linkTextFormat,
+  lastText,
   customBaseUrl,
   excludeCurrentPage = false,
 } = Astro.props as BreadcrumbsProps;
@@ -49,6 +51,7 @@ const parts = generateCrumbs({
   linkTextFormat,
   customBaseUrl,
   excludeCurrentPage,
+  lastText,
 });
 
 const isLastElement = (index: number, array: any[]) =>
diff --git a/node_modules/astro-breadcrumbs/src/lib/generateCrumbs.ts b/node_modules/astro-breadcrumbs/src/lib/generateCrumbs.ts
index 39384d2..0b97699 100644
--- a/node_modules/astro-breadcrumbs/src/lib/generateCrumbs.ts
+++ b/node_modules/astro-breadcrumbs/src/lib/generateCrumbs.ts
@@ -9,6 +9,7 @@ type GenerateCrumbs = {
   linkTextFormat: BreadcrumbsProps["linkTextFormat"];
   customBaseUrl: BreadcrumbsProps["customBaseUrl"];
   excludeCurrentPage: BreadcrumbsProps["excludeCurrentPage"];
+  lastText: BreadcrumbsProps["lastText"];
 };
 
 export const generateCrumbs = ({
@@ -19,6 +20,7 @@ export const generateCrumbs = ({
   linkTextFormat,
   customBaseUrl,
   excludeCurrentPage,
+  lastText,
 }: GenerateCrumbs) => {
   /**
    * If crumbs are passed, use them.
@@ -113,5 +115,9 @@ export const generateCrumbs = ({
     parts.pop();
   }
 
+  if (lastText) {
+    parts[parts.length - 1].text = lastText;
+  }
+
   return parts;
 };

This issue body was partially generated by patch-package.

Resolving Trailing Slash Issue in Breadcrumbs Links

I'm encountering an issue with the using astro-breadcrumbs with Astrowind template on my website. I'm using the astro-breadcrumbs integration to display breadcrumbs. However, after running the build command pnpm run build, the links in the breadcrumbs are having trailing slashes appended to them, despite having set the trailing slash option to "never." Additionally, I've included trailingSlash={false} in the Breadcrumb component for added assurance. It seems the problem only pertains to the links generated by the breadcrumbs. Can you suggest any potential solutions?

Make it possible to not show the last (current) crumb

Thanks for this package!

The breadcrumbs now always show the current page as well, but in our case we usually display that page title as a header right below the breadcrumbs. So it looks a bit redundant.

It would be nice if there is a property to not display the last/current crumb.

Format the text links

Is your feature request related to a problem? Please describe.
I'd like the text of the links to be formatted without the "-" hyphen.

Describe the solution you'd like
You should be able to replace the hyphen with a space and decide which kind of formatted text you'd like.

Describe alternatives you've considered

export function unslugify(slug: string, {
    separator = "-",
    replaceWith = " ",
    format = "none",
} = {}): string | undefined {
    // Throw an error if the slug parameter is not a valid non-null string
    if (!slug || typeof slug !== "string") {
        throw new Error("Slug must be a non-null string");
    }

    // First remove extra separator
    slug = slug.replace(new RegExp(`[${separator}]+`, "g"), separator);

    // Split the slug on the separator,
    // replace the separator with the desired string then trim unecessary whitespace
    const unslugified = slug.split(separator).join(replaceWith).trim();

    switch (format) {
        case "none":
            return unslugified;

        case "lowercase":
            return unslugified.toLowerCase();

        case "uppercase":
            return unslugified.toUpperCase();

        case "capitalize":
            return unslugified.replace(/\w\S*/g, (txt) => {
                return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
            });

        case "capitalize-first":
            return unslugified.charAt(0).toUpperCase() + unslugified.substring(1).toLowerCase();

        default:
            return unslugified
    }
}

Additional context
I'm no professional developer so you should check the code but it seems pretty straightforward.

why vertical

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

astro latest
image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.