|
| 1 | +import React from 'react'; |
| 2 | +import Head from 'next/head'; |
| 3 | + |
| 4 | +import fs from 'fs'; |
| 5 | +import { getLayout } from '~/components/Sidebar'; |
| 6 | +import yaml from 'js-yaml'; |
| 7 | +import { SectionContext } from '~/context'; |
| 8 | +import { Headline1, Headline4 } from '~/components/Headlines'; |
| 9 | +import { DocsHelp } from '~/components/DocsHelp'; |
| 10 | +import Link from 'next/link'; |
| 11 | +import Image from 'next/image'; |
| 12 | + |
| 13 | +export async function getStaticProps() { |
| 14 | + const datas = yaml.load(fs.readFileSync('data/keywords.yml', 'utf-8')); |
| 15 | + |
| 16 | + return { |
| 17 | + props: { |
| 18 | + datas, |
| 19 | + }, |
| 20 | + }; |
| 21 | +} |
| 22 | + |
| 23 | +interface DataObject { |
| 24 | + name: string; |
| 25 | + vocabulary: string[]; |
| 26 | + learnjsonschemalink: string; |
| 27 | + links?: LinkObject[]; |
| 28 | +} |
| 29 | + |
| 30 | +interface LinkObject { |
| 31 | + url: string; |
| 32 | + title: string; |
| 33 | +} |
| 34 | + |
| 35 | +export default function StaticMarkdownPage({ datas }: { datas: DataObject[] }) { |
| 36 | + const markdownFile = '_index'; |
| 37 | + return ( |
| 38 | + <SectionContext.Provider value={null}> |
| 39 | + <Head> |
| 40 | + <title>JSON Schema - Keywords</title> |
| 41 | + </Head> |
| 42 | + <Headline1>JSON Schema Keywords</Headline1> |
| 43 | + <p className='text-slate-600 block leading-7 dark:text-slate-300'> |
| 44 | + JSON Schema keywords are the building blocks of JSON Schema. They are |
| 45 | + used to define the structure of a JSON document |
| 46 | + </p> |
| 47 | + |
| 48 | + <div className='mt-4'> |
| 49 | + {datas |
| 50 | + .sort((a: DataObject, b: DataObject) => a.name.localeCompare(b.name)) |
| 51 | + .map( |
| 52 | + (data: DataObject, index: number) => |
| 53 | + data.links && ( |
| 54 | + <div key={index} className='mt-4'> |
| 55 | + <div className='flex flex-row items-center gap-2'> |
| 56 | + <Headline4>{data.name}</Headline4> |
| 57 | + <Link href={data.learnjsonschemalink} target='_blank'> |
| 58 | + <Image |
| 59 | + src={'/icons/external-link.svg'} |
| 60 | + height={20} |
| 61 | + width={20} |
| 62 | + className='mt-3' |
| 63 | + alt='external link' |
| 64 | + title='Learn JSON Schema' |
| 65 | + /> |
| 66 | + </Link> |
| 67 | + </div> |
| 68 | + <ul className='mt-1 list-disc text-blue-500 ml-7'> |
| 69 | + {data.links?.map((link: LinkObject, index: number) => ( |
| 70 | + <li key={index}> |
| 71 | + <Link href={link.url} className=' hover:underline'> |
| 72 | + {link.title} |
| 73 | + </Link> |
| 74 | + </li> |
| 75 | + ))} |
| 76 | + </ul> |
| 77 | + </div> |
| 78 | + ), |
| 79 | + )} |
| 80 | + </div> |
| 81 | + |
| 82 | + <DocsHelp markdownFile={markdownFile} /> |
| 83 | + </SectionContext.Provider> |
| 84 | + ); |
| 85 | +} |
| 86 | +StaticMarkdownPage.getLayout = getLayout; |
0 commit comments