Skip to content

Instantly share code, notes, and snippets.

@johackim
Last active April 14, 2021 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johackim/d6ad7bb6b6380959db8789143c5c289f to your computer and use it in GitHub Desktop.
Save johackim/d6ad7bb6b6380959db8789143c5c289f to your computer and use it in GitHub Desktop.
Generate mdx node id from file path
const uuid = require("uuid");
const generateNodeId = (filePath) => {
const seedConstant = '638f7a53-c567-4eca-8fc1-b23efb1cfb2b';
const gatsbySourceFilesystemNsHash = uuid.v5('gatsby-source-filesystem', seedConstant);
const gatsbySourceFilesystemNodeId = uuid.v5(filePath, gatsbySourceFilesystemNsHash);
const gatsbyPluginMdxNodeId = `${gatsbySourceFilesystemNodeId} >>> Mdx`;
const gatsbyPluginMdxNsHash = uuid.v5('gatsby-plugin-mdx', seedConstant);
return uuid.v5(gatsbyPluginMdxNodeId, gatsbyPluginMdxNsHash);
};
const filePath = '/home/USER/dev/gatsby-project/content/index.md';
const nodeId = generateNodeId(filePath);
console.log(nodeId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment