Skip to content

Commit

Permalink
Add the Code of Conduct and fix hydration issues due to markdown link…
Browse files Browse the repository at this point in the history
… references

* Adding the CoC through submodule + symlink
* Fixed hydration issues due to markdown link references
  • Loading branch information
benjagm committed Feb 16, 2024
1 parent 842cdd4 commit cfeb2a4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
[submodule "_includes/community"]
path = _includes/community
url = https://github.com/json-schema-org/community.git
[submodule "_includes/dot-github"]
path = _includes/dot-github
url = https://github.com/json-schema-org/.github.git
1 change: 1 addition & 0 deletions _includes/dot-github
Submodule dot-github added at 46e8b7
2 changes: 1 addition & 1 deletion components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const Footer = () => (
<a href='https://opencollective.com/json-schema' className='text-white mb-2'>Open Collective</a>
</div>
<div className='flex flex-col text-center sm:text-left'>
<a target='_blank' rel='noopener noreferrer' href='https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md' className='text-white mb-2'>Code of Conduct</a>
<a href='/overview/code-of-conduct' className='text-white mb-2'>Code of Conduct</a>
</div>
</div>
<div className='grid grid-cols-3 md:grid-cols-1 mx-auto md:mt-8 mb-4 md:mb-0 lg:ml-12'>
Expand Down
4 changes: 3 additions & 1 deletion components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const SegmentSubtitle = ({ label }: { label: string }) => {
}
const getDocsPath = [
'/overview/what-is-jsonschema',
'/overview/sponsors'
'/overview/sponsors',
'/overview/code-of-conduct'
]
const getStartedPath = [
'/learn/json-schema-examples',
Expand Down Expand Up @@ -206,6 +207,7 @@ export const DocsNav = () => {
>
<DocLink uri='/overview/what-is-jsonschema' label='What is JSON Schema?' />
<DocLink uri='/overview/sponsors' label='Sponsors' />
<DocLink uri='/overview/code-of-conduct' label='Code of Conduct' />
</div>
</div>
{/* Get Started */}
Expand Down
21 changes: 21 additions & 0 deletions components/StyledMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,30 @@ type Element = {
type: 'markdown' | 'tabs-group'
markdown: string
}
function transformMarkdownLinks(markdown: string): string {
const linkDefinitions: Record<string, string> = {};

// Extract and remove link definitions
markdown = markdown.replace(/^\[([^\]]+)\]:\s*(.+)$/gm, (_, key: string, value: string) => {
linkDefinitions[key.toLowerCase()] = value;
return '';
});

// Replace reference-style links with inline links
return markdown.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (_, text: string, id: string) => {
const link = linkDefinitions[id.toLowerCase()];
if (link) {
return `[${text}](${link})`;
}
return _; // Return the original string if no link is found
});
}

export default function StyledMarkdown ({ markdown }: { markdown?: string }) {
if (!markdown) return null

markdown = transformMarkdownLinks(markdown);

const sortedTabGroups = (getFindResultsByGlobalRegExp(markdown, REGEX_TAB_GROUPS) || [])
.sort((a, b) => a.index < b.index ? -1 : 1)
let textCuts = sortedTabGroups.map(tabGroup => ({
Expand Down
1 change: 1 addition & 0 deletions pages/overview/code-of-conduct/_index.md
31 changes: 31 additions & 0 deletions pages/overview/code-of-conduct/index.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { getLayout } from '~/components/Sidebar'
import fs from 'fs'
import Head from 'next/head'
import matter from 'gray-matter'
import StyledMarkdown from '~/components/StyledMarkdown'
import { SectionContext } from '~/context'

export async function getStaticProps() {
const block1 = fs.readFileSync('pages/overview/code-of-conduct/_index.md', 'utf-8')
const { content: block1Content } = matter(block1)
return {
props: {
blocks: [block1Content]
}
}
}

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

return (
<SectionContext.Provider value='docs'>
<Head>
<title>{newTitle}</title>
</Head>
<StyledMarkdown markdown={blocks[0]} />
</SectionContext.Provider>
)
}
ContentExample.getLayout = getLayout
2 changes: 0 additions & 2 deletions pages/overview/sponsors/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Head from 'next/head'
import { Headline1 } from '~/components/Headlines'
import matter from 'gray-matter'
import StyledMarkdown from '~/components/StyledMarkdown'
import { DocsHelp } from '~/components/DocsHelp'
import { SectionContext } from '~/context'

export async function getStaticProps() {
Expand All @@ -28,7 +27,6 @@ export default function ContentExample ({ blocks }: { blocks: any[] }) {
</Head>
<Headline1>{newTitle}</Headline1>
<StyledMarkdown markdown={blocks[0]} />
<DocsHelp />
</SectionContext.Provider>
)
}
Expand Down

0 comments on commit cfeb2a4

Please sign in to comment.