Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
feat(component): started making docs component
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Aug 29, 2022
1 parent 4fc50bd commit 47ca3df
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
14 changes: 9 additions & 5 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ exports.sourceNodes = async ({
createContentDigest,
reporter: { activityTimer },
cache,
store,
}) => {
let activity = activityTimer('Fetching Node release data');

Expand Down Expand Up @@ -265,10 +264,15 @@ exports.sourceNodes = async ({
const currentActiveReleasesVersions =
getCurrentActiveReleases(nodeReleasesData);

const allApiFilesPerVersion = await getApiDocsData(
currentActiveReleasesVersions,
{ createNode, createNodeId, cache, store }
);
// For now we're only going to parse the latest Node.js docs
// As the v14 and v16 docs have some Markdown Errors
const [latestNodeRelease] = currentActiveReleasesVersions.reverse();

await getApiDocsData([latestNodeRelease], {
createNode,
createNodeId,
cache,
});

activity.end();

Expand Down
8 changes: 7 additions & 1 deletion src/components/Article/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TableOfContents from '../TableOfContents';
import BlogAuthorsList from '../BlogAuthorsList';
import Codebox from '../Codebox';
import InlineCode from '../Codebox/InlineCode';
import DocsApiComponent from '../DocsApiComponent';
import styles from './index.module.scss';

interface Props {
Expand All @@ -30,7 +31,12 @@ interface Props {
children?: React.ReactNode;
}

const mdxComponents = { pre: Codebox, inlineCode: InlineCode, a: MdxLink };
const mdxComponents = {
pre: Codebox,
inlineCode: InlineCode,
a: MdxLink,
DocsApiComponent,
};

const renderBlogAuthors = (date?: string, authors?: BlogPostAuthor[]) => (
<BlogAuthorsList date={date} authors={authors} />
Expand Down
15 changes: 15 additions & 0 deletions src/components/DocsApiComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

import { DocsApiData } from '../../types';

interface Props {
data: DocsApiData;
}

const DocsApiComponent = (props: Props) => {
console.warn(props.data);

return <></>;
};

export default DocsApiComponent;
15 changes: 15 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import type { GatsbyBrowser, GatsbySSR } from 'gatsby';

export interface DocsApiChange {
version: string | string[];
'pr-url': string;
description: string;
}

export interface DocsApiData {
introduced_in?: string;
added?: string | string[];
type?: string;
name?: string;
source_link?: string;
changes?: DocsApiChange[];
}

export interface GenericPageContext {
intlMessages: Record<string, string>;
locale: string;
Expand Down
5 changes: 2 additions & 3 deletions util-node/getApiDocsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function getApiDocsData(activeReleasesVersions, gatsbyApis) {
// And thgen `gatsby-node` will execute them all
const apiDocsFilesPerVersion = await Promise.all(
apiDocsReleases.map(async (apiDocsFiles, index) => {
const markdownFiles = [...apiDocsFiles].filter(
const markdownFiles = apiDocsFiles.filter(
file => file.name.endsWith('.md') && !file.name.startsWith('index')
);

Expand All @@ -49,9 +49,8 @@ async function getApiDocsData(activeReleasesVersions, gatsbyApis) {

const finalContent = `${frontmatterYaml}${mdxWithComponents}`;

createFileNodeFromBuffer({
return createFileNodeFromBuffer({
buffer: Buffer.from(finalContent),
store: gatsbyApis.store,
cache: gatsbyApis.cache,
createNode: gatsbyApis.createNode,
name: `internalApiDoc-${releaseVersion}-${getFileName(file)}`,
Expand Down

0 comments on commit 47ca3df

Please sign in to comment.