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

feature: define blog slug in frontmatter #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feature: define blog slug in frontmatter #48

wants to merge 2 commits into from

Conversation

jkornblum
Copy link
Contributor

Modify gatsby-node.js so that it reads in frontmatter slug and uses it for blog URL. If frontmatter is not defined or slug is not defined it will default to file path for slug (current behavior).

E.g. on the demo the first blog post is demo.com/blog/2017-04-18--welcoming/ by adding slug to front matter like

---
title: 'Article #2'
tags:
  - test
slug: 2017-04-18/my-article
---

the new url would be demo.com/blog/2017-04-18/my-article

Modify gatsby-node.js that reads in frontmatter slug
and uses it for blog URL. If frontmatter is not defined or
slug is not defined it will default to file path for slug.
Copy link
Owner

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

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

Nice idea! Just a little style modification and I accept this PR 😉

Thanks you 😃

gatsby-node.js Outdated
@@ -36,9 +36,10 @@ exports.onCreateNode = ({node, boundActionCreators, getNode}) => {
let slug;
switch (node.internal.type) {
case `MarkdownRemark`:
const fmSlug = (node.frontmatter && node.frontmatter.slug) ? node.frontmatter.slug : false
Copy link
Owner

Choose a reason for hiding this comment

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

Here you can use get from lodash (https://lodash.com/docs/4.17.5#get), and I prefer long variable name instead of acronyms 😉

const frontmatterSlug = get(node, 'frontmatter.slug');

@fabien0102
Copy link
Owner

@jkornblum carefull you miss a semi-column ^^

gatsby-node.js:39:97
  ✖  39:97  Missing semicolon.

You can run npm run lint:js to be sure (normally it's automaticly done in a git hook with husky) 😉

@jkornblum
Copy link
Contributor Author

Thanks for feedback. I tried the one liner without the checks! I was burned 😄

Anyways I updated and cleaned up code, added unit test, and changed one markdown file use the frontmatter slug.

Let me know if it looks okay.

@fabien0102
Copy link
Owner

fabien0102 commented Feb 15, 2018

It looks good, I just need to check why netlify don't want to deploy ^^

8:29:44 AM: error Generating JavaScript bundles failed
8:29:44 AM: 
8:29:44 AM:   Error: /opt/build/repo/node_modules/@types/react/index.d.ts
8:29:44 AM:   (3508,58): error TS2304: Cannot find name 'HTMLDialogElement'.
8:29:44 AM: 

Strange… I look this after, really thank you for your PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants