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: handle properties as frontmatter #26

Open
parkuman opened this issue Mar 12, 2022 · 11 comments
Open

feature: handle properties as frontmatter #26

parkuman opened this issue Mar 12, 2022 · 11 comments

Comments

@parkuman
Copy link

parkuman commented Mar 12, 2022

Hey everyone!

I thought it would be an interesting feature to allow notion-to-md to take properties of a page and convert them to YAML-style markdown frontmatter. For example:

A notion page with the following properties:

image

would get converted to the following markdown:

---
title: Second Post
summary: My second blog post, its really good and cool
slug: second-post
author: Parker Rowe
date: 2022-03-11
tags:
 - TypeScript
 - SvelteKit
 - Markdown
---

# My Second Post

Yea baby

...

I've started working on a similar parser for my personal site using Notion as my blog CMS (example WIP code here), but I thought it could be useful to have it baked into notion-to-md.

Feel free to discuss! 🍻

@souvikinator
Copy link
Owner

souvikinator commented Mar 13, 2022

Hey Parker, thanks for the suggestion
Definitely, this feature can be included however I'm not sure if this is within the scope of this package. The package's focus is to convert notion pages to markdown. Here we have to convert properties to YAML and then concatenate it with the markdown of the page. I did go through your code and it seems to work.

I see a lot of CMS-based projects are using this package so I understand how handy this feature will be therefore I don't mind adding it. It has to be a separate method rather than adding it to the existing methods.

I do have a few things in mind related to this so, let me know if you are interested. We can discuss the approach and possible use cases.

@parkuman
Copy link
Author

Hey!

Completely understandable. Implementing it as a different method would be quite useful so the feature could be entirely opt-in if the developer wants to use it.

I think it would be cool to have as a part of the package and I'd be glad to help. Would love to hear some of your ideas on this topic too :)

@souvikinator
Copy link
Owner

Awesome. Let's work on a basic version.
Breaking it down:

  1. A private method that takes page properties/page id and converts it to a simplified object
  2. A public method that uses the private method and converts the object to a YAML string.

if you have any other approaches or questions in mind then feel free to share.

@emoriarty
Copy link
Contributor

emoriarty commented Mar 17, 2022

Hey guys,

I've worked on the same feature for the ruby package. Basically, I've taken the same approach as you mention @parkuman. The Front matter is optional.

Anyway, I'm leaving the comment here so perhaps what has been done in notion_to_md can help you. The front matter is parsed here.

Cheers!

@parkuman
Copy link
Author

parkuman commented Mar 21, 2022

@emoriarty Nice! I really like the conversion to snake case even if its not like that already. Thank you for sharing that.

@souvikinator the two staged approach could definitely work well. Seems like frontmatter is commonly used as JSON, TOML (but more often than not), YAML: https://gohugo.io/content-management/front-matter/ . We could allow the user to choose the outputted language for frontmatter, but for now just YAML would be perfect.

So some other questions I thought of:

  • Do we include the default id, title, created_time, last_edited_time, icon, archived and cover parameters from notion in the frontmatter?

  • for notions Date parameter, it is returned as an object. There's the normal start_date and optional end_date parameter. We would need to make a decision on including all info or not.

  • for Multi-Select (each one is an object that contains text + color information). I'm using the color information on my blog site right now but that is definitely overkill. This is where I handle it https://github.com/parkuman/prowe.ca/blob/main/src/lib/notion.ts#L26 .

  • same goes for the person parameter, it is returned as a list of people and each one is an object that contains profile pic info, name & more

I guess the main question is do we want to include all information from each and convert it to YAML? Or only pick and choose the more useful ones like @emoriarty and I have been doing. If there's no preference then I could get started on one that just includes all the information and go from there :) The Type definitions from the notion package shows them all, i think this is where they are: https://github.com/makenotion/notion-sdk-js/blob/main/src/api-endpoints.ts

@souvikinator
Copy link
Owner

True, we can go with YAML for now and later allow users to pass a parameter mentioning the language.

Do we include the default id, title, created_time, last_edited_time, icon, archived and cover parameters from notion in the front matter?

The requirement varies from person to person so probably we have to make it in a way users can remove unnecessary properties.

Possible flow:

  • propertiesToObject(page_id, notionClient) => returns simplified properties object
  • user can remove unwanted fields from the object as per their requirement
  • propertyObjectToFrontmatter(simplified_object, language) => user can pass modified property object andobjects... convert to frontmatter

or

  • propertiesToFrontmatter(page_id, notionClient, options?)
options={
  language?: "",
  remove?: [ fields_to_remove... ]
}

for fields like icon and cover, we can include only the image URL.

for notions Date parameter, it is returned as an object. There's the normal start_date and optional end_date parameter. We would need to make a decision on including all info or not.

start_date should do the work.

for Multi-Select (each one is an object that contains text + color information). I'm using the color information on my blog site right now but that is definitely overkill.

Great work! however, I'm not sure if the color thing is supported in Hugo and other popular static site generators, so for the time being we can keep the plain_text only.

same goes for the person parameter, it is returned as a list of people and each one is an object that contains profile pic info, name & more

let's just extract the name for now.

Would love to hear your thoughts on this.

@souvikinator
Copy link
Owner

Hello there, I'm closing this issue as it is out of the scope for the package.
The package's focus is to convert notion pages to markdown only.

@augnustin
Copy link

Hey,

@souvikinator I don't really agree with you about this feature not being in the scope of the package. The point here is to facilitate using notion as a CMS using standard formats and clearly markdown with frontmatter is part of it.

I'll go for my own custom implementation and will report it here in case it helps others, maybe we could discuss about making this core later.

@kuzzmi
Copy link

kuzzmi commented Nov 14, 2024

How come the page properties are not a part of a page? 🤷 Your decision, of course.

@souvikinator
Copy link
Owner

Hey @kuzzmi
I understand the requirement and I'm working on v4 so I'll definitely be including this one reopening the issue :)

@souvikinator souvikinator reopened this Nov 14, 2024
@souvikinator
Copy link
Owner

souvikinator commented Dec 11, 2024

Hey guys, I have created first draft for version 4 and wanted some input before starting off with implementation and also targeting this very issue. Please feel free to give your inputs here: #112

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

No branches or pull requests

5 participants