Skip to content

Commit

Permalink
chore: Add slug to the ollypack node fields
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Jun 4, 2021
1 parent 6015378 commit 603e07d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 15 additions & 5 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
allObservabilityPacks {
edges {
node {
name
fields {
slug
}
id
}
}
Expand Down Expand Up @@ -111,10 +113,10 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
});

allObservabilityPacks.edges.forEach(({ node }) => {
const { name, id } = node;

const slug = `/observability-packs/${slugify(name)}/${id}`;
console.log(slug);
const {
fields: { slug },
id,
} = node;

createPage({
path: path.join(slug, '/'),
Expand Down Expand Up @@ -189,6 +191,14 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
value: `/apis/${kebabCase(node.name)}`,
});
}

if (node.internal.type === 'ObservabilityPacks') {
createNodeField({
node,
name: 'slug',
value: `/observability-packs/${slugify(node.name)}/${node.id}`,
});
}
};

exports.onCreateWebpackConfig = ({ actions, plugins }) => {
Expand Down
6 changes: 4 additions & 2 deletions src/pages/observability-packs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import DevSiteSeo from '../components/DevSiteSeo';
import { css } from '@emotion/react';
import PackTile from '../components/PackTile';
import PackList from '../components/PackList';
import slugify from '../utils/slugify';
import { SearchInput, Button, Dropdown } from '@newrelic/gatsby-theme-newrelic';

const ObservabilityPacksPage = ({ data, location }) => {
Expand Down Expand Up @@ -132,7 +131,7 @@ const ObservabilityPacksPage = ({ data, location }) => {
featuredImageUrl={
imgSrc || 'https://via.placeholder.com/400x275.png?text=Image'
}
to={`/observability-packs/${slugify(pack.name)}/${pack.id}`}
to={`${pack.fields.slug}`}
/>
);
})}
Expand All @@ -151,6 +150,9 @@ export const pageQuery = graphql`
query {
allObservabilityPacks {
nodes {
fields {
slug
}
id
name
website
Expand Down

0 comments on commit 603e07d

Please sign in to comment.