Skip to content

Commit 9eaad04

Browse files
committed
remove h1 from description section, added redirect to handle service/service
1 parent 182d16b commit 9eaad04

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

components/DescriptionSection.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ interface DescriptionSectionProps {
88
export default function DescriptionSection({
99
description,
1010
}: DescriptionSectionProps) {
11+
// Transform heading levels: h1->h2, h2->h3, h3->h4, h4->h5, h5->h6, h6->h6
12+
const transformedDescription = description
13+
.replace(/<h6([^>]*)>/g, "<h6$1>")
14+
.replace(/<\/h6>/g, "</h6>")
15+
.replace(/<h5([^>]*)>/g, "<h6$1>")
16+
.replace(/<\/h5>/g, "</h6>")
17+
.replace(/<h4([^>]*)>/g, "<h5$1>")
18+
.replace(/<\/h4>/g, "</h5>")
19+
.replace(/<h3([^>]*)>/g, "<h4$1>")
20+
.replace(/<\/h3>/g, "</h4>")
21+
.replace(/<h2([^>]*)>/g, "<h3$1>")
22+
.replace(/<\/h2>/g, "</h3>")
23+
.replace(/<h1([^>]*)>/g, "<h2$1>")
24+
.replace(/<\/h1>/g, "</h2>");
25+
1126
const isLongDescription =
12-
description.length > 300 ||
13-
(description.match(/<\/p>/g) || []).length > 1 ||
14-
(description.match(/<h[1-6]>/g) || []).length > 0;
27+
transformedDescription.length > 300 ||
28+
(transformedDescription.match(/<\/p>/g) || []).length > 1 ||
29+
(transformedDescription.match(/<h[1-6]>/g) || []).length > 0;
1530

1631
return (
1732
<div className="mb-8">
@@ -25,8 +40,10 @@ export default function DescriptionSection({
2540
/>
2641
{/* Content container with collapse effect */}
2742
<div className="overflow-hidden transition-all duration-300 ease-in-out peer-checked:max-h-[9999px] max-h-[12.5em]">
28-
<div className="prose prose-h1:font-bold prose-p:text-gray-700 prose-a:text-blue-600 !max-w-none">
29-
<div dangerouslySetInnerHTML={{ __html: description }} />
43+
<div className="prose prose-h2:font-bold prose-h3:font-bold prose-h4:font-bold prose-h5:font-bold prose-h6:font-bold prose-p:text-gray-700 prose-a:text-blue-600 !max-w-none">
44+
<div
45+
dangerouslySetInnerHTML={{ __html: transformedDescription }}
46+
/>
3047
</div>
3148
</div>
3249

@@ -78,8 +95,8 @@ export default function DescriptionSection({
7895
</div>
7996
</div>
8097
) : (
81-
<div className="prose prose-h1:font-bold prose-p:text-gray-700 prose-a:text-blue-600 prose-max-w-none">
82-
<div dangerouslySetInnerHTML={{ __html: description }} />
98+
<div className="prose prose-h2:font-bold prose-h3:font-bold prose-h4:font-bold prose-h5:font-bold prose-h6:font-bold prose-p:text-gray-700 prose-a:text-blue-600 prose-max-w-none">
99+
<div dangerouslySetInnerHTML={{ __html: transformedDescription }} />
83100
</div>
84101
)}
85102
</div>

next-sitemap.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
import list from "./list.json";
2+
3+
const getProviderOnlyRoutes = () => {
4+
const providerOnlyRoutes = new Set();
5+
6+
for (const key of Object.keys(list)) {
7+
const [provider, service] = key.split(":");
8+
if (!service) {
9+
const providerSlug = provider.toLowerCase();
10+
providerOnlyRoutes.add(`/apis/${providerSlug}/${providerSlug}`);
11+
}
12+
}
13+
14+
return providerOnlyRoutes;
15+
};
16+
17+
const providerOnlyRoutes = getProviderOnlyRoutes();
18+
119
/** @type {import('next-sitemap').IConfig} */
220
module.exports = {
321
siteUrl: process.env.SITE_URL || "https://apis.guru",
@@ -6,6 +24,9 @@ module.exports = {
624
exclude: ["/studio/*", "/api/*", "/blog/*"],
725

826
transform: async (config, path) => {
27+
if (providerOnlyRoutes.has(path)) {
28+
return null;
29+
}
930
return {
1031
loc: path,
1132
changefreq: config.changefreq || "daily",

next.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ const nextConfig: NextConfig = {
6868
? `/apis/${encodeURIComponent(currentProviderSlug)}/${encodeURIComponent(normalizeServiceSlug(service))}`
6969
: `/apis/${encodeURIComponent(currentProviderSlug)}`;
7070

71+
if (!service) {
72+
redirectList.push({
73+
source: `/apis/${encodeURIComponent(currentProviderSlug)}/${encodeURIComponent(currentProviderSlug)}`,
74+
destination: `/apis/${encodeURIComponent(currentProviderSlug)}`,
75+
permanent: true,
76+
});
77+
}
78+
7179
if (legacyFullSlug !== currentProviderSlug) {
7280
redirectList.push({
7381
source: `/apis/${encodeURIComponent(legacyFullSlug)}`,

0 commit comments

Comments
 (0)