Skip to content

Commit

Permalink
refactor: crumb generation
Browse files Browse the repository at this point in the history
BREAKING CHANGE: baseUrl and trailingSlash properties are now deprecated. Both values are now obtained directly from Astro Config.
  • Loading branch information
felix-berlin committed Feb 2, 2024
1 parent 6ab6630 commit 158df4d
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 425 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
![GitHub file size in bytes](https://img.shields.io/github/size/felix-berlin/astro-breadcrumbs/src/Breadcrumbs.astro?label=component%20size&logo=astro&style=flat-square)
![GitHub file size in bytes](https://img.shields.io/github/size/felix-berlin/astro-breadcrumbs/src/breadcrumbs.css?label=CSS%20Size&logo=CSS3&style=flat-square)
![GitHub file size in bytes](https://img.shields.io/github/size/felix-berlin/astro-breadcrumbs/src/breadcrumbs.scss?label=SCSS%20Size&logo=SASS&style=flat-square)
![GitHub file size in bytes](https://img.shields.io/github/size/felix-berlin/astro-breadcrumbs/src/lib/truncated.ts?label=Client%20JS%20size&logo=JS&style=flat-square)
![Dependent repos (via libraries.io)](https://img.shields.io/librariesio/dependent-repos/npm/astro-breadcrumbs?style=flat-square)

Well configurable breadcrumb component for [Astro](https://astro.build/).
Expand Down
8 changes: 5 additions & 3 deletions demo/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { defineConfig } from 'astro/config';
import { defineConfig } from "astro/config";

import mdx from "@astrojs/mdx";

// https://astro.build/config
export default defineConfig({
integrations: [mdx()]
});
base: "/astro-breadcrumbs",
trailingSlash: "always",
integrations: [mdx()],
});
20 changes: 20 additions & 0 deletions demo/src/pages/en/category/astro/one.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
import Layout from "../../../../layouts/Layout.astro";
import Breadcrumbs from "../../../../../../src/Breadcrumbs.astro";
---

<Layout title="Welcome to Astro Breadcrumbs.">
<main>
<h2>
Example 7 - With trailing slash
<Breadcrumbs />
</h2>
</main>
</Layout>
<style>
main {
margin: auto;
padding: 1em;
max-width: 60ch;
}
</style>
129 changes: 68 additions & 61 deletions demo/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
---
import Layout from "../layouts/Layout.astro";
import Card from "../components/Card.astro";
import Breadcrumbs from "../../../src/Breadcrumbs.astro";
---

<Layout title="Welcome to Astro Breadcrumbs.">
<main>
<h1>Welcome to <span class="text-gradient">Astro</span> Breadcrumbs</h1>
<p class="instructions">
Check out the <code>src/pages/en/category/astro/page.astro</code> directory
to see the code example.<br />
</p>
<ul role="list" class="link-card-grid">
<Card
href="/en/category/astro/page"
title="Examples"
body="Explore how to use Astro Breadcrumbs."
/>
<Card
href="https://github.com/felix-berlin/astro-breadcrumbs/"
title="Github"
body="Astro Breadcrumbs Github Page"
/>
</ul>
</main>
<main>
<h1>Welcome to <span class="text-gradient">Astro</span> Breadcrumbs</h1>
<Breadcrumbs />
<p class="instructions">
Check out the <code>src/pages/en/category/astro/page.astro</code> directory
to see the code example.<br />
</p>
<ul role="list" class="link-card-grid">
<Card
href="/en/category/astro/page"
title="Examples"
body="Explore how to use Astro Breadcrumbs."
/>
<Card
href="/astro-breadcrumbs/en/category/astro/page"
title="Examples using base url"
body="Explore how to use Astro Breadcrumbs."
/>
<Card
href="https://github.com/felix-berlin/astro-breadcrumbs/"
title="Github"
body="Astro Breadcrumbs Github Page"
/>
</ul>
</main>
</Layout>

<style>
main {
margin: auto;
padding: 1.5rem;
max-width: 60ch;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin: 0;
}
.text-gradient {
background-image: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 400%;
background-position: 0%;
}
.instructions {
line-height: 1.6;
margin: 1rem 0;
border: 1px solid rgba(var(--accent), 25%);
background-color: white;
padding: 1rem;
border-radius: 0.4rem;
}
.instructions code {
font-size: 0.875em;
font-weight: bold;
background: rgba(var(--accent), 12%);
color: rgb(var(--accent));
border-radius: 4px;
padding: 0.3em 0.45em;
}
.instructions strong {
color: rgb(var(--accent));
}
.link-card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
gap: 1rem;
padding: 0;
}
main {
margin: auto;
padding: 1.5rem;
max-width: 60ch;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin: 0;
}
.text-gradient {
background-image: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 400%;
background-position: 0%;
}
.instructions {
line-height: 1.6;
margin: 1rem 0;
border: 1px solid rgba(var(--accent), 25%);
background-color: white;
padding: 1rem;
border-radius: 0.4rem;
}
.instructions code {
font-size: 0.875em;
font-weight: bold;
background: rgba(var(--accent), 12%);
color: rgb(var(--accent));
border-radius: 4px;
padding: 0.3em 0.45em;
}
.instructions strong {
color: rgb(var(--accent));
}
.link-card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
gap: 1rem;
padding: 0;
}
</style>
14 changes: 4 additions & 10 deletions src/Breadcrumbs.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export interface BreadcrumbsProps {
ariaLabel?: string;
crumbs?: Array<BreadcrumbItem>;
schemaJsonScript?: boolean;
baseUrl?: string;
trailingSlash?: boolean;
ellipsisAriaLabel?: string;
truncated?: boolean;
}
Expand All @@ -26,25 +24,21 @@ const {
ariaLabel = "breadcrumbs",
crumbs = [],
schemaJsonScript = true,
baseUrl,
trailingSlash = false,
ellipsisAriaLabel = "Show hidden navigation",
truncated = false,
} = Astro.props as BreadcrumbsProps;
const hasBaseUrl = !!baseUrl?.length;
const paths = Astro.url.pathname.split("/").filter((crumb: any) => crumb);
const hasTrailingSlash = Astro.url.pathname.endsWith("/");
const pathLength = paths?.length;
const UUID = crypto.randomUUID();
const parts = generateCrumbs(
baseUrl,
const parts = generateCrumbs({
crumbs,
paths,
hasBaseUrl,
trailingSlash,
indexText,
);
hasTrailingSlash,
});
---

<astro-breadcrumbs
Expand Down
88 changes: 0 additions & 88 deletions src/lib/crumbUtils.ts

This file was deleted.

0 comments on commit 158df4d

Please sign in to comment.