Skip to content

Commit c78c127

Browse files
authored
fix: update word filtering and path generation in browse page (#156)
### Description <!-- Please add PR description (don't leave blank) - example: This PR [adds/removes/fixes/replaces] the [feature/bug/etc] --> This pull request updates the logic for browsing dictionary words by alphabet to use the `id` property instead of the deprecated `slug` property, and introduces a new utility function for building word slugs. The changes improve type safety and future-proof the code against upstream type changes. **Refactoring for type safety and future compatibility:** * Updated the filtering logic in `getStaticPaths` to use `word.id[0]` instead of `word.slug[0]`, addressing a TypeScript type issue and aligning with the latest data structure. ([src/pages/browse/[alpha]/[page].astroL20-R20](diffhunk://#diff-c87fe48708b5daee9f4aa138cb2970623ed74a334fa0912fef67f3a71905ee39L20-R20)) * Changed the word link rendering to use `buildWordSlug(word.id)` in combination with `buildWordPathname`, ensuring consistent slug generation from the new `id` property. ([src/pages/browse/[alpha]/[page].astroL48-R47](diffhunk://#diff-c87fe48708b5daee9f4aa138cb2970623ed74a334fa0912fef67f3a71905ee39L48-R47)) * Imported the new `buildWordSlug` utility from `lib/utils/index.js` to support the updated slug-building logic. ([src/pages/browse/[alpha]/[page].astroL7-R8](diffhunk://#diff-c87fe48708b5daee9f4aa138cb2970623ed74a334fa0912fef67f3a71905ee39L7-R8))
1 parent 2221e36 commit c78c127

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/pages/browse/[alpha]/[page].astro

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ALPHABETS } from "../../../../constants.js";
44
import BaseLayout from "../../../layouts/base.astro";
55
import Navbar from "../../../components/navbar.astro";
66
import Search from "../../../components/islands/search";
7-
import { buildWordPathname } from "../../../lib/utils/index.js";
87
import ContributionCTA from "../../../components/contribution-cta.astro";
8+
import { buildWordPathname, buildWordSlug } from "../../../lib/utils/index.js";
99
1010
const { page } = Astro.props;
1111
const params = Astro.params;
@@ -17,8 +17,7 @@ export const prerender = true;
1717
export async function getStaticPaths({ paginate }) {
1818
const dictionary = await getCollection("dictionary");
1919
return ALPHABETS.flatMap(alpha => {
20-
// @ts-expect-error - `slug` property is not defined in `CollectionEntry` type - see https://github.com/withastro/astro/issues/14070
21-
const filteredWords = dictionary.filter(word => word.slug[0] === alpha);
20+
const filteredWords = dictionary.filter(word => word.id[0] === alpha);
2221
return paginate(filteredWords, {
2322
params: { alpha },
2423
// pageSize: 1
@@ -45,7 +44,7 @@ export async function getStaticPaths({ paginate }) {
4544
<!-- Words List -->
4645
<div>
4746
{page.data.length ? page.data.map(word => (
48-
<a href={buildWordPathname(word.slug)}
47+
<a href={buildWordPathname(buildWordSlug(word.id))}
4948
class="flex items-center md:text-lg justify-between no-underline w-full p-4 even:bg-gray-100 hover:bg-gray-100/50"
5049
>
5150
<span>{ word.data.title }</span>

0 commit comments

Comments
 (0)