Skip to content

Commit

Permalink
Adding dynamic table
Browse files Browse the repository at this point in the history
  • Loading branch information
wking-io committed Aug 7, 2024
1 parent 2338e1b commit 533bca4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
45 changes: 45 additions & 0 deletions app/components/docs/Table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { ComponentPropsWithoutRef } from 'react'

export default function Table({
columns,
rows,
footnotes,
...props
}: ComponentPropsWithoutRef<'table'> & {
columns: string[]
rows: string[][]
footnotes: string[]
}) {
return (
<>
<table {...props}>
<thead>
<tr>
{columns.map((column, i) => (
<th key={i}>{column}</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row, i) => (
<tr key={i}>
{row.map((cell, j) => (
<td key={j}>{cell}</td>
))}
</tr>
))}
</tbody>
</table>
{footnotes.length > 0 && (
<ol className="mt-2 list-none !pl-0 text-sm">
{footnotes.map((footnote, i) => (
<li key={i} className="flex gap-1">
<sup>{i + 1}</sup>
<span className="italic">{footnote}</span>
</li>
))}
</ol>
)}
</>
)
}
10 changes: 6 additions & 4 deletions app/components/layout/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import Ref from '~/components/docs/Ref.tsx'
import { RoleVar } from '~/components/docs/RoleVar.tsx'
import { ChildHeading, TableLink } from '~/components/docs/Spec.tsx'
import Table from '~/components/docs/Table.tsx'
import Tag from '~/components/docs/Tag.tsx'
import ErrorPage from '~/components/layout/ErrorPage.tsx'
import TableOfContents from '~/components/layout/TableOfContents.tsx'
Expand All @@ -42,7 +43,7 @@ import { CACHE_CONTROL } from '~/utils/http.server.ts'
import { removeEndSlashes } from '~/utils/removeEndSlashes.ts'

export async function publicLoader({ params }: LoaderFunctionArgs) {
let { product, ref, '*': splat } = params
const { product, ref, '*': splat } = params
invariant(product, 'expected `params.product`')
invariant(ref, 'expected `params.ref`')

Expand Down Expand Up @@ -83,7 +84,7 @@ export async function publicLoader({ params }: LoaderFunctionArgs) {
}

export async function privateLoader({ params }: LoaderFunctionArgs) {
let { product, ref, '*': splat } = params
const { product, ref, '*': splat } = params
invariant(product, 'expected `params.product`')
invariant(ref, 'expected `params.ref`')

Expand Down Expand Up @@ -125,8 +126,9 @@ export async function privateLoader({ params }: LoaderFunctionArgs) {
}

export const headers: HeadersFunction = ({ loaderHeaders }) => {
const cacheControl = loaderHeaders.get('Cache-Control') ?? CACHE_CONTROL.doc
return {
'Cache-Control': loaderHeaders.get('Cache-Control')!,
'Cache-Control': cacheControl,
'Vary': 'Cookie',
}
}
Expand Down Expand Up @@ -223,6 +225,7 @@ export function Content({
TableLink,
Image,
CopyButton,
Table,
Tag,
Ref,
MediaRow,
Expand Down Expand Up @@ -279,7 +282,6 @@ export function Content({

export function ErrorBoundary() {
const error = useRouteError()
console.log(error)
let status = 500
let message = 'Unknown error'

Expand Down
4 changes: 3 additions & 1 deletion app/lib/docs/mdx/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bundleMDX } from 'mdx-bundler'
import path from 'path'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeSlug from 'rehype-slug'
import remarkGfm from 'remark-gfm'
Expand All @@ -15,9 +16,10 @@ import rehypeWrapTable from './tables.server.ts'

export async function parseMdx(mdx: string) {
// Pull all h2 & h3 headings
let headings: Heading[] = []
const headings: Heading[] = []
const { frontmatter, code } = await bundleMDX({
source: mdx,
cwd: path.join(process.cwd(), 'documentation'),
mdxOptions(options) {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 533bca4

Please sign in to comment.