website/src/templates/default.jsx

126 lines
3.6 KiB
React
Raw Normal View History

2022-08-26 13:46:21 +00:00
import React from "react"
import { Link, graphql } from "gatsby"
import Layout from "../components/layout"
2022-12-01 09:04:26 +00:00
import SEO from "../components/seo"
2022-08-28 09:59:41 +00:00
import DocsCard from "../components/cards/docs"
2022-09-01 10:19:20 +00:00
import { node2slug } from "../utils";
2022-08-26 13:46:21 +00:00
import rehypeReact from "rehype-react"
function DivMixin(props) {
if (props?.class != null && props.class.includes("gatsby-highlight")) {
props.class = props.class + " mockup-code mb-5"
}
return <div {...props} />
}
const componentMap = {
div: DivMixin,
a: (props) => {
return <Link className="link" to={props?.href} {...props} />
},
2022-08-26 16:16:07 +00:00
kbd: (props) => {
2022-08-26 17:20:48 +00:00
return <kbd className="kbd bg-base-300" {...props} />
2022-08-26 16:16:07 +00:00
},
2022-08-26 13:46:21 +00:00
ol: (props) => {
return <ul className="steps steps-vertical" {...props} />
},
li: (props) => {
return <li className="step" {...props} />
},
2022-08-27 09:01:03 +00:00
table: (props) => {
2022-08-28 09:59:41 +00:00
return <table className="table w-full" {...props} />
2022-08-27 09:01:03 +00:00
},
tr: (props) => {
2022-08-28 09:59:41 +00:00
return <tr className="hover" {...props} />
2022-08-27 09:01:03 +00:00
},
2022-08-26 13:46:21 +00:00
hr: (props) => {
2022-08-27 09:01:03 +00:00
return <div className="divider" {...props} />
2022-08-26 13:46:21 +00:00
}
}
2022-08-28 09:59:41 +00:00
export default function PageTemplate({ data: { markdownRemark, allMarkdownRemark } }) {
2022-08-26 13:46:21 +00:00
const renderAst = new rehypeReact({
createElement: React.createElement,
components: componentMap,
Fragment: ({ children }) => {
return <div className="prose contents">{children}</div>
}
}).Compiler
2022-08-28 09:59:41 +00:00
const filtered = allMarkdownRemark.nodes.filter(it => it.frontmatter.parent === markdownRemark.frontmatter.title).map(it => {
return <DocsCard md={it} key={it} width="w-full" />
})
2022-08-26 13:46:21 +00:00
return (
<Layout>
<div className="flex items-center w-full flex-col">
2022-09-01 10:17:26 +00:00
<div className="text-sm breadcrumbs md-5">
2022-08-26 13:46:21 +00:00
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/docs">Documentation</Link></li>
<li>{markdownRemark.frontmatter.title}</li>
</ul>
</div>
<div className="w-full mx-10 md:w-2/3 card bg-base-200 shadow-xl">
<div className="card-body">
2022-09-01 10:17:26 +00:00
<h1 className="card-title text-xl">{markdownRemark.frontmatter.title}</h1>
2022-08-26 13:46:21 +00:00
{renderAst(markdownRemark.htmlAst)}
</div>
</div>
2022-09-01 10:46:36 +00:00
<div className="alert shadow-lg w-full mx-auto md:w-2/3 mt-5">
<div>
<div>
<h3 className="font-bold">Edit on GitHub</h3>
<div className="text-xs">If you see a mistake here, you can open a pull request</div>
</div>
</div>
<div className="flex-none">
<a
className="btn btn-primary btn-sm"
2022-10-30 11:01:07 +00:00
href={`https://github.com/recloudstream/website/blob/master/src/pages${node2slug(markdownRemark)}`}
2022-09-01 10:46:36 +00:00
target="_blank">Edit</a>
</div>
</div>
2022-08-28 09:59:41 +00:00
{filtered.length > 0 && <>
2022-09-01 10:17:26 +00:00
<div className="divider text-xl mt-5">Children</div>
2022-08-28 09:59:41 +00:00
<div className="grid gap-5 w-full px-10 place-items-center auto-rows-max grid-flow-row-dense grid-cols-1 md:grid-cols-2 lg:grid-cols-3">
{filtered}
</div></>}
2022-08-26 13:46:21 +00:00
</div>
</Layout>
)
}
2022-08-28 09:59:41 +00:00
export function Head({ data }) {
2022-12-01 09:04:26 +00:00
return <SEO title={data.markdownRemark.frontmatter.title} description={data.markdownRemark.excerpt} />
2022-08-26 13:46:21 +00:00
}
export const pageQuery = graphql`
query ($id: String!) {
markdownRemark(id: { eq: $id }) {
frontmatter {
title
}
2022-09-01 10:17:26 +00:00
fileAbsolutePath
2022-08-26 15:40:16 +00:00
excerpt
2022-08-26 13:46:21 +00:00
htmlAst
}
2022-08-28 09:59:41 +00:00
allMarkdownRemark(
sort: {fields: frontmatter___order}
filter: {frontmatter: {parent: {ne: null}}}
) {
nodes {
frontmatter {
title
order
parent
}
fileAbsolutePath
excerpt
}
}
2022-08-26 13:46:21 +00:00
}
2022-08-26 16:16:07 +00:00
`