diff --git a/components/Code.tsx b/components/Code.tsx index 7460fa4e8..fb6f7f1ef 100644 --- a/components/Code.tsx +++ b/components/Code.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import classnames from 'classnames'; import { BlockContext, BlockContextValue } from '~/context'; -export default function Code({ children }: { children: any }) { +export default function Code({ children }: { children: React.ReactNode }) { // eslint-disable-next-line react-hooks/rules-of-hooks const blockContext = useContext(BlockContext); return ( diff --git a/components/DocTable.tsx b/components/DocTable.tsx index a8862797b..b717ab73e 100644 --- a/components/DocTable.tsx +++ b/components/DocTable.tsx @@ -3,16 +3,25 @@ import React from 'react'; import Link from 'next/link'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +interface Author { + name: string; + photo?: string; +} + interface DocTableProps { frontmatter: { - Specification: string; - Published: string; - authors: string[]; - Metaschema: string; + Specification?: string; + Published?: string; + authors?: (string | Author)[]; + Metaschema?: string; }; } const DocTable = ({ frontmatter }: DocTableProps) => { + const authors = frontmatter.authors ?? []; + const getAuthorName = (author: string | Author): string => + typeof author === 'string' ? author : author.name; + return ( @@ -22,63 +31,71 @@ const DocTable = ({ frontmatter }: DocTableProps) => {
-
-
-
- Specification -
-
- - {frontmatter.Specification} - + {frontmatter.Specification && ( +
+
+
+ Specification +
+
+ + {frontmatter.Specification} + +
-
-
-
-
- Published + )} + {frontmatter.Published && ( +
+
+
+ Published +
+
{frontmatter.Published}
-
{frontmatter.Published}
-
-
-
-
- Authors -
-
- {frontmatter.authors.map((author: string, index: number) => ( - - {author} - {index < frontmatter.authors.length - 1 ? ', ' : ''} - - ))} + )} + {authors.length > 0 && ( +
+
+
+ Authors +
+
+ {authors.map((author, index: number) => ( + + {getAuthorName(author)} + {index < authors.length - 1 ? ', ' : ''} + + ))} +
-
-
-
-
- Metaschema -
-
- - {frontmatter.Metaschema} - + )} + {frontmatter.Metaschema && ( +
+
+
+ Metaschema +
+
+ + {frontmatter.Metaschema} + +
-
+ )}
diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index e50ba43a9..6a4ae85d0 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -9,13 +9,21 @@ async function fetchData() { const response = await fetch('/data/getting-started-examples.json'); const data = await response.json(); - const defaultSchemaData = data.find((data: any) => data.default === true); + const defaultSchemaData = data.find( + (data: { default?: boolean; file: string; instances: unknown[] }) => + data.default === true, + ); const schemaResp = await fetch(defaultSchemaData.file); const schemaData = await schemaResp.json(); const defaultInstanceData = defaultSchemaData.instances.find( - (instance: any) => instance.default === true, + (instance: { + default?: boolean; + file: string; + details: string; + valid: string; + }) => instance.default === true, ); const instanceResp = await fetch(defaultInstanceData.file); @@ -31,11 +39,13 @@ async function fetchData() { } interface SchemaOption { + name: string; file: string; instances: InstanceOption[]; } interface InstanceOption { + name: string; file: string; details: string; valid: string; @@ -139,7 +149,7 @@ const GettingStarted = () => { id='Examples' onChange={handleSchemaChange} > - {options.map((option: any, id: number) => ( + {options.map((option, id) => ( @@ -194,7 +204,7 @@ const GettingStarted = () => { id='Examples' onChange={handleInstanceChange} > - {instances.map((instance: any, id: number) => ( + {instances.map((instance, id) => ( diff --git a/components/JsonEditor.tsx b/components/JsonEditor.tsx index c7870e7ca..6bc07b561 100644 --- a/components/JsonEditor.tsx +++ b/components/JsonEditor.tsx @@ -1,7 +1,14 @@ /* eslint-disable linebreak-style */ import React, { useContext } from 'react'; import { BaseEditor, createEditor, Descendant, Text } from 'slate'; -import { Editable, ReactEditor, Slate, withReact } from 'slate-react'; +import { + Editable, + ReactEditor, + Slate, + withReact, + RenderLeafProps, + RenderElementProps, +} from 'slate-react'; import { cn } from '@/lib/utils'; import getPartsOfJson, { SyntaxPart } from '~/lib/getPartsOfJson'; import jsonSchemaReferences from './jsonSchemaLinks'; @@ -21,7 +28,7 @@ import { atomOneDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; type CustomElement = CustomNode | CustomText; type CustomNode = { type: 'paragraph'; children: CustomText[] }; -type CustomText = { text: string }; +type CustomText = { text: string; syntaxPart?: SyntaxPart }; declare module 'slate' { interface CustomTypes { @@ -215,7 +222,7 @@ const calculateNewDecorationsMap = ( textPathIndexes, ); const highlightingDecorations = multipathDecorations.reduce( - (acc, multipathDecoration: MultipathDecoration) => { + (acc: RangeWithSyntaxPart[], multipathDecoration: MultipathDecoration) => { const decorationsOfNodes = multipathDecoration.nodes.reduce( (acc: RangeWithSyntaxPart[], node: NodeRange) => { const decorationOfNode = { @@ -231,11 +238,11 @@ const calculateNewDecorationsMap = ( }; return [...acc, decorationOfNode]; }, - [], + [] as RangeWithSyntaxPart[], ); return [...acc, ...decorationsOfNodes]; }, - [], + [] as RangeWithSyntaxPart[], ); const decorationMap = makeDecorationsToMap(highlightingDecorations); @@ -359,7 +366,7 @@ export default function JsonEditor({ } }, [codeContent, isJsonMode]); - const parsedCode: null | any = React.useMemo(() => { + const parsedCode: Record | null = React.useMemo(() => { try { return JSON.parse(serializedCode); } catch (e) { @@ -404,8 +411,15 @@ export default function JsonEditor({ let text = ''; /* istanbul ignore else : there is no else block to test here */ if (value) { - value.forEach((e: any) => { - text += e.children[0].text + '\n'; + value.forEach((e: Descendant) => { + if ( + 'children' in e && + Array.isArray(e.children) && + e.children[0] && + 'text' in e.children[0] + ) { + text += (e.children[0] as Text).text + '\n'; + } }); } return text; @@ -414,10 +428,11 @@ export default function JsonEditor({ // copy status react state const [copied, setCopied] = React.useState(false); - const allPathDecorationsMap: Record = React.useMemo( - () => calculateNewDecorationsMap(value, isPartialSchema), - [value, isPartialSchema], - ); + const allPathDecorationsMap: Record = + React.useMemo( + () => calculateNewDecorationsMap(value, isPartialSchema), + [value, isPartialSchema], + ); // Badge text logic for regular code blocks const getBadgeText = () => { @@ -609,17 +624,19 @@ export default function JsonEditor({ /* istanbul ignore next: allPathDecorationsMap[stringPath] cannot be null */ return allPathDecorationsMap[stringPath] || []; }} - renderLeaf={(props: any) => { + renderLeaf={(props: RenderLeafProps) => { const { leaf, children, attributes } = props; + const syntaxType = leaf.syntaxPart?.type ?? ''; const textStyles: undefined | string = (() => { + const parentJsonPath = leaf.syntaxPart?.parentJsonPath ?? ''; if ( [ 'objectPropertyStartQuotes', 'objectPropertyEndQuotes', - ].includes(leaf.syntaxPart?.type) + ].includes(syntaxType) ) return 'text-blue-200'; - if (['objectProperty'].includes(leaf.syntaxPart?.type)) { + if (['objectProperty'].includes(syntaxType)) { const isJsonScope = jsonPathsWithJsonScope .filter( (jsonPathWithScope) => @@ -630,7 +647,7 @@ export default function JsonEditor({ (jsonPathsWithJsonScope) => jsonPathsWithJsonScope.jsonPath, ) - .includes(leaf.syntaxPart?.parentJsonPath); + .includes(parentJsonPath); if ( isJsonScope && jsonSchemaReferences.objectProperty[leaf.text] @@ -652,7 +669,7 @@ export default function JsonEditor({ 'arrayComma', 'arrayStartBracket', 'arrayEndBracket', - ].includes(leaf.syntaxPart?.type) + ].includes(syntaxType) ) return 'text-slate-400'; if ( @@ -661,19 +678,20 @@ export default function JsonEditor({ 'stringValue', 'booleanValue', 'nullValue', - ].includes(leaf.syntaxPart?.type) + ].includes(syntaxType) ) return 'text-lime-200'; // Handle partial schema specific highlighting that might not match exactly - if (!leaf.syntaxPart?.type) { + if (!syntaxType) { // If no syntax part type, apply default white color for partial schemas return isPartialSchema ? 'text-white' : undefined; } })(); const link: null | string = (() => - jsonSchemaReferences?.[leaf.syntaxPart?.type]?.[leaf.text] || + (syntaxType && + jsonSchemaReferences?.[syntaxType]?.[leaf.text]) || null)(); return ( @@ -691,7 +709,7 @@ export default function JsonEditor({ ); }} - renderElement={(props: any) => { + renderElement={(props: RenderElementProps) => { // This will be the path to the image element. const { element, children, attributes } = props; const path = ReactEditor.findPath(editor, element); @@ -783,18 +801,20 @@ export type PathIndex = [number, number[]]; const getMultipathDecorationsByMatchesAndTextPathIndexes = ( syntaxParts: SyntaxPart[], textPathIndexes: PathIndex[], -): any[] => { - const multipathDecorations: any[] = syntaxParts.map((syntaxPart) => { - const nodes = getNodesFromIndexAndLength( - syntaxPart.index, - syntaxPart.length, - textPathIndexes, - ); - return { - nodes: nodes, - syntaxPart, - }; - }); +): MultipathDecoration[] => { + const multipathDecorations: MultipathDecoration[] = syntaxParts.map( + (syntaxPart) => { + const nodes = getNodesFromIndexAndLength( + syntaxPart.index, + syntaxPart.length, + textPathIndexes, + ); + return { + nodes: nodes, + syntaxPart, + }; + }, + ); return multipathDecorations; }; @@ -802,10 +822,10 @@ export const getNodesFromIndexAndLength = ( index: number, length: number, textPathIndexes: PathIndex[], -): any[] => { +): NodeRange[] => { const { nodes } = textPathIndexes.reduce( ( - acc: { nodes: any[]; index: number; length: number }, + acc: { nodes: NodeRange[]; index: number; length: number }, textPathIndex: PathIndex, ) => { if (acc.length <= 0) return acc; @@ -816,7 +836,7 @@ export const getNodesFromIndexAndLength = ( const anchor = acc.index; const focus = Math.min(anchor + acc.length, textPathLength); const lengthInNode = focus - anchor; - const node: any = { anchor, focus, path: nodePath }; + const node: NodeRange = { anchor, focus, path: nodePath }; return { nodes: [...acc.nodes, node], index: 0, @@ -828,9 +848,14 @@ export const getNodesFromIndexAndLength = ( return nodes; }; -const makeDecorationsToMap = (decorations: any[]): Record => { - return decorations.reduce((acc, decoration) => { - const stringPath = decoration.anchor.path.join(','); - return { ...acc, [stringPath]: [...(acc[stringPath] || []), decoration] }; - }, {}); +const makeDecorationsToMap = ( + decorations: RangeWithSyntaxPart[], +): Record => { + return decorations.reduce( + (acc, decoration) => { + const stringPath = decoration.anchor.path.join(','); + return { ...acc, [stringPath]: [...(acc[stringPath] || []), decoration] }; + }, + {} as Record, + ); }; diff --git a/components/Layout.tsx b/components/Layout.tsx index 32879f12c..d9ef519f9 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -32,7 +32,9 @@ export default function Layout({ metaTitle, whiteBg, }: Props) { - const showMobileNav = useStore((s: any) => s.overlayNavigation === 'docs'); + const showMobileNav = useStore( + (s: { overlayNavigation: string | null }) => s.overlayNavigation === 'docs', + ); const router = useRouter(); @@ -60,7 +62,7 @@ export default function Layout({ const handleCloseNavbar = (event: MouseEvent) => { if ( mobileNavRef.current && - (mobileNavRef.current as any).contains(event.target) + mobileNavRef.current.contains(event.target as Node) ) { useStore.setState({ overlayNavigation: null }); } @@ -176,7 +178,9 @@ const MainNavLink = ({ const MainNavigation = () => { const section = useContext(SectionContext); - const showMobileNav = useStore((s: any) => s.overlayNavigation === 'docs'); + const showMobileNav = useStore( + (s: { overlayNavigation: string | null }) => s.overlayNavigation === 'docs', + ); const { resolvedTheme, theme } = useTheme(); const [icon, setIcon] = useState(''); diff --git a/pages/[slug].page.tsx b/pages/[slug].page.tsx index 7a9e7726e..22eab1a2a 100644 --- a/pages/[slug].page.tsx +++ b/pages/[slug].page.tsx @@ -8,11 +8,12 @@ import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import type { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages'); } @@ -20,8 +21,8 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; diff --git a/pages/ambassadors/index.page.tsx b/pages/ambassadors/index.page.tsx index 259d32035..1f713a1c0 100644 --- a/pages/ambassadors/index.page.tsx +++ b/pages/ambassadors/index.page.tsx @@ -26,7 +26,7 @@ export async function getStaticProps() { export default function ambassadorPages({ ambassadorData, }: { - ambassadorData: any; + ambassadorData: string; }) { return ( diff --git a/pages/draft-05/index.page.tsx b/pages/draft-05/index.page.tsx index e8c83ca8c..939ce5608 100644 --- a/pages/draft-05/index.page.tsx +++ b/pages/draft-05/index.page.tsx @@ -8,6 +8,7 @@ import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-05/index.md', 'utf-8'); @@ -27,12 +28,23 @@ export async function getStaticProps() { }; } +interface DraftFrontmatter extends Frontmatter { + Specification?: string; + Published?: string; + Metaschema?: string; +} + +interface BlocksData { + index: string; + body: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: DraftFrontmatter; }) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/draft-06/[slug].page.tsx b/pages/draft-06/[slug].page.tsx index 64655ed3c..1b4dcd2be 100644 --- a/pages/draft-06/[slug].page.tsx +++ b/pages/draft-06/[slug].page.tsx @@ -7,11 +7,12 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft-06'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/draft-06'); } @@ -19,14 +20,14 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} diff --git a/pages/draft-06/index.page.tsx b/pages/draft-06/index.page.tsx index 12a760519..1b2b3c0c3 100644 --- a/pages/draft-06/index.page.tsx +++ b/pages/draft-06/index.page.tsx @@ -8,6 +8,7 @@ import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-06/index.md', 'utf-8'); @@ -25,12 +26,22 @@ export async function getStaticProps() { }; } +interface DraftFrontmatter extends Frontmatter { + Specification?: string; + Published?: string; + Metaschema?: string; +} + +interface BlocksData { + index: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: DraftFrontmatter; }) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/draft-07/[slug].page.tsx b/pages/draft-07/[slug].page.tsx index f4ef2b082..68b7eaf41 100644 --- a/pages/draft-07/[slug].page.tsx +++ b/pages/draft-07/[slug].page.tsx @@ -7,11 +7,12 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft-07'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/draft-07'); } @@ -19,14 +20,14 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} diff --git a/pages/draft-07/index.page.tsx b/pages/draft-07/index.page.tsx index a639ca275..f727b6f9a 100644 --- a/pages/draft-07/index.page.tsx +++ b/pages/draft-07/index.page.tsx @@ -8,6 +8,7 @@ import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-07/index.md', 'utf-8'); @@ -25,12 +26,22 @@ export async function getStaticProps() { }; } +interface DraftFrontmatter extends Frontmatter { + Specification?: string; + Published?: string; + Metaschema?: string; +} + +interface BlocksData { + index: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: DraftFrontmatter; }) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/draft/2019-09/[slug].page.tsx b/pages/draft/2019-09/[slug].page.tsx index 26acaf0e1..5252c4a30 100644 --- a/pages/draft/2019-09/[slug].page.tsx +++ b/pages/draft/2019-09/[slug].page.tsx @@ -7,11 +7,12 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft/2019-09'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/draft/2019-09'); } @@ -19,14 +20,14 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} diff --git a/pages/draft/2019-09/index.page.tsx b/pages/draft/2019-09/index.page.tsx index 51898b28e..81fbc7bf5 100644 --- a/pages/draft/2019-09/index.page.tsx +++ b/pages/draft/2019-09/index.page.tsx @@ -8,6 +8,7 @@ import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft/2019-09/index.md', 'utf-8'); @@ -24,12 +25,22 @@ export async function getStaticProps() { }; } +interface DraftFrontmatter extends Frontmatter { + Specification?: string; + Published?: string; + Metaschema?: string; +} + +interface BlocksData { + index: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: DraftFrontmatter; }) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/draft/2020-12/[slug].page.tsx b/pages/draft/2020-12/[slug].page.tsx index cc2331502..14176f965 100644 --- a/pages/draft/2020-12/[slug].page.tsx +++ b/pages/draft/2020-12/[slug].page.tsx @@ -7,11 +7,12 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft/2020-12'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/draft/2020-12'); } @@ -19,14 +20,14 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} diff --git a/pages/draft/2020-12/index.page.tsx b/pages/draft/2020-12/index.page.tsx index b5162ef02..64b5be76f 100644 --- a/pages/draft/2020-12/index.page.tsx +++ b/pages/draft/2020-12/index.page.tsx @@ -8,6 +8,7 @@ import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft/2020-12/index.md', 'utf-8'); @@ -24,12 +25,22 @@ export async function getStaticProps() { }; } +interface DraftFrontmatter extends Frontmatter { + Specification?: string; + Published?: string; + Metaschema?: string; +} + +interface BlocksData { + index: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: DraftFrontmatter; }) { const fileRenderType = 'indexmd'; return ( diff --git a/pages/implementers/[slug].page.tsx b/pages/implementers/[slug].page.tsx index c149e95eb..8dfd7af40 100644 --- a/pages/implementers/[slug].page.tsx +++ b/pages/implementers/[slug].page.tsx @@ -8,11 +8,12 @@ import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/implementers'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/implementers'); } @@ -20,13 +21,13 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} diff --git a/pages/implementers/index.page.tsx b/pages/implementers/index.page.tsx index 7579ba030..23b3af754 100644 --- a/pages/implementers/index.page.tsx +++ b/pages/implementers/index.page.tsx @@ -17,13 +17,8 @@ export async function getStaticProps() { }, }; } -export default function ContentExample({ - blocks, -}: { - blocks: any[]; - frontmatter: any; - content: any; -}) { + +export default function ContentExample({ blocks }: { blocks: string[] }) { const fileRenderType = '_indexmd'; return ( diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index d186f1a4d..ad657ed70 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -8,11 +8,12 @@ import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/learn'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/learn'); } @@ -20,13 +21,13 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} 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 de2cab73f..e20ad14f8 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -29,13 +29,7 @@ export async function getStaticProps() { }; } -export default function StyledValidator({ - blocks, -}: { - blocks: any[]; - frontmatter: any; - content: any; -}) { +export default function StyledValidator({ blocks }: { blocks: string[] }) { const newTitle = 'Creating your first schema'; const fileRenderType = 'tsx'; return ( diff --git a/pages/overview/[slug].page.tsx b/pages/overview/[slug].page.tsx index c50fa4f39..3b37072e4 100644 --- a/pages/overview/[slug].page.tsx +++ b/pages/overview/[slug].page.tsx @@ -8,11 +8,12 @@ import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/overview'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps(args, 'pages/overview'); } @@ -20,24 +21,24 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const fileRenderType = '_md'; const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - + {newTitle} {frontmatter.title} diff --git a/pages/overview/code-of-conduct/index.page.tsx b/pages/overview/code-of-conduct/index.page.tsx index 75e6000f2..82a99b1ed 100644 --- a/pages/overview/code-of-conduct/index.page.tsx +++ b/pages/overview/code-of-conduct/index.page.tsx @@ -21,13 +21,7 @@ export async function getStaticProps() { }; } -export default function Content({ - blocks, -}: { - blocks: any[]; - frontmatter: any; - content: any; -}) { +export default function Content({ blocks }: { blocks: string[] }) { const newTitle = 'Code of Conduct'; const fileRenderType = 'https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'; diff --git a/pages/overview/sponsors/index.page.tsx b/pages/overview/sponsors/index.page.tsx index c3c59d4ee..6c88b38d0 100644 --- a/pages/overview/sponsors/index.page.tsx +++ b/pages/overview/sponsors/index.page.tsx @@ -19,7 +19,7 @@ export async function getStaticProps() { }; } -export default function ContentExample({ blocks }: { blocks: any[] }) { +export default function ContentExample({ blocks }: { blocks: string[] }) { const newTitle = 'Sponsors'; const fileRenderType = 'https://github.com/json-schema-org/community/blob/main/programs/sponsors/sponsors.md'; diff --git a/pages/specification/json-hyper-schema/index.page.tsx b/pages/specification/json-hyper-schema/index.page.tsx index 83d5376d8..21b07a40d 100644 --- a/pages/specification/json-hyper-schema/index.page.tsx +++ b/pages/specification/json-hyper-schema/index.page.tsx @@ -7,6 +7,7 @@ import { SectionContext } from '~/context'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticProps() { const index = fs.readFileSync( @@ -29,22 +30,31 @@ export async function getStaticProps() { }; } +interface SpecificationFrontmatter extends Frontmatter { + Specification?: string; +} + +interface BlocksData { + index: string; + body?: string; +} + export default function ImplementationsPages({ blocks, frontmatter, }: { - blocks: any; - frontmatter: any; + blocks: BlocksData; + frontmatter: SpecificationFrontmatter; }) { const fileRenderType = '_indexmd'; return ( {frontmatter.title} -

{frontmatter.type}

-

{frontmatter.Specification}

+ {frontmatter.type &&

{frontmatter.type}

} + {frontmatter.Specification &&

{frontmatter.Specification}

} - + {blocks.body && } {frontmatter.title} - + {blocks.body && }
{frontmatter.title} - + {blocks.body && }
+ {newTitle} diff --git a/pages/understanding-json-schema/index.page.tsx b/pages/understanding-json-schema/index.page.tsx index 40ed5c449..9e819ce51 100644 --- a/pages/understanding-json-schema/index.page.tsx +++ b/pages/understanding-json-schema/index.page.tsx @@ -19,13 +19,8 @@ export async function getStaticProps() { }, }; } -export default function ContentExample({ - blocks, -}: { - blocks: any[]; - frontmatter: any; - content: any; -}) { + +export default function ContentExample({ blocks }: { blocks: string[] }) { const fileRenderType = '_indexmd'; return ( diff --git a/pages/understanding-json-schema/reference/[slug].page.tsx b/pages/understanding-json-schema/reference/[slug].page.tsx index dc87fef98..eb6faf5ff 100644 --- a/pages/understanding-json-schema/reference/[slug].page.tsx +++ b/pages/understanding-json-schema/reference/[slug].page.tsx @@ -8,11 +8,12 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import NextPrevButton from '~/components/NavigationButtons'; +import { Frontmatter } from '~/types/common'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/understanding-json-schema/reference'); } -export async function getStaticProps(args: any) { +export async function getStaticProps(args: { params?: { slug: string } }) { return getStaticMarkdownProps( args, 'pages/understanding-json-schema/reference', @@ -23,13 +24,13 @@ export default function StaticMarkdownPage({ frontmatter, content, }: { - frontmatter: any; - content: any; + frontmatter: Frontmatter; + content: string; }) { const newTitle = 'JSON Schema - ' + frontmatter.title; const fileRenderType = '_md'; return ( - + {newTitle} diff --git a/types/common.ts b/types/common.ts new file mode 100644 index 000000000..decc5bc29 --- /dev/null +++ b/types/common.ts @@ -0,0 +1,122 @@ +// Common type definitions for the JSON Schema website +import React from 'react'; + +// Author type for blog posts and content +export interface Author { + name: string; + photo: string; + twitter?: string; + link?: string; +} + +// Frontmatter type for markdown files +export interface Frontmatter { + title: string; + date?: string; + excerpt?: string; + cover?: string; + authors?: Author[]; + type?: string | string[]; + section?: SectionType; + prev?: NavLink; + next?: NavLink; + [key: string]: unknown; +} + +// Props for getStaticProps parameter +export interface StaticPropsParams { + params?: { + slug: string; + }; +} + +// Return type for markdown page props +export interface MarkdownPageProps { + frontmatter: Frontmatter; + content: string; +} + +// Props for pages with blocks +export interface PageWithBlocksProps extends MarkdownPageProps { + blocks: string[]; +} + +// Calendar event type +export interface CalendarEvent { + title: string; + time: string; + day: string; + timezone: string; + parsedStartDate: string; +} + +// iCal event data structure +export interface ICalEventData { + [key: string]: { + type: string; + summary?: string; + start?: { + tz: string; + [key: string]: unknown; + }; + rrule?: { + between: (start: Date, end: Date, inclusive: boolean) => Date[]; + }; + [key: string]: unknown; + }; +} + +// Blog post structure +export interface BlogPost { + slug: string; + frontmatter: Frontmatter; + content: string; +} + +// Slate editor types for JsonEditor +export interface SlateRenderProps { + attributes: { + 'data-slate-node'?: string; + 'data-slate-inline'?: boolean; + 'data-slate-void'?: boolean; + dir?: 'rtl'; + ref: React.RefObject; + [key: string]: unknown; + }; + children: React.ReactNode; + element?: unknown; + leaf?: unknown; + text?: { + text: string; + [key: string]: unknown; + }; +} + +// Section context type +export type SectionType = + | 'learn' + | 'docs' + | 'implementers' + | 'tools' + | 'implementations' + | 'blog' + | 'community' + | 'specification' + | 'overview' + | 'getting-started' + | 'reference' + | 'roadmap' + | 'ambassador' + | 'pro-help' + | null; + +// Navigation link type +export interface NavLink { + label: string; + url: string; +} + +// JSON Schema specific types +export interface JsonKeywordValue { + [key: string]: unknown; +}