Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement logic to parse the toc.toml and render it #1329

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file removed AWSCLIV2.pkg
Binary file not shown.
4 changes: 4 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ ORG_NAME = "mongodb"
REPO_NAME = "docs-landing"
BRANCH_NAME = "master"
PARSER_VERSION = "0.18.9"

# remove when merged
[context.deploy-preview.environment]
GATSBY_USE_UNIFIED_TOC = "true"
181 changes: 178 additions & 3 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 @@ -133,6 +133,7 @@
"html-screen-capture-js": "^1.0.50",
"https-browserify": "^1.0.0",
"immer": "^9.0.6",
"js-toml": "^1.0.1",
"json-schema": "^0.4.0",
"lodash": "^4.6.0",
"minimist": "^1.2.6",
Expand Down
10 changes: 9 additions & 1 deletion plugins/gatsby-source-snooty-prod/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const swc = require('@swc/core');
const { load } = require('js-toml');

Check warning on line 2 in plugins/gatsby-source-snooty-prod/gatsby-node.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'load' is assigned a value but never used

Check warning on line 2 in plugins/gatsby-source-snooty-prod/gatsby-node.js

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'load' is assigned a value but never used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove from here?

const path = require('path');
const fs = require('fs/promises');
const { transformBreadcrumbs } = require('../../src/utils/setup/transform-breadcrumbs.js');
Expand All @@ -21,7 +22,7 @@
const { createProductNodes } = require('../utils/products.js');
const { createDocsetNodes } = require('../utils/docsets.js');
const { createBreadcrumbNodes } = require('../utils/breadcrumbs.js');

const { createTocNodes } = require('../utils/unified-toc.js');
const assets = new Map();
const projectComponents = new Set();

Expand Down Expand Up @@ -127,6 +128,7 @@
);
process.exit(1);
}

const pageIdPrefix = constructPageIdPrefix(siteMetadata);
documents.forEach((doc) => {
const { page_id, ...rest } = doc;
Expand Down Expand Up @@ -195,6 +197,9 @@

await createBreadcrumbNodes({ db, createNode, createNodeId, createContentDigest });

// create TOC nodes
await createTocNodes({ createNode, createNodeId, createContentDigest });

if (process.env['OFFLINE_DOCS'] !== 'true') {
const umbrellaProduct = await db.realmInterface.getMetadata(
{
Expand Down Expand Up @@ -420,5 +425,8 @@
propertyUrl: String
}

type TOC implements Node @dontInfer {
tocTree: JSON!
}
`);
};
27 changes: 27 additions & 0 deletions plugins/utils/unified-toc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { load } = require('js-toml');
const fs = require('fs/promises');

const createTocNodes = async ({ createNode, createNodeId, createContentDigest }) => {
// Get all MongoDB products for the sidenav

try {
const tomlContents = (await fs.readFile(`${process.cwd()}/toc.toml`)).toString();
const toc = load(tomlContents);

createNode({
tocTree: toc,
id: createNodeId('toc'),
internal: {
contentDigest: createContentDigest(toc),
type: 'TOC',
},
parent: null,
});
} catch (e) {
console.error('error occurred when reading the toc.toml', e);
}
};

module.exports = {
createTocNodes,
};
Loading
Loading