Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 🎸 docs demo
Do not merge for demo only
  • Loading branch information
benhalverson committed Jul 20, 2021
commit dc7d3cf5618ed978590621229eac77462f35041c
6 changes: 2 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ module.exports = {
{
resolve: 'gatsby-source-git',
options: {
name: 'i18n-repo',
remote: 'https://github.com/nodejs/i18n.git',
branch: 'master',
patterns: 'content/v14.x/en-US/doc'
name: 'markdown-docs',
path: './node_modules/node-i18n/content/v12.x/en-US/doc/api'
},
},
{
Expand Down
35 changes: 35 additions & 0 deletions gatsby-node-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions;

const docsTemplate = require.resolve(`./src/templates/docs.tsx`);

const result = await graphql(`
{
allMarkdownRemark {
edges {
node {
excerpt
fileAbsolutePath
}
}
}
}
`);

// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}

result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
// path: node.frontmatter.slug,
path: 'test',
component: docsTemplate,
context: {
excerpt,
},
});
});
};
2 changes: 1 addition & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const fetch = require('node-fetch');
const createSlug = require('./util-node/createSlug');
const getReleaseStatus = require('./util-node/getReleaseStatus');

require('./gatsby-node-docs');
const BLOG_POST_FILENAME_REGEX = /([0-9]+)-([0-9]+)-([0-9]+)-(.+)\.md$/;

exports.createPages = ({ graphql, actions }) => {
Expand Down
50 changes: 33 additions & 17 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"gatsby-transformer-yaml": "^3.4.0",
"intersection-observer": "^0.12.0",
"node-fetch": "^2.6.1",
"node-i18n": "github:nodejs/i18n",
"prismjs": "^1.23.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
58 changes: 58 additions & 0 deletions src/pages/docs-demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { graphql } from 'gatsby';
import React from 'react';
import dompurify from 'dompurify';
import Layout from '../components/Layout';

const sanitizer = dompurify.sanitize;
const title = 'Download Node.js';
const description = 'Come get me!';

interface Props {
data: {
doc: {
edges: string[] | {};
};
};
}

const DocsLayout = ({ data }: Props): React.ReactNode => (
<Layout title={title} description={description} style={{width: '100%'}}>
<main>
{console.log(data)}
<p
dangerouslySetInnerHTML={{
__html: sanitizer(data.doc.edges[102].node.html),
}}
/>
</main>
</Layout>
);
export default DocsLayout;

export const query = graphql`
{
doc: allMarkdownRemark {
edges {
node {
fileAbsolutePath
frontmatter {
title
}
html
}
}
}
allFile(
filter: {
absolutePath: { eq: "node_modules/node-i18n/content/v12.x/en-US/doc/" }
}
) {
edges {
node {
id
absolutePath
}
}
}
}
`;