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

Fix frontmatter issues #16

Merged
merged 3 commits into from
Mar 9, 2021
Merged

Conversation

saswatamcode
Copy link
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 <[email protected]>
Copy link
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 💪🏽

pkg/mdformatter/mdformatter.go Outdated Show resolved Hide resolved
pkg/mdformatter/mdformatter.go Outdated Show resolved Hide resolved
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
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
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
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
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 <[email protected]>
@saswatamcode
Copy link
Collaborator Author

Linting issues have been fixed @bwplotka.

Copy link
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
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
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
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
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 <[email protected]>
@saswatamcode saswatamcode requested a review from bwplotka March 9, 2021 13:28
Copy link
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!

for _, k := range keys {
_, _ = fmt.Fprintf(b, "%v: %v\n", k, frontMatter[k])
// Check if frontMatter[k] is a map.
Copy link
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