From f0271053e60e304743f64061e6616213612668a9 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Fri, 20 Dec 2024 12:19:42 +0530 Subject: [PATCH 1/8] Link-redirect-fix --- components/DocsHelp.tsx | 18 +++-- cypress/components/DocsHelp.cy.tsx | 70 +++++++++++-------- pages/[slug].page.tsx | 4 +- pages/docs/index.page.tsx | 3 +- pages/draft-05/index.page.tsx | 7 +- pages/draft-06/[slug].page.tsx | 4 +- pages/draft-06/index.page.tsx | 3 +- pages/draft-07/[slug].page.tsx | 4 +- pages/draft-07/index.page.tsx | 3 +- pages/draft/2019-09/[slug].page.tsx | 4 +- pages/draft/2019-09/index.page.tsx | 3 +- pages/draft/2020-12/[slug].page.tsx | 4 +- pages/draft/2020-12/index.page.tsx | 3 +- pages/implementers/[slug].page.tsx | 4 +- pages/implementers/index.page.tsx | 4 +- pages/learn/[slug].page.tsx | 4 +- .../index.page.tsx | 4 +- pages/learn/index.page.tsx | 4 +- pages/overview/[slug].page.tsx | 4 +- pages/overview/case-studies/index.page.tsx | 4 +- pages/overview/code-of-conduct/index.page.tsx | 4 +- pages/overview/roadmap/index.page.tsx | 4 +- pages/overview/sponsors/index.page.tsx | 4 +- pages/overview/use-cases/index.page.tsx | 4 +- .../json-hyper-schema/index.page.tsx | 4 +- pages/specification/migration/index.page.tsx | 4 +- .../release-notes/index.page.tsx | 4 +- .../understanding-json-schema/[slug].page.tsx | 4 +- .../understanding-json-schema/index.page.tsx | 4 +- .../keywords/index.page.tsx | 4 +- .../reference/[slug].page.tsx | 4 +- .../reference/index.page.tsx | 4 +- 32 files changed, 118 insertions(+), 88 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index 544189b77..b81c6e02e 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -3,18 +3,26 @@ import React, { FormEvent, useRef, useState } from 'react'; import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment'; interface DocsHelpProps { - markdownFile?: string; + fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md'; } -export function DocsHelp({ markdownFile }: DocsHelpProps) { +export function DocsHelp({ fileRenderType }: DocsHelpProps) { const router = useRouter(); - const path = encodeURIComponent(router.pathname); const [isFormOpen, setIsFormOpen] = useState(false); const [feedbackStatus, setFeedbackStatus] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(''); const feedbackFormRef = useRef(null); - + let gitredirect = ''; + if (fileRenderType === 'tsx') { + gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.page.tsx'}`; + } else if (fileRenderType === '_indexmd') { + gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`; + } else if (fileRenderType === 'indexmd') { + gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`; + } else { + gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`; + } async function createFeedbackHandler(event: FormEvent) { event.preventDefault(); const formData = new FormData(feedbackFormRef.current!); @@ -301,7 +309,7 @@ export function DocsHelp({ markdownFile }: DocsHelpProps) { target='_blank' rel='noreferrer' className='px-[16px] py-[8px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md hover:bg-gray-200 dark:hover:bg-gray-600' - href={`https://github.com/json-schema-org/website/blob/main/pages${markdownFile ? (markdownFile === '_indexPage' ? extractPathWithoutFragment(router.asPath) + '/_index.md' : extractPathWithoutFragment(router.asPath) + '.md') : `/${path}/index.page.tsx`}`} + href={gitredirect} data-test='edit-on-github-link' > { // eslint-disable-next-line @typescript-eslint/no-unused-vars let mockRouter: MockRouter; + const extractPathWithoutFragment = (path: any) => path.split('#')[0]; // Note: we are not using the mockRouter in this test file, but it is required to mock the router in the component file beforeEach(() => { - const markdownFile = '_index'; + const fileRenderType = 'indexmd'; mockRouter = mockNextRouter(); cy.viewport(1200, 800); - cy.mount(); + cy.mount(); }); // should render the component correctly it('should render the component correctly', () => { // Check if the main component wrapper is present + cy.mount(); cy.get(DOCS_HELP).should('exist'); // "Need Help?" header cy.get('[data-test="need-help-heading"]') .should('have.prop', 'tagName', 'H2') - .and('contains', /Need Help?/i); + .and('contain.text', 'Need Help?'); // Main feedback question cy.get('[data-test="feedback-main-heading"]') .should('have.prop', 'tagName', 'H3') - .and('contains', /Did you find these docs helpful?/i); + .and('contain.text', 'Did you find these docs helpful?'); // Feedback form element cy.get(FEEDBACK_FORM).should('have.prop', 'tagName', 'FORM'); @@ -50,20 +52,17 @@ describe('DocsHelp Component', () => { // "Help us improve" section header cy.get('[data-test="contribute-docs-heading"]') .should('have.prop', 'tagName', 'H3') - .and('contains', /Help us make our docs great!/i); + .and('contain.text', 'Help us make our docs great!'); // Contribution encouragement text cy.get('[data-test="contribute-docs-description"]') .should('have.prop', 'tagName', 'P') - .and( - 'contains', - /At JSON Schema, we value docs contributions as much as every other type of contribution!/i, - ); + .and('contain.text', 'At JSON Schema, we value docs contributions'); // "Edit on GitHub" link cy.get('[data-test="edit-on-github-link"]') .should('have.prop', 'tagName', 'A') - .and('contains', /Edit this page on Github/i); + .and('contain.text', 'Edit this page on Github'); // "Learn to contribute" link cy.get('[data-test="learn-to-contribute-link"]') @@ -73,20 +72,17 @@ describe('DocsHelp Component', () => { 'href', 'https://github.com/json-schema-org/website/blob/main/CONTRIBUTING.md', ) - .and('contains', /Learn how to contribute/i); + .and('contain.text', 'Learn how to contribute'); // "Still Need Help?" section header cy.get('[data-test="additional-help-heading"]') .should('have.prop', 'tagName', 'H3') - .and('contains', /Still Need Help?/i); + .and('contain.text', 'Still Need Help?'); // Additional help description cy.get('[data-test="additional-help-description"]') .should('have.prop', 'tagName', 'P') - .should( - 'contains', - /Learning JSON Schema is often confusing, but don't worry, we are here to help!./i, - ); + .and('contain.text', 'Learning JSON Schema is often confusing'); // GitHub community link cy.get('[ data-test="ask-on-github-link"]') @@ -96,7 +92,7 @@ describe('DocsHelp Component', () => { 'href', 'https://github.com/orgs/json-schema-org/discussions/new?category=q-a', ) - .and('contains', /Ask the community on GitHub/i); + .and('contain.text', 'Ask the community on GitHub'); // Slack community link cy.get('[data-test="ask-on-slack-link"]') @@ -237,15 +233,33 @@ describe('DocsHelp Component', () => { }); // This test is to check component render correctly with different markdown files - it('should render component with different markdown files', () => { - /* Note: Already checking with _index markdown file in the first test case */ - - // render with _indexPage markdown file - const markdownFile = '_indexPage'; - cy.mount(); - cy.get(DOCS_HELP).should('exist'); - - // render without any markdown file - cy.mount(); - }); + it('should render component with different markdown files and validate gitredirect', () => { + const fileRenderTypes: ('tsx' | 'indexmd' | '_indexmd' | '_md')[] = [ + 'tsx', + '_indexmd', + 'indexmd', + '_md', + ]; + + fileRenderTypes.forEach((type) => { + let expectedGitRedirect = ''; + + if (type === 'tsx') { + expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.page.tsx'}`; + } else if (type === '_indexmd') { + expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`; + } else if (type === 'indexmd') { + expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`; + } else { + expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`; + } + cy.mount(); + + cy.get('[data-test="edit-on-github-link"]').should( + 'have.attr', + 'href', + expectedGitRedirect, + ); + }); + }) }); diff --git a/pages/[slug].page.tsx b/pages/[slug].page.tsx index 4bd646418..c672ae97e 100644 --- a/pages/[slug].page.tsx +++ b/pages/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/docs/index.page.tsx b/pages/docs/index.page.tsx index 635f55cf1..2412f40c4 100644 --- a/pages/docs/index.page.tsx +++ b/pages/docs/index.page.tsx @@ -8,6 +8,7 @@ import { DocsHelp } from '~/components/DocsHelp'; export default function Welcome() { const newTitle = 'Welcome'; + const fileRenderType = 'tsx'; return ( @@ -56,7 +57,7 @@ export default function Welcome() { link='/specification' /> - + ); } diff --git a/pages/draft-05/index.page.tsx b/pages/draft-05/index.page.tsx index 1d619e0b4..b768b2327 100644 --- a/pages/draft-05/index.page.tsx +++ b/pages/draft-05/index.page.tsx @@ -32,14 +32,17 @@ export default function ImplementationsPages({ }: { blocks: any; frontmatter: any; -}) { +}) + +{ + const fileRenderType = 'indexmd'; return ( {frontmatter.title} - + ); } diff --git a/pages/draft-06/[slug].page.tsx b/pages/draft-06/[slug].page.tsx index fc447db63..64655ed3c 100644 --- a/pages/draft-06/[slug].page.tsx +++ b/pages/draft-06/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/draft-06/index.page.tsx b/pages/draft-06/index.page.tsx index 12127285b..b328e38ae 100644 --- a/pages/draft-06/index.page.tsx +++ b/pages/draft-06/index.page.tsx @@ -31,12 +31,13 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { + const fileRenderType = 'indexmd'; return ( {frontmatter.title} - + ); } diff --git a/pages/draft-07/[slug].page.tsx b/pages/draft-07/[slug].page.tsx index be10dfdba..f4ef2b082 100644 --- a/pages/draft-07/[slug].page.tsx +++ b/pages/draft-07/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/draft-07/index.page.tsx b/pages/draft-07/index.page.tsx index 91d52a981..c057e259c 100644 --- a/pages/draft-07/index.page.tsx +++ b/pages/draft-07/index.page.tsx @@ -31,12 +31,13 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { + const fileRenderType = 'indexmd'; return ( {frontmatter.title} - + ); } diff --git a/pages/draft/2019-09/[slug].page.tsx b/pages/draft/2019-09/[slug].page.tsx index d7d289a2e..26acaf0e1 100644 --- a/pages/draft/2019-09/[slug].page.tsx +++ b/pages/draft/2019-09/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/draft/2019-09/index.page.tsx b/pages/draft/2019-09/index.page.tsx index 14fb022f2..c8e7f3e2d 100644 --- a/pages/draft/2019-09/index.page.tsx +++ b/pages/draft/2019-09/index.page.tsx @@ -30,12 +30,13 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { + const fileRenderType = 'indexmd'; return ( {frontmatter.title} - + ); } diff --git a/pages/draft/2020-12/[slug].page.tsx b/pages/draft/2020-12/[slug].page.tsx index 52734da09..cc2331502 100644 --- a/pages/draft/2020-12/[slug].page.tsx +++ b/pages/draft/2020-12/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/draft/2020-12/index.page.tsx b/pages/draft/2020-12/index.page.tsx index 4446b9c1b..30e21a5bd 100644 --- a/pages/draft/2020-12/index.page.tsx +++ b/pages/draft/2020-12/index.page.tsx @@ -30,12 +30,13 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { + const fileRenderType = 'indexmd'; return ( {frontmatter.title} - + ); } diff --git a/pages/implementers/[slug].page.tsx b/pages/implementers/[slug].page.tsx index c86202c00..0e0f69786 100644 --- a/pages/implementers/[slug].page.tsx +++ b/pages/implementers/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/implementers/index.page.tsx b/pages/implementers/index.page.tsx index 425d1f4c9..1dacaec01 100644 --- a/pages/implementers/index.page.tsx +++ b/pages/implementers/index.page.tsx @@ -18,7 +18,7 @@ export async function getStaticProps() { } export default function ContentExample({ blocks }: { blocks: any[] }) { - const markdownFile = '_indexPage'; + const fileRenderType = '_indexmd'; return ( @@ -45,7 +45,7 @@ export default function ContentExample({ blocks }: { blocks: any[] }) { /> - + ); } diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index f110ff75d..7c7d33308 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index b1b8b7eb2..2c58ef1e3 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -30,7 +30,7 @@ export async function getStaticProps() { export default function StyledValidator({ blocks }: { blocks: any[] }) { const newTitle = 'Creating your first schema'; - + const fileRenderType = 'tsx'; return ( @@ -40,7 +40,7 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) { - + ); } diff --git a/pages/learn/index.page.tsx b/pages/learn/index.page.tsx index 1cac2c83d..80963af47 100644 --- a/pages/learn/index.page.tsx +++ b/pages/learn/index.page.tsx @@ -7,7 +7,7 @@ import Card from '~/components/Card'; import { DocsHelp } from '~/components/DocsHelp'; export default function Welcome() { - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; const newTitle = 'Getting Started'; return ( @@ -39,7 +39,7 @@ export default function Welcome() { link='https://tour.json-schema.org/' /> - + ); } diff --git a/pages/overview/[slug].page.tsx b/pages/overview/[slug].page.tsx index e4d5476d7..808428d8d 100644 --- a/pages/overview/[slug].page.tsx +++ b/pages/overview/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} - + ); } diff --git a/pages/overview/case-studies/index.page.tsx b/pages/overview/case-studies/index.page.tsx index 81c761ca6..40afaa5a3 100644 --- a/pages/overview/case-studies/index.page.tsx +++ b/pages/overview/case-studies/index.page.tsx @@ -10,7 +10,7 @@ import { useTheme } from 'next-themes'; export default function ContentExample() { const newTitle = 'Case Studies'; - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; const { resolvedTheme } = useTheme(); const imgUrl = (src: string): string => { @@ -47,7 +47,7 @@ export default function ContentExample() { /> ))} - + ); } diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx index c4d74033e..e8b50bdda 100644 --- a/pages/overview/code-of-conduct/index.page.tsx +++ b/pages/overview/code-of-conduct/index.page.tsx @@ -22,14 +22,14 @@ export async function getStaticProps() { export default function Content({ blocks }: { blocks: any[] }) { const newTitle = 'Code of Conduct'; - + const fileRenderType = 'tsx'; return ( {newTitle} - + ); } diff --git a/pages/overview/roadmap/index.page.tsx b/pages/overview/roadmap/index.page.tsx index 8f3c0d92a..26d2198ab 100644 --- a/pages/overview/roadmap/index.page.tsx +++ b/pages/overview/roadmap/index.page.tsx @@ -34,7 +34,7 @@ const impactColors = { export default function Roadmap() { const newTitle = 'JSON Schema Roadmap'; - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; return ( @@ -130,7 +130,7 @@ export default function Roadmap() { - + ); } diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx index a26f1dfe7..5f15e1e7f 100644 --- a/pages/overview/sponsors/index.page.tsx +++ b/pages/overview/sponsors/index.page.tsx @@ -20,7 +20,7 @@ export async function getStaticProps() { export default function ContentExample({ blocks }: { blocks: any[] }) { const newTitle = 'Sponsors'; - + const fileRenderType = '_indexmd'; return ( @@ -28,7 +28,7 @@ export default function ContentExample({ blocks }: { blocks: any[] }) { {newTitle} - + ); } diff --git a/pages/overview/use-cases/index.page.tsx b/pages/overview/use-cases/index.page.tsx index 6e2811a51..c7cb5b158 100644 --- a/pages/overview/use-cases/index.page.tsx +++ b/pages/overview/use-cases/index.page.tsx @@ -9,7 +9,7 @@ import { DocsHelp } from '~/components/DocsHelp'; export default function Content() { const newTitle = 'Use Cases'; - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; return ( @@ -35,7 +35,7 @@ export default function Content() { /> ))} - + ); } diff --git a/pages/specification/json-hyper-schema/index.page.tsx b/pages/specification/json-hyper-schema/index.page.tsx index b1ce3264f..7701392c8 100644 --- a/pages/specification/json-hyper-schema/index.page.tsx +++ b/pages/specification/json-hyper-schema/index.page.tsx @@ -35,7 +35,7 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { - const markdownFile = '_indexPage'; + const fileRenderType = '_indexmd'; return ( {frontmatter.title} @@ -44,7 +44,7 @@ export default function ImplementationsPages({ - + ); } diff --git a/pages/specification/migration/index.page.tsx b/pages/specification/migration/index.page.tsx index fbba9bd33..cbdbb94d6 100644 --- a/pages/specification/migration/index.page.tsx +++ b/pages/specification/migration/index.page.tsx @@ -36,7 +36,7 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { - const markdownFile = '_indexPage'; + const fileRenderType = '_indexmd'; return ( {frontmatter.title} @@ -72,7 +72,7 @@ export default function ImplementationsPages({ link='/draft-06/json-schema-release-notes' /> - + ); } diff --git a/pages/specification/release-notes/index.page.tsx b/pages/specification/release-notes/index.page.tsx index 50ea7f7d5..33bde330c 100644 --- a/pages/specification/release-notes/index.page.tsx +++ b/pages/specification/release-notes/index.page.tsx @@ -36,7 +36,7 @@ export default function ImplementationsPages({ blocks: any; frontmatter: any; }) { - const markdownFile = '_indexPage'; + const fileRenderType = '_indexmd'; return ( {frontmatter.title} @@ -79,7 +79,7 @@ export default function ImplementationsPages({ link='/draft-05#explanation-for-lack-of-draft-05-meta-schema' /> - + ); } diff --git a/pages/understanding-json-schema/[slug].page.tsx b/pages/understanding-json-schema/[slug].page.tsx index 6174f5ea1..e161dacfc 100644 --- a/pages/understanding-json-schema/[slug].page.tsx +++ b/pages/understanding-json-schema/[slug].page.tsx @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({ frontmatter: any; content: any; }) { - const markdownFile = '_index'; + const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({ {frontmatter.title || 'NO TITLE!'} - + ); } diff --git a/pages/understanding-json-schema/index.page.tsx b/pages/understanding-json-schema/index.page.tsx index e8f6fa8e6..a7ad3b051 100644 --- a/pages/understanding-json-schema/index.page.tsx +++ b/pages/understanding-json-schema/index.page.tsx @@ -20,12 +20,12 @@ export async function getStaticProps() { } export default function ContentExample({ blocks }: { blocks: any[] }) { - const markdownFile = '_indexPage'; + const fileRenderType = '_indexmd'; return ( - + ); } diff --git a/pages/understanding-json-schema/keywords/index.page.tsx b/pages/understanding-json-schema/keywords/index.page.tsx index ffa2e72f0..b74a4b055 100644 --- a/pages/understanding-json-schema/keywords/index.page.tsx +++ b/pages/understanding-json-schema/keywords/index.page.tsx @@ -38,7 +38,7 @@ interface LinkObject { } export default function StaticMarkdownPage({ datas }: { datas: DataObject[] }) { - const markdownFile = '_index'; + const fileRenderType = 'tsx'; return ( @@ -87,7 +87,7 @@ export default function StaticMarkdownPage({ datas }: { datas: DataObject[] }) { )} - + ); } diff --git a/pages/understanding-json-schema/reference/[slug].page.tsx b/pages/understanding-json-schema/reference/[slug].page.tsx index acab32f4c..6827b2950 100644 --- a/pages/understanding-json-schema/reference/[slug].page.tsx +++ b/pages/understanding-json-schema/reference/[slug].page.tsx @@ -26,7 +26,7 @@ export default function StaticMarkdownPage({ content: any; }) { const newTitle = 'JSON Schema - ' + frontmatter.title; - const markdownFile = '_index'; + const fileRenderType = '_md'; return ( @@ -34,7 +34,7 @@ export default function StaticMarkdownPage({ {frontmatter.title || 'NO TITLE!'} - + ); } diff --git a/pages/understanding-json-schema/reference/index.page.tsx b/pages/understanding-json-schema/reference/index.page.tsx index 19953a9d4..76e3b7037 100644 --- a/pages/understanding-json-schema/reference/index.page.tsx +++ b/pages/understanding-json-schema/reference/index.page.tsx @@ -20,11 +20,11 @@ export async function getStaticProps() { } export default function ContentExample({ blocks }: { blocks: any[] }) { - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; return ( - + ); } From 55d3341597d2797201f7d08f4b4a209738bc0081 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Fri, 20 Dec 2024 12:33:21 +0530 Subject: [PATCH 2/8] linting-not-working --- components/DocsHelp.tsx | 3 +-- cypress/components/DocsHelp.cy.tsx | 2 +- data/tooling-data.schema.json | 2 +- pages/docs/index.page.tsx | 2 +- pages/draft-05/index.page.tsx | 4 +--- pages/overview/faq/index.page.tsx | 4 ++-- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index b81c6e02e..60e95e1c5 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -5,8 +5,7 @@ import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment'; interface DocsHelpProps { fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md'; } - -export function DocsHelp({ fileRenderType }: DocsHelpProps) { +export function DocsHelp({ fileRenderType }: DocsHelpProps) { const router = useRouter(); const [isFormOpen, setIsFormOpen] = useState(false); const [feedbackStatus, setFeedbackStatus] = useState(''); diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx index 8065e0020..c97a865b0 100644 --- a/cypress/components/DocsHelp.cy.tsx +++ b/cypress/components/DocsHelp.cy.tsx @@ -261,5 +261,5 @@ describe('DocsHelp Component', () => { expectedGitRedirect, ); }); - }) + }); }); diff --git a/data/tooling-data.schema.json b/data/tooling-data.schema.json index b91ae2365..c8185ba78 100644 --- a/data/tooling-data.schema.json +++ b/data/tooling-data.schema.json @@ -121,7 +121,7 @@ "C#", "Go", "C++", - "JavaScript", + "JavaScript", "Julia" ] ] diff --git a/pages/docs/index.page.tsx b/pages/docs/index.page.tsx index 2412f40c4..f77c33782 100644 --- a/pages/docs/index.page.tsx +++ b/pages/docs/index.page.tsx @@ -57,7 +57,7 @@ export default function Welcome() { link='/specification' /> - + ); } diff --git a/pages/draft-05/index.page.tsx b/pages/draft-05/index.page.tsx index b768b2327..a792cfc05 100644 --- a/pages/draft-05/index.page.tsx +++ b/pages/draft-05/index.page.tsx @@ -32,9 +32,7 @@ export default function ImplementationsPages({ }: { blocks: any; frontmatter: any; -}) - -{ +}) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/overview/faq/index.page.tsx b/pages/overview/faq/index.page.tsx index 283edf29e..c2166ae77 100644 --- a/pages/overview/faq/index.page.tsx +++ b/pages/overview/faq/index.page.tsx @@ -8,7 +8,7 @@ import { DocsHelp } from '~/components/DocsHelp'; export default function Content() { const newTitle = 'FAQ'; - const markdownFile = '_indexPage'; + const fileRenderType = 'tsx'; return ( @@ -21,7 +21,7 @@ export default function Content() { Schema.

- +
); } From 579c8f2f5dc3bcf4068ce4c6cbbcb2a315612927 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Fri, 27 Dec 2024 16:00:31 +0530 Subject: [PATCH 3/8] resolved-the-conflicts --- pages/overview/roadmap/index.page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/overview/roadmap/index.page.tsx b/pages/overview/roadmap/index.page.tsx index feab740b4..e22e358f5 100644 --- a/pages/overview/roadmap/index.page.tsx +++ b/pages/overview/roadmap/index.page.tsx @@ -130,7 +130,7 @@ export default function Roadmap() { })} - + Date: Tue, 31 Dec 2024 15:19:56 +0530 Subject: [PATCH 4/8] changed-the-sponsors-and-code_of_conduct-redirect --- components/DocsHelp.tsx | 14 +++++++++++++- pages/overview/code-of-conduct/index.page.tsx | 2 +- pages/overview/sponsors/index.page.tsx | 2 +- .../reference/index.page.tsx | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index 60e95e1c5..355aeea45 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -3,7 +3,13 @@ import React, { FormEvent, useRef, useState } from 'react'; import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment'; interface DocsHelpProps { - fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md'; + fileRenderType?: + | '_indexmd' + | 'indexmd' + | 'tsx' + | '_md' + | 'sponsors' + | 'code_of_conduct'; } export function DocsHelp({ fileRenderType }: DocsHelpProps) { const router = useRouter(); @@ -19,6 +25,12 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`; } else if (fileRenderType === 'indexmd') { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`; + } else if (fileRenderType === 'sponsors') { + gitredirect = + 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; + } else if (fileRenderType === 'code_of_conduct') { + gitredirect = + 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; } else { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`; } diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx index d057a559c..c7370e69b 100644 --- a/pages/overview/code-of-conduct/index.page.tsx +++ b/pages/overview/code-of-conduct/index.page.tsx @@ -29,7 +29,7 @@ export default function Content({ content: any; }) { const newTitle = 'Code of Conduct'; - const fileRenderType = 'tsx'; + const fileRenderType = 'code_of_conduct'; return ( diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx index a65500c3a..58a586d85 100644 --- a/pages/overview/sponsors/index.page.tsx +++ b/pages/overview/sponsors/index.page.tsx @@ -21,7 +21,7 @@ export async function getStaticProps() { export default function ContentExample({ blocks }: { blocks: any[] }) { const newTitle = 'Sponsors'; - const fileRenderType = '_indexmd'; + const fileRenderType = 'sponsors'; return ( diff --git a/pages/understanding-json-schema/reference/index.page.tsx b/pages/understanding-json-schema/reference/index.page.tsx index 76e3b7037..2447e6d6d 100644 --- a/pages/understanding-json-schema/reference/index.page.tsx +++ b/pages/understanding-json-schema/reference/index.page.tsx @@ -20,7 +20,7 @@ export async function getStaticProps() { } export default function ContentExample({ blocks }: { blocks: any[] }) { - const fileRenderType = 'tsx'; + const fileRenderType = '_indexmd'; return ( From 336c74749094ea97ba61e148bfe795d154d1b4b4 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Tue, 31 Dec 2024 15:33:56 +0530 Subject: [PATCH 5/8] test-added-for-the-changes --- cypress/components/DocsHelp.cy.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx index c97a865b0..3a77c7508 100644 --- a/cypress/components/DocsHelp.cy.tsx +++ b/cypress/components/DocsHelp.cy.tsx @@ -234,12 +234,14 @@ describe('DocsHelp Component', () => { // This test is to check component render correctly with different markdown files it('should render component with different markdown files and validate gitredirect', () => { - const fileRenderTypes: ('tsx' | 'indexmd' | '_indexmd' | '_md')[] = [ - 'tsx', - '_indexmd', - 'indexmd', - '_md', - ]; + const fileRenderTypes: ( + | 'tsx' + | 'indexmd' + | '_indexmd' + | '_md' + | 'sponsors' + | 'code_of_conduct' + )[] = ['tsx', '_indexmd', 'indexmd', '_md', 'sponsors', 'code_of_conduct']; fileRenderTypes.forEach((type) => { let expectedGitRedirect = ''; @@ -250,6 +252,12 @@ describe('DocsHelp Component', () => { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`; } else if (type === 'indexmd') { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`; + } else if (type === 'sponsors') { + expectedGitRedirect = + 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; + } else if (type === 'code_of_conduct') { + expectedGitRedirect = + 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; } else { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`; } From 41029df87b01da0c3a3410d0feb8f4a27c791a46 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Fri, 17 Jan 2025 18:17:12 +0530 Subject: [PATCH 6/8] made-the-component-flexible --- components/DocsHelp.tsx | 21 ++++++---------- cypress/components/DocsHelp.cy.tsx | 25 +++++++------------ pages/implementers/index.page.tsx | 5 +--- pages/overview/code-of-conduct/index.page.tsx | 3 ++- pages/overview/sponsors/index.page.tsx | 3 ++- .../understanding-json-schema/index.page.tsx | 5 +--- 6 files changed, 22 insertions(+), 40 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index 355aeea45..da58226e8 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -3,13 +3,7 @@ import React, { FormEvent, useRef, useState } from 'react'; import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment'; interface DocsHelpProps { - fileRenderType?: - | '_indexmd' - | 'indexmd' - | 'tsx' - | '_md' - | 'sponsors' - | 'code_of_conduct'; + fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md' | string; } export function DocsHelp({ fileRenderType }: DocsHelpProps) { const router = useRouter(); @@ -19,18 +13,17 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) { const [error, setError] = useState(''); const feedbackFormRef = useRef(null); let gitredirect = ''; - if (fileRenderType === 'tsx') { + if ( + typeof fileRenderType === 'string' && + fileRenderType.startsWith('https://') + ) { + gitredirect = fileRenderType; + } else if (fileRenderType === 'tsx') { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.page.tsx'}`; } else if (fileRenderType === '_indexmd') { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/_index.md'}`; } else if (fileRenderType === 'indexmd') { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`; - } else if (fileRenderType === 'sponsors') { - gitredirect = - 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; - } else if (fileRenderType === 'code_of_conduct') { - gitredirect = - 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; } else { gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '.md'}`; } diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx index 3a77c7508..42eaf7f41 100644 --- a/cypress/components/DocsHelp.cy.tsx +++ b/cypress/components/DocsHelp.cy.tsx @@ -234,30 +234,23 @@ describe('DocsHelp Component', () => { // This test is to check component render correctly with different markdown files it('should render component with different markdown files and validate gitredirect', () => { - const fileRenderTypes: ( - | 'tsx' - | 'indexmd' - | '_indexmd' - | '_md' - | 'sponsors' - | 'code_of_conduct' - )[] = ['tsx', '_indexmd', 'indexmd', '_md', 'sponsors', 'code_of_conduct']; + const fileRenderTypes: ('tsx' | 'indexmd' | '_indexmd' | '_md')[] = [ + 'tsx', + '_indexmd', + 'indexmd', + '_md', + ]; fileRenderTypes.forEach((type) => { let expectedGitRedirect = ''; - - if (type === 'tsx') { + if (typeof type === 'string' && type.startsWith('https://')) { + expectedGitRedirect = type; + } else if (type === 'tsx') { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.page.tsx'}`; } else if (type === '_indexmd') { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`; } else if (type === 'indexmd') { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`; - } else if (type === 'sponsors') { - expectedGitRedirect = - 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; - } else if (type === 'code_of_conduct') { - expectedGitRedirect = - 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; } else { expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`; } diff --git a/pages/implementers/index.page.tsx b/pages/implementers/index.page.tsx index 0d49b0d42..6b056bd06 100644 --- a/pages/implementers/index.page.tsx +++ b/pages/implementers/index.page.tsx @@ -17,9 +17,6 @@ export async function getStaticProps() { }, }; } - -export default function ContentExample({ blocks }: { blocks: any[] }) { - const fileRenderType = '_indexmd'; export default function ContentExample({ blocks, }: { @@ -27,7 +24,7 @@ export default function ContentExample({ frontmatter: any; content: any; }) { - + const fileRenderType = '_indexmd'; return ( diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx index ded68b47b..75e6000f2 100644 --- a/pages/overview/code-of-conduct/index.page.tsx +++ b/pages/overview/code-of-conduct/index.page.tsx @@ -29,7 +29,8 @@ export default function Content({ content: any; }) { const newTitle = 'Code of Conduct'; - const fileRenderType = 'code_of_conduct'; + const fileRenderType = + 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; return ( diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx index 58a586d85..c3c59d4ee 100644 --- a/pages/overview/sponsors/index.page.tsx +++ b/pages/overview/sponsors/index.page.tsx @@ -21,7 +21,8 @@ export async function getStaticProps() { export default function ContentExample({ blocks }: { blocks: any[] }) { const newTitle = 'Sponsors'; - const fileRenderType = 'sponsors'; + const fileRenderType = + 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; return ( diff --git a/pages/understanding-json-schema/index.page.tsx b/pages/understanding-json-schema/index.page.tsx index 3ff5af08f..40ed5c449 100644 --- a/pages/understanding-json-schema/index.page.tsx +++ b/pages/understanding-json-schema/index.page.tsx @@ -19,9 +19,6 @@ export async function getStaticProps() { }, }; } - -export default function ContentExample({ blocks }: { blocks: any[] }) { - const fileRenderType = '_indexmd'; export default function ContentExample({ blocks, }: { @@ -29,7 +26,7 @@ export default function ContentExample({ frontmatter: any; content: any; }) { - + const fileRenderType = '_indexmd'; return ( From 8844cb50d8840464be8d479cf3fc5fa2ac62cdfe Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Sat, 18 Jan 2025 00:25:39 +0530 Subject: [PATCH 7/8] fixed-the-test-issue --- cypress/components/DocsHelp.cy.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cypress/components/DocsHelp.cy.tsx b/cypress/components/DocsHelp.cy.tsx index 42eaf7f41..7d2dd7162 100644 --- a/cypress/components/DocsHelp.cy.tsx +++ b/cypress/components/DocsHelp.cy.tsx @@ -262,5 +262,12 @@ describe('DocsHelp Component', () => { expectedGitRedirect, ); }); + const customLink = 'https://example.com/custom-docs'; + cy.mount(); + cy.get('[data-test="edit-on-github-link"]').should( + 'have.attr', + 'href', + customLink, + ); }); }); From 233d6fd514bd2bd01e81f99cd120c171be1023e8 Mon Sep 17 00:00:00 2001 From: Yashwanth1906 Date: Sat, 18 Jan 2025 23:59:21 +0530 Subject: [PATCH 8/8] added-showEditOption-functionality --- components/DocsHelp.tsx | 50 +++++++++++++++++------------- cypress/components/DocsHelp.cy.tsx | 10 ++++++ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index da58226e8..8fa21d48b 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -4,8 +4,12 @@ import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment'; interface DocsHelpProps { fileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md' | string; + showEditOption?: boolean; } -export function DocsHelp({ fileRenderType }: DocsHelpProps) { +export function DocsHelp({ + fileRenderType, + showEditOption = true, +}: DocsHelpProps) { const router = useRouter(); const [isFormOpen, setIsFormOpen] = useState(false); const [feedbackStatus, setFeedbackStatus] = useState(''); @@ -308,28 +312,30 @@ export function DocsHelp({ fileRenderType }: DocsHelpProps) { type of contribution!

- + + Edit this page on Github + + + )}