From bfc0c275230e975b0c11c5d371a679252e07a751 Mon Sep 17 00:00:00 2001 From: techmannih Date: Tue, 19 Nov 2024 17:18:47 +0530 Subject: [PATCH 1/2] fix: Implement a TOC component --- components/Sidebar.tsx | 2 +- components/StyledMarkdown.tsx | 120 ++++++++---------- pages/[slug].page.tsx | 26 +++- pages/implementers/[slug].page.tsx | 25 +++- pages/learn/[slug].page.tsx | 28 +++- pages/learn/file-system.md | 32 ++--- .../getting-started-step-by-step.md | 1 - .../index.page.tsx | 35 +++-- pages/learn/json-schema-examples.md | 11 -- pages/learn/miscellaneous-examples.md | 8 -- pages/overview/[slug].page.tsx | 31 +++-- pages/specification-links.md | 1 - .../json-hyper-schema/index.page.tsx | 25 +++- .../understanding-json-schema/[slug].page.tsx | 31 ++++- .../reference/[slug].page.tsx | 40 ++++-- .../reference/array.md | 14 +- .../reference/conditionals.md | 6 +- .../reference/numeric.md | 6 +- .../reference/object.md | 14 +- .../reference/schema.md | 2 +- .../reference/string.md | 8 +- .../understanding-json-schema/structuring.md | 21 +-- 22 files changed, 275 insertions(+), 212 deletions(-) diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index 6370bb406..b93ddd0ae 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -244,7 +244,7 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => { variant='sidebar' /> -
+
{children}
diff --git a/components/StyledMarkdown.tsx b/components/StyledMarkdown.tsx index a56cd48ee..ed676e1e3 100644 --- a/components/StyledMarkdown.tsx +++ b/components/StyledMarkdown.tsx @@ -554,9 +554,6 @@ export function TableOfContentMarkdown({ href={`#${slug}`} className='block cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-[-0.40rem] font-medium' > - - ● - {children} ); @@ -567,91 +564,76 @@ export function TableOfContentMarkdown({ h2: depth === 0 ? { + component: ({ children }) => { + const slug = slugifyMarkdownHeadline(children); + return ( + + {children} + + ); + }, + } + : depth >= 2 + ? { component: ({ children }) => { const slug = slugifyMarkdownHeadline(children); + const [isChrome, setIsChrome] = useState(false); + + useEffect(() => { + const chromeCheck = + /Chrome/.test(navigator.userAgent) && + /Google Inc/.test(navigator.vendor); + setIsChrome(chromeCheck); + }, []); + return ( + // chromeClass + {children} ); }, } - : depth >= 2 - ? { - component: ({ children }) => { - const slug = slugifyMarkdownHeadline(children); - const [isChrome, setIsChrome] = useState(false); - - useEffect(() => { - const chromeCheck = - /Chrome/.test(navigator.userAgent) && - /Google Inc/.test(navigator.vendor); - setIsChrome(chromeCheck); - }, []); - - return ( - // chromeClass - - - ● - - {children} - - ); - }, - } : { component: () => null }, h3: depth >= 3 ? { - component: ({ children }) => { - const slug = slugifyMarkdownHeadline(children); - return ( - - - —— - - - ● - + component: ({ children }) => { + const slug = slugifyMarkdownHeadline(children); + return ( + - {children} - - ); - }, - } + {children} + + ); + }, + } : { component: () => null }, h4: - depth >= 4 + depth <= 4 ? { - component: ({ children }) => { - const slug = slugifyMarkdownHeadline(children); - return ( - - - ———— - - - ● - - - {children} - - ); - }, - } /* eslint-enable */ + component: ({ children }) => { + const slug = slugifyMarkdownHeadline(children); + return ( + + {children} + + ); + }, + } /* eslint-enable */ : { component: () => null }, ...hiddenElements( 'strong', diff --git a/pages/[slug].page.tsx b/pages/[slug].page.tsx index 4bd646418..05e750c88 100644 --- a/pages/[slug].page.tsx +++ b/pages/[slug].page.tsx @@ -7,6 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; // Import TOC component export async function getStaticPaths() { return getStaticMarkdownPaths('pages'); @@ -26,12 +27,25 @@ export default function StaticMarkdownPage({ const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - - {newTitle} - - {frontmatter.title} - - + +
+
+ + {newTitle} + + {frontmatter.title} + + +
+
+
+
+ On this page +
+ +
+
+
); } diff --git a/pages/implementers/[slug].page.tsx b/pages/implementers/[slug].page.tsx index c86202c00..0baed655c 100644 --- a/pages/implementers/[slug].page.tsx +++ b/pages/implementers/[slug].page.tsx @@ -7,6 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/implementers'); @@ -26,12 +27,24 @@ export default function StaticMarkdownPage({ const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - - {newTitle} - - {frontmatter.title} - - +
+
+ + {newTitle} + + {frontmatter.title} + + +
+
+
+
+ On this page +
+ +
+
+
); } diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index f110ff75d..d07df01f8 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -7,6 +7,9 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { + TableOfContentMarkdown, +} from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/learn'); @@ -26,13 +29,26 @@ export default function StaticMarkdownPage({ const newTitle = 'JSON Schema - ' + frontmatter.title; return ( - - {newTitle} - - {frontmatter.title} - - +
+
+ + {newTitle} + + {frontmatter.title} + + +
+
+
+
+ On this page +
+ +
+
+
); } + StaticMarkdownPage.getLayout = getLayout; diff --git a/pages/learn/file-system.md b/pages/learn/file-system.md index a408b70b1..bace51cb5 100644 --- a/pages/learn/file-system.md +++ b/pages/learn/file-system.md @@ -5,20 +5,8 @@ title: Modeling a file system with JSON Schema In this step-by-step guide you will learn how to design a JSON Schema that mirrors the structure of an `/etc/fstab` file. -This guide is divided into the following sections: -* [Introduction](#introduction) -* [Creating the `fstab` schema](#fstab-schema) -* [Starting the `entry` schema](#entry-schema) -* [Constraining an entry](#constraining-entry) -* [The `diskDevice` definition](#diskdevice) -* [The `diskUUID` definition](#diskuuid) -* [The `nfs` definition](#nfs) -* [The `tmpfs` definition](#tmpfs) -* [The full entry schema](#full-entry) -* [Referencing the `entry` schema in the `fstab` schema](#referencing-entry) - -## Introduction[#introduction] +## Introduction > Not all constraints to an fstab file can be modeled using JSON Schema alone; however, it can represent a good number of them and the exercise is useful to demonstrate how constraints work. The examples provided are illustrative of the JSON Schema concepts rather than a real, working schema for an fstab file. @@ -60,7 +48,7 @@ An entry in an fstab file can have many different forms; Here is an example: } ``` -## Creating the `fstab` schema[#fstab-schema] +## Creating the `fstab` schema We will start with a base JSON Schema expressing the following constraints: @@ -100,7 +88,7 @@ Building out our JSON Schema from top to bottom: } ``` -## Starting the `entry` schema[#entry-schema] +## Starting the `entry` schema We will start with an outline of the JSON schema which adds new concepts to what we've already demonstrated. @@ -142,7 +130,7 @@ To this we add: } ``` -## Constraining an entry[#constraining-entry] +## Constraining an entry Let's now extend this skeleton to add constraints to some of the properties. @@ -198,7 +186,7 @@ With these added constraints, the schema now looks like this: } ``` -## The `diskDevice` definition[#diskdevice] +## The `diskDevice` definition One new keyword is introduced here: @@ -222,7 +210,7 @@ One new keyword is introduced here: } ``` -## The `diskUUID` definition[#diskuuid] +## The `diskUUID` definition No new keywords are introduced here. @@ -246,7 +234,7 @@ We do have a new key: `label` and the `pattern` validation keyword states it mus } ``` -## The `nfs` definition[#nfs] +## The `nfs` definition We find another new keyword: @@ -276,7 +264,7 @@ We find another new keyword: } ``` -## The `tmpfs` definition[#tmpfs] +## The `tmpfs` definition Our last definition introduces two new keywords: @@ -301,7 +289,7 @@ Our last definition introduces two new keywords: } ``` -## The full entry schema[#full-entry] +## The full entry schema The resulting schema is quite large: @@ -399,7 +387,7 @@ The resulting schema is quite large: } ``` -## Referencing the `entry` schema in the `fstab` schema[#referencing-entry] +## Referencing the `entry` schema in the `fstab` schema Coming full circle we use the `$ref` keyword to add our entry schema into the keys left empty at the start of the exercise: diff --git a/pages/learn/getting-started-step-by-step/getting-started-step-by-step.md b/pages/learn/getting-started-step-by-step/getting-started-step-by-step.md index 5926ddb1c..8c93da839 100644 --- a/pages/learn/getting-started-step-by-step/getting-started-step-by-step.md +++ b/pages/learn/getting-started-step-by-step/getting-started-step-by-step.md @@ -9,7 +9,6 @@ After creating your JSON Schema, you can then validate example data against your If you already know how to create JSON Schemas and you are looking for different JSON Schema use cases like schema generation, code generation, documentation, UI generation or JSON Schema processing or conversion, please visit [Tools](https://json-schema.org/tools) and explore the amazing tooling available in the JSON Schema Ecosystem. - 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..122ea6d93 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -9,7 +9,9 @@ import StyledMarkdown from '~/components/StyledMarkdown'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; import GettingStarted from '~/components/GettingStarted'; - +import { + TableOfContentMarkdown, +} from '~/components/StyledMarkdown'; export async function getStaticProps() { const block1 = fs.readFileSync( 'pages/learn/getting-started-step-by-step/getting-started-step-by-step.md', @@ -27,21 +29,32 @@ export async function getStaticProps() { }, }; } - export default function StyledValidator({ blocks }: { blocks: any[] }) { const newTitle = 'Creating your first schema'; return ( - - {newTitle} - - {newTitle} - - - - +
+
+ + {newTitle} + + {newTitle} + + + + +
+ +
+
+
On this page
+ +
+
+
); } -StyledValidator.getLayout = getLayout; + +StyledValidator.getLayout = getLayout; \ No newline at end of file diff --git a/pages/learn/json-schema-examples.md b/pages/learn/json-schema-examples.md index d86b9656b..a6e646a1f 100644 --- a/pages/learn/json-schema-examples.md +++ b/pages/learn/json-schema-examples.md @@ -5,17 +5,6 @@ title: JSON Schema examples In this page, you will find examples illustrating different use cases to help you get the most out of your JSON Schemas. These examples cover a wide range of scenarios, and each example comes with accompanying JSON data and explanation, showcasing how JSON Schemas can be applied to various domains. You can modify these examples to suit your specific needs, as this is just one of the many ways you can utilize JSON Schemas. -- [Address](#address) -- [Blog post](#blog-post) -- [Calendar](#calendar) -- [Device Type](#device-type) -- [Ecommerce System](#ecommerce-system) -- [Geographical location](#geographical-location) -- [Health record](#health-record) -- [Job posting](#job-posting) -- [Movie](#movie) -- [User profile](#user-profile) - ## Address diff --git a/pages/learn/miscellaneous-examples.md b/pages/learn/miscellaneous-examples.md index ba63f03b1..31bb8fb2c 100644 --- a/pages/learn/miscellaneous-examples.md +++ b/pages/learn/miscellaneous-examples.md @@ -5,14 +5,6 @@ title: Miscellaneous Examples In this page, you will find miscellaneous examples illustrating different uses cases to help you get the most out of your JSON Schemas. Each example comes with accompanying JSON data and explanation. -- [A typical minimum schema](#basic) -- [Arrays of things](#arrays-of-things) -- [Enumerated values](#enumerated-values) -- [Regular expression pattern](#regular-expression-pattern) -- [Complex object with nested properties](#complex-object-with-nested-properties) -- [Conditional validation with dependentRequired](#conditional-validation-with-dependentrequired) -- [Conditional validation with dependentSchemas](#conditional-validation-with-dependentschemas) -- [Conditional validation with if-else](#conditional-validation-with-if-else) ## Basic diff --git a/pages/overview/[slug].page.tsx b/pages/overview/[slug].page.tsx index e4d5476d7..a79d83fa2 100644 --- a/pages/overview/[slug].page.tsx +++ b/pages/overview/[slug].page.tsx @@ -7,7 +7,9 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; - +import { + TableOfContentMarkdown, +} from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/overview'); } @@ -27,13 +29,26 @@ export default function StaticMarkdownPage({ return ( - - {newTitle} - - {frontmatter.title} - - +
+
+ + {newTitle} + + {frontmatter.title} + + +
+
+
+
+ On this page +
+ +
+
+
); } -StaticMarkdownPage.getLayout = getLayout; + +StaticMarkdownPage.getLayout = getLayout; \ No newline at end of file diff --git a/pages/specification-links.md b/pages/specification-links.md index a327ef50d..f88a2895c 100644 --- a/pages/specification-links.md +++ b/pages/specification-links.md @@ -7,7 +7,6 @@ section: docs You can find the latest released draft on the [Specification](../../specification) page. The complex numbering and naming system for drafts and meta-schemas is fully explained here as well. - ## Understanding draft names and numbers diff --git a/pages/specification/json-hyper-schema/index.page.tsx b/pages/specification/json-hyper-schema/index.page.tsx index b1ce3264f..8cf3d3744 100644 --- a/pages/specification/json-hyper-schema/index.page.tsx +++ b/pages/specification/json-hyper-schema/index.page.tsx @@ -6,6 +6,7 @@ import StyledMarkdown from '~/components/StyledMarkdown'; import { SectionContext } from '~/context'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync( @@ -38,13 +39,25 @@ export default function ImplementationsPages({ const markdownFile = '_indexPage'; return ( - {frontmatter.title} -

{frontmatter.type}

-

{frontmatter.Specification}

+
+
+ {frontmatter.title} +

{frontmatter.type}

+

{frontmatter.Specification}

+ + + +
+
+
+
+ On this page +
+ +
+
- - - +
); } diff --git a/pages/understanding-json-schema/[slug].page.tsx b/pages/understanding-json-schema/[slug].page.tsx index 6174f5ea1..dfa727383 100644 --- a/pages/understanding-json-schema/[slug].page.tsx +++ b/pages/understanding-json-schema/[slug].page.tsx @@ -7,6 +7,14 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; import { SectionContext } from '~/context'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; + +// Function to remove all HTML tags +const stripHtmlTags = (markdown: string) => { + // Regular expression to remove all HTML tags + const htmlTagRegex = /<\/?[^>]+(>|$)/g; + return markdown.replace(htmlTagRegex, ''); +}; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/understanding-json-schema'); @@ -24,14 +32,25 @@ export default function StaticMarkdownPage({ }) { const markdownFile = '_index'; const newTitle = 'JSON Schema - ' + frontmatter.title; + const sanitizedContent = stripHtmlTags(content); return ( - - {newTitle} - - {frontmatter.title || 'NO TITLE!'} - - +
+
+ + {newTitle} + + {frontmatter.title || 'NO TITLE!'} + + +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/understanding-json-schema/reference/[slug].page.tsx b/pages/understanding-json-schema/reference/[slug].page.tsx index acab32f4c..52eb86fec 100644 --- a/pages/understanding-json-schema/reference/[slug].page.tsx +++ b/pages/understanding-json-schema/reference/[slug].page.tsx @@ -7,15 +7,19 @@ import getStaticMarkdownPaths from '~/lib/getStaticMarkdownPaths'; import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; + +const stripHtmlTags = (markdown: string) => { + const htmlTagRegex = /<\/?[^>]+(>|$)/g; + return markdown.replace(htmlTagRegex, ''); // Remove HTML tags +}; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/understanding-json-schema/reference'); } + export async function getStaticProps(args: any) { - return getStaticMarkdownProps( - args, - 'pages/understanding-json-schema/reference', - ); + return getStaticMarkdownProps(args, 'pages/understanding-json-schema/reference'); } export default function StaticMarkdownPage({ @@ -27,15 +31,31 @@ export default function StaticMarkdownPage({ }) { const newTitle = 'JSON Schema - ' + frontmatter.title; const markdownFile = '_index'; + + // Sanitize the markdown content to remove all HTML tags + const sanitizedContent = stripHtmlTags(content); + console.log('sanitizedContent', sanitizedContent); + return ( - - {newTitle} - - {frontmatter.title || 'NO TITLE!'} - - +
+
+ + {newTitle} + + {frontmatter.title || 'NO TITLE!'} + + +
+
+
+
On this page
+ +
+
+
); } + StaticMarkdownPage.getLayout = getLayout; diff --git a/pages/understanding-json-schema/reference/array.md b/pages/understanding-json-schema/reference/array.md index b6b9e05a5..242839d3f 100644 --- a/pages/understanding-json-schema/reference/array.md +++ b/pages/understanding-json-schema/reference/array.md @@ -56,7 +56,7 @@ There are two ways in which arrays are generally used in JSON: usage is often given a whole separate type in some programming languages, such as Python\'s `tuple`). -## Items[#items] +## Items List validation is useful for arrays of arbitrary length where each item matches the same schema. For this kind of array, set the `items` [keyword](../../learn/glossary#keyword) @@ -94,7 +94,7 @@ The empty array is always valid: -## Tuple validation[#tupleValidation] +## Tuple validation Tuple validation is useful when the array is a collection of items where each has a different schema and the ordinal index of each item is @@ -176,7 +176,7 @@ And, by default, it's also okay to add additional items to end: -### Additional Items[#additionalitems] +### Additional Items The `items` keyword can be used to control whether it\'s valid to have additional items in a tuple beyond what is defined in `prefixItems`. The @@ -261,7 +261,7 @@ Extra string items are ok ... -## Unevaluated Items[#unevaluateditems] +## Unevaluated Items @@ -392,7 +392,7 @@ items and reference `my-tuple#extended` when you need three items. -## Contains[#contains] +## Contains @@ -470,7 +470,7 @@ Fails `maxContains` -## Length[#length] +## Length The length of the array can be specified using the `minItems` and `maxItems` keywords. The value of each keyword must be a non-negative @@ -507,7 +507,7 @@ number. These keywords work whether doing [list validation](#items) or [tuple-va -## Uniqueness[#uniqueItems] +## Uniqueness A schema can ensure that each of the items in an array is unique. Simply set the `uniqueItems` keyword to `true`. diff --git a/pages/understanding-json-schema/reference/conditionals.md b/pages/understanding-json-schema/reference/conditionals.md index 7579ccfdd..cd6c3eaff 100644 --- a/pages/understanding-json-schema/reference/conditionals.md +++ b/pages/understanding-json-schema/reference/conditionals.md @@ -5,7 +5,7 @@ section: docs -## dependentRequired[#dependentRequired] +## dependentRequired The `dependentRequired` [keyword](../../learn/glossary#keyword) conditionally requires that certain properties must be present if a given property is present in an object. @@ -125,7 +125,7 @@ Previously to Draft 2019-09, ``dependentRequired`` and -## dependentSchemas [#dependentSchemas] +## dependentSchemas The `dependentSchemas` keyword conditionally applies a [subschema](../../learn/glossary#subschema) when a given property is present. This schema is applied in the same way @@ -191,7 +191,7 @@ Previously to Draft 2019-09, ``dependentRequired`` and -## If-Then-Else[#ifthenelse] +## If-Then-Else The `if`, `then` and `else` keywords allow the application of a subschema based diff --git a/pages/understanding-json-schema/reference/numeric.md b/pages/understanding-json-schema/reference/numeric.md index dbe32eaf5..eea2c32a6 100644 --- a/pages/understanding-json-schema/reference/numeric.md +++ b/pages/understanding-json-schema/reference/numeric.md @@ -11,7 +11,7 @@ They share the same validation [keywords](../../learn/glossary#keyword). > JSON has no standard way to represent complex numbers, so there is no way to test for them in JSON Schema. -## integer[#integer] +## integer The `integer` type is used for integral numbers. JSON does not have distinct types for integers and floating-point values. Therefore, the @@ -63,7 +63,7 @@ Numbers as strings are rejected: "42" ``` -## number[#number] +## number The `number` type is used for any numeric type, either integers or floating point numbers. @@ -165,7 +165,7 @@ The multiple can be a floating point number: -## Range[#range] +## Range Ranges of numbers are specified using a combination of the `minimum` and `maximum` keywords, (or `exclusiveMinimum` and `exclusiveMaximum` for diff --git a/pages/understanding-json-schema/reference/object.md b/pages/understanding-json-schema/reference/object.md index 421a21aeb..ec438507e 100644 --- a/pages/understanding-json-schema/reference/object.md +++ b/pages/understanding-json-schema/reference/object.md @@ -143,7 +143,7 @@ By default, providing additional properties is valid: { "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue", "direction": "NW" } ``` -## Pattern Properties [#patternProperties] +## Pattern Properties Sometimes you want to say that, given a particular kind of property name, the value should match a particular schema. That\'s where @@ -201,7 +201,7 @@ This is a key that doesn't match any of the regular expressions: { "keyword": "value" } ``` -## Additional Properties [#additionalproperties] +## Additional Properties The `additionalProperties` keyword is used to control the handling of extra stuff, that is, properties whose names are not listed in the @@ -313,7 +313,7 @@ It must be a string: { "keyword": 42 } ``` -### Extending Closed Schemas[#extending] +### Extending Closed Schemas It\'s important to note that `additionalProperties` only recognizes properties declared in the same [subschema](../../learn/glossary#subschema) as itself. So, @@ -423,7 +423,7 @@ necessary properties and the schema works as expected. Keep reading to see how the `unevaluatedProperties` keyword solves this problem without needing to redeclare properties. -## Unevaluated Properties [#unevaluatedproperties] +## Unevaluated Properties @@ -538,7 +538,7 @@ as \"evaluated\" properties if the \"type\" of the address is -## Required Properties[#required] +## Required Properties By default, the properties defined by the `properties` keyword are not required. However, one can provide a list of required properties using @@ -610,7 +610,7 @@ In JSON a property with value `null` is not equivalent to the property not being -## Property names [#propertyNames] +## Property names @@ -653,7 +653,7 @@ schema given to `propertyNames` is always at least: -## Size[#size] +## Size The number of properties on an object can be restricted using the `minProperties` and `maxProperties` keywords. Each of these must be a diff --git a/pages/understanding-json-schema/reference/schema.md b/pages/understanding-json-schema/reference/schema.md index 17bff8bcd..7bae5dd75 100644 --- a/pages/understanding-json-schema/reference/schema.md +++ b/pages/understanding-json-schema/reference/schema.md @@ -11,7 +11,7 @@ provides ways to describe your own custom dialects. -## $schema[#schema] +## $schema The `$schema` keyword is used to declare which dialect of JSON Schema the schema was written for. The value of the `$schema` keyword is also diff --git a/pages/understanding-json-schema/reference/string.md b/pages/understanding-json-schema/reference/string.md index a91cf75ca..cda388079 100644 --- a/pages/understanding-json-schema/reference/string.md +++ b/pages/understanding-json-schema/reference/string.md @@ -42,7 +42,7 @@ In Swift, "string" is analogous to the ``String`` type. 42 ``` -## Length[#length] +## Length The length of a string can be constrained using the `minLength` and `maxLength` [keywords](../../learn/glossary#keyword). For both keywords, the value must be a @@ -73,7 +73,7 @@ non-negative number. "ABCD" ``` -## Regular Expressions[#regexp] +## Regular Expressions The `pattern` keyword is used to restrict a string to a particular regular expression. The regular expression syntax is the one defined in @@ -116,7 +116,7 @@ with an optional area code: "(800)FLOWERS" ``` -## Format[#format] +## Format The `format` keyword allows for basic semantic identification of certain kinds of string values that are commonly used. For example, because JSON @@ -146,7 +146,7 @@ exchanging the JSON documents also exchange information about the custom format types. A JSON Schema validator will ignore any format type that it does not understand. -### Built-in formats[#built-in-formats] +### Built-in formats The following is the list of formats specified in the JSON Schema specification. diff --git a/pages/understanding-json-schema/structuring.md b/pages/understanding-json-schema/structuring.md index e5624a20b..dc5f10621 100644 --- a/pages/understanding-json-schema/structuring.md +++ b/pages/understanding-json-schema/structuring.md @@ -5,15 +5,6 @@ section: docs -* [Schema Identification](#schema-identification) -* [Base URI](#base-uri) -* [$ref](#dollarref) -* [$id](#id) -* [$defs](#defs) -* [Recursion](#recursion) -* [Extending Recursive Schemas](#extending-recursive-schemas) -* [Bundling](#bundling) - When writing computer programs of even moderate complexity, it\'s commonly accepted that \"structuring\" the program into reusable functions is better than copying-and-pasting duplicate bits of code @@ -88,7 +79,7 @@ very familiar. -### Retrieval URI[#retrieval-uri] +### Retrieval URI The URI used to fetch a schema is known as the \"retrieval URI\". It\'s often possible to pass an anonymous schema to an implementation in which @@ -115,7 +106,7 @@ The base URI for this schema is the same as the retrieval URI, `https://example. -## $id[#id] +## $id You can set the base URI by using the `$id` [keyword](../learn/glossary#keyword) at the root of the schema. The value of `$id` is a URI-reference without a fragment that @@ -192,7 +183,7 @@ The base URI of the following schema will always be -### JSON Pointer[#json-pointer] +### JSON Pointer In addition to identifying a schema document, you can also identify subschemas. The most common way to do that is to use a [JSON @@ -225,7 +216,7 @@ identifies the highlighted subschema in the following schema. -### \$anchor[#anchor] +### \$anchor A less common way to identify a subschema is to create a named anchor in the schema using the `$anchor` keyword and using that name in the URI @@ -348,7 +339,7 @@ therefore can\'t be used to retrieve the address schema. -## \$defs[#defs] +## \$defs Sometimes we have small subschemas that are only intended for use in the current schema and it doesn\'t make sense to define them as separate @@ -463,7 +454,7 @@ Documentation Coming Soon -## Bundling[#bundling] +## Bundling Working with multiple schema documents is convenient for development, but it\'s often more convenient for distribution to bundle all of your From 7f7ea3b612aebfc75ae216fed85af2990a742de1 Mon Sep 17 00:00:00 2001 From: techmannih Date: Wed, 20 Nov 2024 18:54:17 +0530 Subject: [PATCH 2/2] fix: Implement a TOC component for draft --- pages/[slug].page.tsx | 4 +-- pages/draft-05/index.page.tsx | 23 ++++++++++++----- pages/draft-06/[slug].page.tsx | 12 ++++++++- pages/draft-06/index.page.tsx | 12 ++++++++- pages/draft-07/[slug].page.tsx | 12 ++++++++- pages/draft-07/index.page.tsx | 12 ++++++++- pages/draft/2019-09/index.page.tsx | 12 ++++++++- pages/draft/2020-12/[slug].page.tsx | 13 +++++++++- pages/draft/2020-12/index.page.tsx | 12 ++++++++- .../understanding-json-schema/index.page.tsx | 25 ++++++++++++++++--- .../reference/combining.md | 12 ++++----- 11 files changed, 125 insertions(+), 24 deletions(-) diff --git a/pages/[slug].page.tsx b/pages/[slug].page.tsx index 05e750c88..114e7d2f3 100644 --- a/pages/[slug].page.tsx +++ b/pages/[slug].page.tsx @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; -import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; // Import TOC component +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages'); @@ -42,7 +42,7 @@ export default function StaticMarkdownPage({
On this page
- + diff --git a/pages/draft-05/index.page.tsx b/pages/draft-05/index.page.tsx index 1d619e0b4..1e518e2f8 100644 --- a/pages/draft-05/index.page.tsx +++ b/pages/draft-05/index.page.tsx @@ -7,7 +7,7 @@ import { SectionContext } from '~/context'; import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-05/index.md', 'utf-8'); const main = fs.readFileSync('pages/draft-05/release-notes.md', 'utf-8'); @@ -35,11 +35,22 @@ export default function ImplementationsPages({ }) { return ( - {frontmatter.title} - - - - +
+
+ {frontmatter.title} + + + + +
+
+
+
On this page
+ + +
+
+
); } diff --git a/pages/draft-06/[slug].page.tsx b/pages/draft-06/[slug].page.tsx index fc447db63..15b0aa0ee 100644 --- a/pages/draft-06/[slug].page.tsx +++ b/pages/draft-06/[slug].page.tsx @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft-06'); } @@ -27,12 +27,22 @@ export default function StaticMarkdownPage({ return ( +
+
{newTitle} {frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/draft-06/index.page.tsx b/pages/draft-06/index.page.tsx index 12127285b..bfe15a422 100644 --- a/pages/draft-06/index.page.tsx +++ b/pages/draft-06/index.page.tsx @@ -7,7 +7,7 @@ import { SectionContext } from '~/context'; import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-06/index.md', 'utf-8'); @@ -33,10 +33,20 @@ export default function ImplementationsPages({ }) { return ( +
+
{frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/draft-07/[slug].page.tsx b/pages/draft-07/[slug].page.tsx index be10dfdba..d16e88d66 100644 --- a/pages/draft-07/[slug].page.tsx +++ b/pages/draft-07/[slug].page.tsx @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft-07'); } @@ -27,12 +27,22 @@ export default function StaticMarkdownPage({ return ( +
+
{newTitle} {frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/draft-07/index.page.tsx b/pages/draft-07/index.page.tsx index 91d52a981..f3a66f234 100644 --- a/pages/draft-07/index.page.tsx +++ b/pages/draft-07/index.page.tsx @@ -7,7 +7,7 @@ import { SectionContext } from '~/context'; import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; - + import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft-07/index.md', 'utf-8'); @@ -33,10 +33,20 @@ export default function ImplementationsPages({ }) { return ( +
+
{frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/draft/2019-09/index.page.tsx b/pages/draft/2019-09/index.page.tsx index 14fb022f2..9020842a1 100644 --- a/pages/draft/2019-09/index.page.tsx +++ b/pages/draft/2019-09/index.page.tsx @@ -7,7 +7,7 @@ import { SectionContext } from '~/context'; import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft/2019-09/index.md', 'utf-8'); const { content: indexContent, data: indexData } = matter(index); @@ -32,10 +32,20 @@ export default function ImplementationsPages({ }) { return ( +
+
{frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/draft/2020-12/[slug].page.tsx b/pages/draft/2020-12/[slug].page.tsx index 52734da09..b111bfb76 100644 --- a/pages/draft/2020-12/[slug].page.tsx +++ b/pages/draft/2020-12/[slug].page.tsx @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/draft/2020-12'); } @@ -27,13 +27,24 @@ export default function StaticMarkdownPage({ return ( +
+
{newTitle} {frontmatter.title} +
+
+
+
On this page
+ +
+
+
+ ); } StaticMarkdownPage.getLayout = getLayout; diff --git a/pages/draft/2020-12/index.page.tsx b/pages/draft/2020-12/index.page.tsx index 4446b9c1b..c23acaf65 100644 --- a/pages/draft/2020-12/index.page.tsx +++ b/pages/draft/2020-12/index.page.tsx @@ -7,7 +7,7 @@ import { SectionContext } from '~/context'; import DocTable from '~/components/DocTable'; import { Headline1 } from '~/components/Headlines'; import { DocsHelp } from '~/components/DocsHelp'; - +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; export async function getStaticProps() { const index = fs.readFileSync('pages/draft/2020-12/index.md', 'utf-8'); const { content: indexContent, data: indexData } = matter(index); @@ -32,10 +32,20 @@ export default function ImplementationsPages({ }) { return ( +
+
{frontmatter.title} +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/understanding-json-schema/index.page.tsx b/pages/understanding-json-schema/index.page.tsx index e8f6fa8e6..46a13f761 100644 --- a/pages/understanding-json-schema/index.page.tsx +++ b/pages/understanding-json-schema/index.page.tsx @@ -5,6 +5,14 @@ import matter from 'gray-matter'; import StyledMarkdown from '~/components/StyledMarkdown'; import { DocsHelp } from '~/components/DocsHelp'; import { SectionContext } from '~/context'; +import { TableOfContentMarkdown } from '~/components/StyledMarkdown'; + +// Function to remove all HTML tags +const stripHtmlTags = (markdown: string) => { + // Regular expression to remove all HTML tags + const htmlTagRegex = /<\/?[^>]+(>|$)/g; + return markdown.replace(htmlTagRegex, ''); +}; export async function getStaticProps() { const block1 = fs.readFileSync( @@ -22,10 +30,21 @@ export async function getStaticProps() { export default function ContentExample({ blocks }: { blocks: any[] }) { const markdownFile = '_indexPage'; + const sanitizedContent = stripHtmlTags(blocks[0]); return ( - - - + +
+
+ + +
+
+
+
On this page
+ +
+
+
); } diff --git a/pages/understanding-json-schema/reference/combining.md b/pages/understanding-json-schema/reference/combining.md index e6777dcb7..9f213b7ac 100644 --- a/pages/understanding-json-schema/reference/combining.md +++ b/pages/understanding-json-schema/reference/combining.md @@ -33,7 +33,7 @@ In addition, there is: -## allOf[#allOf] +## allOf To validate against `allOf`, the given data must be valid against all of the given subschemas. @@ -64,7 +64,7 @@ information. -## anyOf[#anyOf] +## anyOf To validate against `anyOf`, the given data must be valid against any (one or more) of the given subschemas. @@ -98,7 +98,7 @@ To validate against `anyOf`, the given data must be valid against any -## oneOf [#oneOf] +## oneOf To validate against `oneOf`, the given data must be valid against exactly one of the given subschemas. @@ -166,9 +166,9 @@ a string: -## Properties of Schema Composition[#composition] +## Properties of Schema Composition -### Illogical Schemas [#illogicalschemas] +### Illogical Schemas Note that it\'s quite easy to create schemas that are logical impossibilities with these keywords. The following example creates a @@ -193,7 +193,7 @@ both a string and a number at the same time): -1 ``` -### Factoring Schemas [#factoringschemas] +### Factoring Schemas Note that it\'s possible to \"factor\" out the common parts of the subschemas. The following two schemas are equivalent.