From 5b2149fa55a6dbc576815333a934432430c816b2 Mon Sep 17 00:00:00 2001 From: Aqib Nawab Date: Wed, 9 Jul 2025 09:56:43 +0500 Subject: [PATCH 1/4] Add Navigation into the japnese --- lib/slugifyMarkdownHeadline.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/slugifyMarkdownHeadline.ts b/lib/slugifyMarkdownHeadline.ts index ae943e138..cf4863672 100644 --- a/lib/slugifyMarkdownHeadline.ts +++ b/lib/slugifyMarkdownHeadline.ts @@ -4,23 +4,49 @@ export default function slugifyMarkdownHeadline( markdownChildren: string | any[], ): string { const FRAGMENT_REGEX = /\[#(?(\w|-|_)*)\]/g; + if (!markdownChildren) return ''; + if (typeof markdownChildren === 'string') - return slugify(markdownChildren, { lower: true, trim: true }); + return slugify(markdownChildren, { + lower: true, + + trim: true, + + remove: /[*+~()'"!]/g, + }); + const metaSlug = markdownChildren.reduce((acc, child) => { if (acc) return acc; + if (typeof child !== 'string') return null; + const fragment = FRAGMENT_REGEX.exec(child); + if (!fragment) return null; + const slug = fragment?.groups?.slug; + return slug || null; }, null); + if (metaSlug) return metaSlug; const joinedChildren = markdownChildren + .filter((child) => typeof child === 'string') + .map((string) => string.replace(FRAGMENT_REGEX, '')) + .join(' '); - const slug = slugify(joinedChildren, { lower: true, trim: true }); + + const slug = slugify(joinedChildren, { + lower: true, + + trim: true, + + remove: /[*+~()'"!]/g, + }); + return slug; } From 9455512003a66336403b61bc2df8cba953616d5b Mon Sep 17 00:00:00 2001 From: Aqib Nawab Date: Wed, 9 Jul 2025 11:32:06 +0500 Subject: [PATCH 2/4] Update the test case --- cypress/components/Headlines.cy.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cypress/components/Headlines.cy.tsx b/cypress/components/Headlines.cy.tsx index 2fd627b5d..8348f09fb 100644 --- a/cypress/components/Headlines.cy.tsx +++ b/cypress/components/Headlines.cy.tsx @@ -6,6 +6,7 @@ import { Headline4, } from '~/components/Headlines'; import mockNextRouter, { MockRouter } from '../plugins/mockNextRouterUtils'; +import slugifyMarkdownHeadline from '~/lib/slugifyMarkdownHeadline'; describe('Headlines Component', () => { let mockRouter: MockRouter; @@ -94,15 +95,18 @@ describe('Headlines Component', () => { it('should be active if the URL has the hash', () => { /* Testing the active headline with Headline1 */ - // Set the URL with the hash - mockRouter.asPath = '/#what-is-json-schema'; + const title = 'What is JSON Schema?'; + const slug = slugifyMarkdownHeadline(title); + + // Update the existing mock router's properties + mockRouter.asPath = `/#${slug}`; // Check if Correct headline is active - cy.mount(What is JSON Schema?); + cy.mount({title}); cy.get('span').should( 'have.class', 'text-startBlue dark:text-endBlue inline-block ml-2', ); cy.get('span').should('have.text', '¶'); }); -}); +}); \ No newline at end of file From 606fa9b7e34b722746bc5d0d34498dfc5006ab52 Mon Sep 17 00:00:00 2001 From: Aqib Nawab Date: Wed, 9 Jul 2025 11:37:45 +0500 Subject: [PATCH 3/4] fix the linting issues --- cypress/components/Headlines.cy.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/components/Headlines.cy.tsx b/cypress/components/Headlines.cy.tsx index 8348f09fb..dfa1a450a 100644 --- a/cypress/components/Headlines.cy.tsx +++ b/cypress/components/Headlines.cy.tsx @@ -109,4 +109,4 @@ describe('Headlines Component', () => { ); cy.get('span').should('have.text', '¶'); }); -}); \ No newline at end of file +}); From 3e77f0530b4a00ffd93a0fb38249e4a47182495e Mon Sep 17 00:00:00 2001 From: Aqib Nawab Date: Thu, 10 Jul 2025 08:47:05 +0500 Subject: [PATCH 4/4] remove the extra spaces --- lib/slugifyMarkdownHeadline.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/slugifyMarkdownHeadline.ts b/lib/slugifyMarkdownHeadline.ts index cf4863672..14b796b2d 100644 --- a/lib/slugifyMarkdownHeadline.ts +++ b/lib/slugifyMarkdownHeadline.ts @@ -10,9 +10,7 @@ export default function slugifyMarkdownHeadline( if (typeof markdownChildren === 'string') return slugify(markdownChildren, { lower: true, - trim: true, - remove: /[*+~()'"!]/g, }); @@ -33,18 +31,13 @@ export default function slugifyMarkdownHeadline( if (metaSlug) return metaSlug; const joinedChildren = markdownChildren - .filter((child) => typeof child === 'string') - .map((string) => string.replace(FRAGMENT_REGEX, '')) - .join(' '); const slug = slugify(joinedChildren, { lower: true, - trim: true, - remove: /[*+~()'"!]/g, });