Skip to content

Commit fe18817

Browse files
Revert "revert gatby node changes and fix"
This reverts commit 4487b86. Signed-off-by: Rajesh-Nagarajan-11 <rajeshnagarajan36@gmail.com>
1 parent 4487b86 commit fe18817

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

gatsby-node.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,30 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
469469
}
470470

471471
handbook.forEach((page) => {
472+
let finalSlug = page.fields.slug;
473+
// Strip `.html` for production builds so client-side router matches clean paths
474+
if (process.env.NODE_ENV === "production") {
475+
finalSlug = finalSlug.replace(/\.html$/, "");
476+
}
477+
472478
envCreatePage({
473-
path: page.fields.slug,
479+
path: finalSlug,
474480
component: `${HandbookTemplate}?__contentFilePath=${page.internal.contentFilePath}`,
475481
context: {
476-
slug: page.fields.slug,
482+
slug: finalSlug,
477483
},
478484
});
485+
486+
// If the source slug contained .html, create a redirect so .html URLs still resolve
487+
if (finalSlug !== page.fields.slug) {
488+
createRedirect({
489+
fromPath: page.fields.slug,
490+
toPath: finalSlug,
491+
isPermanent: true,
492+
redirectInBrowser: true,
493+
force: true,
494+
});
495+
}
479496
});
480497

481498

src/sections/Community/Handbook/handbook-single/HandbookTOC.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ const HandbookTOC = ({ pages, currentSlug }) => {
3535
</div>
3636
<div className="toc-list">
3737
<ul className={`toc-ul ${expand ? "toc-ul-open" : ""}`}>
38-
{pages.map((page, index) => {
39-
const slug = `${page.fields.slug}.html`;
40-
return (
41-
<li key={index}>
42-
<Link
43-
to={slug}
44-
className={`toc-sub-heading toc-sub-inline${page.fields.slug === currentSlug ? " active" : ""}`}
45-
>
46-
{page.frontmatter.title}
47-
</Link>
48-
</li>
49-
);
50-
})}
38+
{pages.map((page, index) => (
39+
<li key={index}>
40+
<Link
41+
to={page.fields.slug}
42+
className={`toc-sub-heading toc-sub-inline${page.fields.slug === currentSlug ? " active" : ""}`}
43+
>
44+
{page.frontmatter.title}
45+
</Link>
46+
</li>
47+
))}
5148
</ul>
5249
</div>
5350
</TOCWrapper>

0 commit comments

Comments
 (0)