queen.raae.codes · a developer’s logbook
1 min read by Cap'n Ola

Ola adds a slug field to his homemade markdown node

Written in 2022, 4 years ago. Tools and advice may have moved on since.

My Sunday Skill Builder Session:

This Sunday, I added a slug field to my homemade markdown node 🐛

What did I do?

I added a slug field to my homemade markdown node with createNodeField from the onCreateNode hook.

Why did I do it?

I need that slug to add support for a basic content section to create Markdown marketing pages with sections for Queen @raae’s usepow.app.

How did I do it?

Short version:

// POW!-website / gatsby - node.js;
async function slugifyMarkdownRemarkNode({ actions, node, getNode }) {
  const { createNodeField } = actions;
  if (node.internal.type === "MarkdownRemark") {
    const slug = createFilePath({ node, getNode });
    createNodeField({
      name: "slug",
      node,
      value: slug,
    });
  }
}

exports.onCreateNode = async (gatsbyUtils) => {
  await Promise.all([slugifyMarkdownRemarkNode(gatsbyUtils)]);
};

Cheat Sheet:

// POW!-site/gatsby-node.js
async function slugifyMarkdownRemarkNode({ actions, node, getNode }) {
  // 🔨💰🍓
  con
  // my md type of node ... internal
  if ( ) {
    // 🐛 = 🔨 + 📁 + 🎢 ({ node, getNode })
  con
    // 🔨💰🍓 ({ 🐛, 💰, 🐛 })
    cre
      na
      no
      va
    })
  }
};

If you can guess what one of the emojis mean, reply to this email 😺👍

Long version: Sunday’s OlaCast on YouTube

 
💪😺👍
Keep your skill-builder-ship afloat this week!
⛵🔧🏴‍☠️

Ola Vea
Cap’n of his own skill-builder-ship

Join the crew!

All the shenanigans from me and my piratical family, straight to your inbox.

Search the log

↑↓ to move · Enter to open · Esc to close All entries →