Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: link-redirect-fix #1046

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions components/DocsHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment';

interface DocsHelpProps {
markdownFile?: string;
FileRenderType?: '_indexmd' | 'indexmd' | 'tsx' | '_md';
Yashwanth1906 marked this conversation as resolved.
Show resolved Hide resolved
}

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<HTMLFormElement>(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'}`;

Check warning on line 20 in components/DocsHelp.tsx

View check run for this annotation

Codecov / codecov/patch

components/DocsHelp.tsx#L20

Added line #L20 was not covered by tests
} else if (FileRenderType === 'indexmd') {
gitredirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(router.asPath) + '/index.md'}`;

Check warning on line 22 in components/DocsHelp.tsx

View check run for this annotation

Codecov / codecov/patch

components/DocsHelp.tsx#L22

Added line #L22 was not covered by tests
} 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!);
Expand Down Expand Up @@ -301,7 +309,7 @@
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'
>
<svg
Expand Down
8 changes: 4 additions & 4 deletions cypress/components/DocsHelp.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe('DocsHelp Component', () => {
// 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 markdownFile = '_md';
mockRouter = mockNextRouter();
cy.viewport(1200, 800);
cy.mount(<DocsHelp markdownFile={markdownFile} />);
cy.mount(<DocsHelp FileRenderType={markdownFile} />);
});

// should render the component correctly
Expand Down Expand Up @@ -241,8 +241,8 @@ describe('DocsHelp Component', () => {
/* Note: Already checking with _index markdown file in the first test case */

// render with _indexPage markdown file
const markdownFile = '_indexPage';
cy.mount(<DocsHelp markdownFile={markdownFile} />);
const markdownFile = 'tsx';
cy.mount(<DocsHelp FileRenderType={markdownFile} />);
cy.get(DOCS_HELP).should('exist');

// render without any markdown file
Expand Down
4 changes: 2 additions & 2 deletions pages/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;
return (
<SectionContext.Provider value={frontmatter.section || null}>
Expand All @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/docs/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DocsHelp } from '~/components/DocsHelp';

export default function Welcome() {
const newTitle = 'Welcome';
const markdownFile = 'tsx';
return (
<SectionContext.Provider value='docs'>
<Head>
Expand Down Expand Up @@ -56,7 +57,7 @@ export default function Welcome() {
link='/specification'
/>
</div>
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/draft-05/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export default function ImplementationsPages({
blocks: any;
frontmatter: any;
}) {
const markdownFile = 'indexmd';
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<StyledMarkdown markdown={blocks.body} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/draft-06/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;

return (
Expand All @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/draft-06/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export default function ImplementationsPages({
blocks: any;
frontmatter: any;
}) {
const markdownFile = 'indexmd';
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/draft-07/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;

return (
Expand All @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/draft-07/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export default function ImplementationsPages({
blocks: any;
frontmatter: any;
}) {
const markdownFile = 'indexmd';
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/draft/2019-09/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;

return (
Expand All @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/draft/2019-09/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export default function ImplementationsPages({
blocks: any;
frontmatter: any;
}) {
const markdownFile = 'indexmd';
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/draft/2020-12/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;

return (
Expand All @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/draft/2020-12/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export default function ImplementationsPages({
blocks: any;
frontmatter: any;
}) {
const markdownFile = 'indexmd';
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/implementers/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;
return (
<SectionContext.Provider value={frontmatter.section || null}>
Expand All @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/implementers/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getStaticProps() {
}

export default function ContentExample({ blocks }: { blocks: any[] }) {
const markdownFile = '_indexPage';
const markdownFile = '_indexmd';

return (
<SectionContext.Provider value='docs'>
Expand All @@ -45,7 +45,7 @@ export default function ContentExample({ blocks }: { blocks: any[] }) {
/>
</div>
</section>
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/learn/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;
return (
<SectionContext.Provider value={frontmatter.section || null}>
Expand All @@ -31,7 +31,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/learn/getting-started-step-by-step/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getStaticProps() {

export default function StyledValidator({ blocks }: { blocks: any[] }) {
const newTitle = 'Creating your first schema';

const markdownFile = 'tsx';
return (
<SectionContext.Provider value='docs'>
<Head>
Expand All @@ -40,7 +40,7 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) {
<StyledMarkdown markdown={blocks[0]} />
<GettingStarted />
<StyledMarkdown markdown={blocks[1]} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/learn/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Card from '~/components/Card';
import { DocsHelp } from '~/components/DocsHelp';

export default function Welcome() {
const markdownFile = '_indexPage';
const markdownFile = 'tsx';

const newTitle = 'Getting Started';
return (
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function Welcome() {
link='https://tour.json-schema.org/'
/>
</div>
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/overview/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function StaticMarkdownPage({
frontmatter: any;
content: any;
}) {
const markdownFile = '_index';
const markdownFile = '_md';
const newTitle = 'JSON Schema - ' + frontmatter.title;

return (
Expand All @@ -32,7 +32,7 @@ export default function StaticMarkdownPage({
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/overview/case-studies/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useTheme } from 'next-themes';

export default function ContentExample() {
const newTitle = 'Case Studies';
const markdownFile = '_indexPage';
const markdownFile = 'tsx';
const { resolvedTheme } = useTheme();

const imgUrl = (src: string): string => {
Expand Down Expand Up @@ -47,7 +47,7 @@ export default function ContentExample() {
/>
))}
</div>
<DocsHelp markdownFile={markdownFile} />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/overview/code-of-conduct/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export async function getStaticProps() {

export default function Content({ blocks }: { blocks: any[] }) {
const newTitle = 'Code of Conduct';

const markdownFile = '_indexmd';
return (
<SectionContext.Provider value='docs'>
<Head>
<title>{newTitle}</title>
</Head>
<StyledMarkdown markdown={blocks[0]} />
<DocsHelp />
<DocsHelp FileRenderType={markdownFile} />
</SectionContext.Provider>
);
}
Expand Down
Loading
Loading