Skip to content

Fix frontmatter issues#16

Merged
bwplotka merged 3 commits intobwplotka:masterfrom
saswatamcode:frontmatter-fix
Mar 9, 2021
Merged

Fix frontmatter issues#16
bwplotka merged 3 commits intobwplotka:masterfrom
saswatamcode:frontmatter-fix

Conversation

@saswatamcode
Copy link
Copy Markdown
Collaborator

@saswatamcode saswatamcode commented Mar 6, 2021

This PR fixes the frontmatter issue, where frontmatter in md being formatted led to maps showing up. Now, mdformatter.go correctly processes nested fields. Fixes issue #13

---
title: 'Build a gRPC microservice in Go'
excerpt: "If you've dealt with microservices before, you've probably heard about gRPC. In this blog, we'll be exploring the awesome world of gRPC and write our very own microservice with it. We'll also delve into why gRPC might be better than our traditional REST architectures as well the caveats associated with it."
coverImage: '/assets/blog/build-a-grpc-microservice/cover.jpg'
date: '2020-12-06T05:35:07.322Z'
author:
  name: Saswata Mukherjee
  picture: '/assets/blog/authors/saswatamcode.jpeg'
ogImage:
  url: '/assets/blog/build-a-grpc-microservice/cover.jpg'
---

The above frontmatter generated before fix.

---
title: Build a gRPC microservice in Go
ogImage: map[url:/assets/blog/build-a-grpc-microservice/cover.jpg]
excerpt: If you've dealt with microservices before, you've probably heard about gRPC. In this blog, we'll be exploring the awesome world of gRPC and write our very own microservice with it. We'll also delve into why gRPC might be better than our traditional REST architectures as well the caveats associated with it.
date: 2020-12-06T05:35:07.322Z
coverImage: /assets/blog/build-a-grpc-microservice/cover.jpg
author: map[name:Saswata Mukherjee picture:/assets/blog/authors/saswatamcode.jpeg]
---

The above frontmatter generated after fix.

---
title: Build a gRPC microservice in Go
ogImage:
  url: /assets/blog/build-a-grpc-microservice/cover.jpg
excerpt: If you've dealt with microservices before, you've probably heard about gRPC. In this blog, we'll be exploring the awesome world of gRPC and write our very own microservice with it. We'll also delve into why gRPC might be better than our traditional REST architectures as well the caveats associated with it.
date: 2020-12-06T05:35:07.322Z
coverImage: /assets/blog/build-a-grpc-microservice/cover.jpg
author:
  name: Saswata Mukherjee
  picture: /assets/blog/authors/saswatamcode.jpeg
---

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this issue 🤗

Good work, some early suggestions 💪🏽

for _, k := range keys {
_, _ = fmt.Fprintf(b, "%v: %v\n", k, frontMatter[k])
// check if frontMatter[k] is a map
frontMatterStr := fmt.Sprintf("%s", frontMatter[k])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is nice tricky, but wonder if we could add some type safety (: Would _, isMap := frontMatter[k].(map[string]interface{}) work? 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will check it out!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks like it worked! Do we need frontMatterStr then? 🤗

@bwplotka
Copy link
Copy Markdown
Owner

bwplotka commented Mar 6, 2021

image

It happens usually when you put value to variable and never used later (e.g you replace it with another value later on)

@saswatamcode saswatamcode requested a review from bwplotka March 6, 2021 10:43
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode
Copy link
Copy Markdown
Collaborator Author

Linting issues have been fixed @bwplotka.

Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Amazing, almost perfect (:

for _, k := range keys {
_, _ = fmt.Fprintf(b, "%v: %v\n", k, frontMatter[k])
// check if frontMatter[k] is a map
frontMatterStr := fmt.Sprintf("%s", frontMatter[k])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks like it worked! Do we need frontMatterStr then? 🤗

_, _ = fmt.Fprintf(b, "%v: %v\n", k, frontMatter[k])
// Check if frontMatter[k] is a map.
frontMatterStr := fmt.Sprintf("%s", frontMatter[k])
_, isMap := frontMatter[k].(map[string]interface{})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Actually we can do better. Since you are casting to map we could use this map directly, no need to use frontMatterStr, no? (:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh yes. Will make the changes!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Used the casted map. Code looks better now!

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode saswatamcode requested a review from bwplotka March 9, 2021 13:28
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Amazing, thank you!

b := bytes.NewBuffer([]byte("---"))
for _, k := range keys {
_, _ = fmt.Fprintf(b, "%v: %v\n", k, frontMatter[k])
// Check if frontMatter[k] is a map.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

For the next time, this comment might be not needed - the code is now nicely self-explanatory (:

@bwplotka bwplotka merged commit 16d9ba0 into bwplotka:master Mar 9, 2021
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