Skip to content

Commit

Permalink
Prototype for new stdlib hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
vkleen committed Apr 12, 2023
1 parent 6c672af commit b08fe67
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
6 changes: 3 additions & 3 deletions flake.lock

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

56 changes: 40 additions & 16 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
redirectToIntro("/user-manual/");
redirectToIntro("/user-manual");

let redirectToStdlibArray = fromPath => (
let redirectToStdlibStd = fromPath => (
actions.createRedirect({
fromPath,
toPath: `/stdlib/array`,
toPath: `/stdlib/std`,
redirectInBrowser: true,
isPermanent: true,
})
Expand All @@ -73,7 +73,23 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
redirectToStdlibArray("/stdlib");
};

exports.onCreateNode = ({ node, getNode, createNodeId, actions }) => {
const makeStdlibSection = ({ actions, createNodeId, createContentDigest, node, slug, name, content }) => {
newNode = {
id: createNodeId(`${node.id} >>> Nickel Stdlib Doc ${slug}`),
parent: node.id,
slug,
name,
internal: {
contentDigest: createContentDigest(content),
content: JSON.stringify(content),
type: "StdlibSection"
}
};
actions.createNode(newNode);
actions.createParentChildLink({ parent: node, child: newNode })
}

exports.onCreateNode = ({ node, getNode, createNodeId, createContentDigest, actions }) => {
if (node.internal.type === "MarkdownRemark" && getNode(node.parent).sourceInstanceName === "user-manual") {
newNode = {
id: createNodeId(`Nickel User Manual ${node.id}`),
Expand All @@ -89,19 +105,27 @@ exports.onCreateNode = ({ node, getNode, createNodeId, actions }) => {
}

if (node.internal.type === "NickelStdlibDocJson") {
const slug = getNode(node.parent).name;
const toplevelName = getNode(node.parent).name;
docsContent = JSON.parse(getNode(node.parent).internal.content);

newNode = {
id: createNodeId(`Nickel Stdlib Doc ${node.id}`),
parent: node.id,
slug,
internal: {
contentDigest: node.internal.contentDigest,
content: getNode(node.parent).internal.content,
type: "StdlibSection"
}
}
actions.createNode(newNode);
actions.createParentChildLink({ parent: node, child: newNode })
toplevelFields = Object.fromEntries(Object.entries(docsContent).filter(([key, value]) => !value.fields));

makeStdlibSection({
actions, createNodeId, createContentDigest,
node,
slug: toplevelName,
name: toplevelName,
content: toplevelFields,
})

Object.entries(docsContent).filter(([key, value]) => !!value.fields).forEach(([slug, value]) => {
makeStdlibSection({
actions, createNodeId, createContentDigest,
node,
slug: `${toplevelName}-${slug}`,
name: `${toplevelName}.${slug}`,
content: value.fields,
})
});
}
}
5 changes: 3 additions & 2 deletions src/components/stdlib-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function SidebarToc({active, headings}) {
edges {
node {
slug
name
}
}
}
Expand All @@ -53,11 +54,11 @@ export default function SidebarToc({active, headings}) {
</div>

<ul>
{data.allStdlibSection.edges.map(({node: { slug }}) => {
{data.allStdlibSection.edges.map(({node: { slug, name }}) => {
const key = `sec-stdlib-${slug}`;
return (
<li key={key}>
<Link className="link-primary" activeClassName="sidebar-link-active" to={`${data.site.siteMetadata.stdlib.link}/${slug}`}>{slug}</Link>
<Link className="link-primary" activeClassName="sidebar-link-active" to={`${data.site.siteMetadata.stdlib.link}/${slug}`}>{name}</Link>
{
(slug === active) ?
subMenu({
Expand Down
10 changes: 6 additions & 4 deletions src/pages/stdlib/{StdlibSection.slug}.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import ReactMarkdown from 'react-markdown';
const Stdlib = ({data}) => {
const object = JSON.parse(data.stdlibSection.internal.content);
const slug = data.stdlibSection.slug;
const name = data.stdlibSection.name;
const sidebarProps = {
active: slug,
headings: object[slug].fields,
headings: object,
};

const HeaderWithTypes = ({id, name, types, contracts}) => {
Expand Down Expand Up @@ -84,7 +85,6 @@ const Stdlib = ({data}) => {
})
};

console.log(object[`${slug}`].fields);
return (
<Layout>
<div className="container-fluid">
Expand All @@ -95,20 +95,22 @@ const Stdlib = ({data}) => {
</div>
<div className={"col-xl-9 col-lg-8 col-md-7 order-2"}>
<div className={"container content-main-container content documentation-page"}>
<h2>{slug.charAt(0).toUpperCase() + slug.slice(1)}</h2>
<DocEntries prefix={``} fields={object[`${slug}`].fields} />
<h2>{name}</h2>
<DocEntries prefix={``} fields={object} />
</div>
</div>
</div>
</div>
</Layout>
)
// <h2>{name.charAt(0).toUpperCase() + name.slice(1)}</h2>
};

export const pageQuery = graphql`
query($id: String) {
stdlibSection(id: { eq: $id }) {
slug
name
internal { content }
}
}
Expand Down

0 comments on commit b08fe67

Please sign in to comment.