Skip to content

Commit 5979251

Browse files
committed
fix broken urls and featured links
1 parent c7ec5f9 commit 5979251

8 files changed

Lines changed: 54 additions & 42 deletions

File tree

src/components/ExternalArticle.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ const ExternalArticle: React.FC<FeaturedArticle> = (props) => {
5454
</div>
5555
<div className="group relative">
5656
<h3 className="mt-3 text-lg leading-6 font-semibold text-gray-900 group-hover:text-gray-600">
57-
<Link
58-
href={url}
59-
className="absolute inset-0 font-medium no-underline"
60-
toolSlug={toolSlug}
61-
linkType="featured_article"
62-
linkPlacementDescription="featured-article-card"
63-
>
64-
{title}
65-
</Link>
57+
{url ? (
58+
<Link
59+
href={url}
60+
className="font-medium no-underline after:absolute after:inset-0"
61+
toolSlug={toolSlug}
62+
linkType="featured_article"
63+
linkPlacementDescription="featured-article-card"
64+
>
65+
{title}
66+
</Link>
67+
) : (
68+
<span className="font-medium">{title}</span>
69+
)}
6670
</h3>
6771
<p className="mt-5 line-clamp-3 text-sm leading-6 text-gray-600">
6872
{description}

src/pages/categories/[...slug].astro

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ import { isModern } from '@/utils/versionFilters';
2323
export const getStaticPaths: GetStaticPaths = async () => {
2424
const categories = await getCollection('categories');
2525
return categories.map((category) => ({
26-
params: { slug: category.id },
26+
params: { slug: category.id.replace(/\.md$/, '') },
2727
props: { category },
2828
}));
2929
};
3030
3131
// 2. For your template, you can get the entry directly from the prop
32-
const { slug } = Astro.params;
33-
const category = await getEntry('categories', slug as string);
32+
const { category } = Astro.props;
3433
3534
if (!category) {
36-
throw new Error(`No category found for slug ${slug}`);
35+
throw new Error(`No category found for slug ${Astro.params.slug}`);
3736
}
3837
3938
const { Content } = await render(category);
4039
41-
// Note: category.id includes .md extension, but tool category references don't
42-
const categoryIdWithoutExt = category.id.replace(/\.md$/, '');
40+
const slug = category.id.replace(/\.md$/, '');
41+
const categorySlug = slug; // For comparing with tool category references
4342
4443
// Track if there are legacy tools in this category
4544
let hasLegacyTools = false;
@@ -55,7 +54,7 @@ const allTools = (await getCollection('tools')).filter((tool) => {
5554
const categories = tool.data.categories;
5655
// Check if tool belongs to this category
5756
const isInCategory = categories.some(
58-
(cat) => cat.id === categoryIdWithoutExt
57+
(cat) => cat.id === categorySlug
5958
);
6059
6160
if (!isInCategory) {
@@ -92,7 +91,7 @@ const tools = [...sponsoredTools, ...nonSponsoredTools];
9291
const toolsData = tools.map((tool) => ({
9392
category: category.data,
9493
tool: tool.data,
95-
slug: tool.id,
94+
slug: tool.id.replace(/\.md$/, ''),
9695
}));
9796
---
9897

@@ -130,7 +129,7 @@ const toolsData = tools.map((tool) => ({
130129
url: `https://openapi.tools/categories/${slug}`,
131130
tools: tools.map((t) => ({
132131
name: t.data.name,
133-
url: `https://openapi.tools/tools/${t.id}`,
132+
url: `https://openapi.tools/tools/${t.id.replace(/\.md$/, '')}`,
134133
})),
135134
})
136135
)}

src/pages/collections/[...slug].astro

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ function filterTools(
7777
export const getStaticPaths: GetStaticPaths = async () => {
7878
const curatedCollections = await getCollection('curated-collections');
7979
return curatedCollections.map((collection) => ({
80-
params: { slug: collection.id },
80+
params: { slug: collection.id.replace(/\.md$/, '') },
8181
props: { collection },
8282
}));
8383
};
8484
8585
// 2. Get the collection from props
86-
const { slug } = Astro.params;
87-
const collection = await getEntry('curated-collections', slug as string);
86+
const { collection } = Astro.props;
8887
8988
if (!collection) {
90-
throw new Error(`No collection found for slug ${slug}`);
89+
throw new Error(`No collection found for slug ${Astro.params.slug}`);
9190
}
9291
9392
const { Content } = await render(collection);
9493
94+
const slug = collection.id.replace(/\.md$/, '');
95+
9596
// 3. Get all tools and filter them based on collection filters
9697
const allTools = await getCollection('tools');
9798
const filteredTools = filterTools(allTools, collection.data.filters);
@@ -107,9 +108,9 @@ type CategoryWithTools = {
107108
108109
const categoriesWithTools: CategoryWithTools[] = allCategories
109110
.map((category) => {
110-
const categoryIdWithoutExt = category.id.replace(/\.md$/, '');
111+
const categorySlug = category.id.replace(/\.md$/, '');
111112
const toolsInCategory = filteredTools.filter((tool) =>
112-
tool.data.categories?.some((cat) => cat.id === categoryIdWithoutExt)
113+
tool.data.categories?.some((cat) => cat.id === categorySlug)
113114
);
114115
return {
115116
category,
@@ -130,7 +131,7 @@ const categoryGroups = categoriesWithTools.map(({ category, tools }) => ({
130131
description: category.data.description,
131132
tools: tools.map((tool) => ({
132133
tool: tool.data,
133-
slug: tool.id,
134+
slug: tool.id.replace(/\.md$/, ''),
134135
category: category.data,
135136
})),
136137
}));
@@ -170,7 +171,7 @@ const categoryGroups = categoriesWithTools.map(({ category, tools }) => ({
170171
url: `https://openapi.tools/collections/${slug}`,
171172
tools: filteredTools.slice(0, 10).map((tool) => ({
172173
name: tool.data.name,
173-
url: `https://openapi.tools/tools/${tool.id}`,
174+
url: `https://openapi.tools/tools/${tool.id.replace(/\.md$/, '')}`,
174175
})),
175176
})
176177
)}

src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const sortedCategories = allCategories.sort((a, b) =>
3535
{
3636
sortedCategories.map((category) => (
3737
<QuickLink
38-
href={`/categories/${category.id}`}
38+
href={`/categories/${category.id.replace(/\.md$/, '')}`}
3939
title={category.data.name}
4040
body={category.data.description}
4141
/>

src/pages/legacy.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const sortedCategories = allCategories.sort((a, b) =>
3737
const toolsByCategory = new Map<string, typeof legacyTools>();
3838
3939
for (const category of sortedCategories) {
40-
const categoryIdWithoutExt = category.id.replace(/\.md$/, '');
40+
const categorySlug = category.id.replace(/\.md$/, '');
4141
const categoryTools = legacyTools
4242
.filter((tool) => {
4343
const categories = tool.data.categories;
44-
return categories.some((cat) => cat.id === categoryIdWithoutExt);
44+
return categories.some((cat) => cat.id === categorySlug);
4545
})
4646
// Sort by active sponsors first, then alphabetically
4747
.sort((a, b) => {
@@ -90,7 +90,7 @@ for (const category of sortedCategories) {
9090
url: 'https://openapi.tools/legacy',
9191
tools: legacyTools.slice(0, 10).map((t) => ({
9292
name: t.data.name,
93-
url: `https://openapi.tools/tools/${t.id}`,
93+
url: `https://openapi.tools/tools/${t.id.replace(/\.md$/, '')}`,
9494
})),
9595
})
9696
)}
@@ -150,7 +150,7 @@ for (const category of sortedCategories) {
150150
const toolsData = tools.map((tool) => ({
151151
category: category.data,
152152
tool: tool.data,
153-
slug: tool.id,
153+
slug: tool.id.replace(/\.md$/, ''),
154154
}));
155155

156156
return (

src/pages/sponsor/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const uniqueSponsors = activeSponsors.filter((tool) => {
113113
<ul>
114114
{uniqueSponsors.map((tool) => (
115115
<li>
116-
<Link href={`/tools/${tool.id}`}>{tool.data.name}</Link>
116+
<Link href={`/tools/${tool.id.replace(/\.md$/, '')}`}>{tool.data.name}</Link>
117117
{tool.data.description && ` - ${tool.data.description}`}
118118
</li>
119119
))}

src/pages/tools/[...slug].astro

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ import {
2424
// 1. Generate a new path for every collection entry
2525
export const getStaticPaths: GetStaticPaths = async () => {
2626
const tools = await getCollection('tools');
27-
return tools.map((category) => ({
28-
params: { slug: category.id },
27+
return tools.map((tool) => ({
28+
params: { slug: tool.id.replace(/\.md$/, '') },
29+
props: { tool },
2930
}));
3031
};
3132
3233
// 2. For your template, you can get the entry directly from the prop
33-
const { slug } = Astro.params;
34-
const tool = await getEntry('tools', slug as string);
34+
const { tool } = Astro.props;
3535
3636
if (!tool) {
37-
throw new Error(`No category found for slug ${slug}`);
37+
throw new Error(`No tool found for slug ${Astro.params.slug}`);
3838
}
3939
40+
const slug = tool.id.replace(/\.md$/, '');
41+
4042
const languages: Record<string, boolean> = tool.data?.languages || {};
4143
4244
const { Content } = await render(tool);
@@ -112,7 +114,7 @@ const toolBadges = tool.data.badges
112114
Visit Website
113115
</Button>
114116
) : (
115-
<p>No Website</p>
117+
''
116118
)
117119
}
118120
{
@@ -173,7 +175,7 @@ const toolBadges = tool.data.badges
173175
(category) =>
174176
category && (
175177
<Link
176-
href={`/categories/${category.id}`}
178+
href={`/categories/${category.id.replace(/\.md$/, '')}`}
177179
className="no-underline"
178180
>
179181
<Badge variant="blue">{category.data.name}</Badge>
@@ -240,7 +242,13 @@ const toolBadges = tool.data.badges
240242

241243
<section class="md-grid-cols-2 grid gap-4 lg:grid-cols-3">
242244
{enrichedFeaturedArticles.map((article) => (
243-
<ExternalArticle {...article.og} toolSlug={slug as string} />
245+
<ExternalArticle
246+
{...article.og}
247+
url={article.url}
248+
title={article.title}
249+
date={article.date}
250+
toolSlug={slug as string}
251+
/>
244252
))}
245253
</section>
246254
</>

src/pages/tools/index.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const nonSponsoredTools = modernTools
3636
const tools = [...sponsoredTools, ...nonSponsoredTools];
3737
const toolsData = tools.map((tool) => ({
3838
tool: tool.data,
39-
slug: tool.id,
39+
slug: tool.id.replace(/\.md$/, ''),
4040
}));
4141
4242
const title = 'All Tools';
@@ -67,7 +67,7 @@ const description = 'Browse all OpenAPI tools that support modern OpenAPI.';
6767
url: 'https://openapi.tools/tools',
6868
tools: tools.map((t) => ({
6969
name: t.data.name,
70-
url: `https://openapi.tools/tools/${t.id}`,
70+
url: `https://openapi.tools/tools/${t.id.replace(/\.md$/, '')}`,
7171
})),
7272
})
7373
)}

0 commit comments

Comments
 (0)