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

[Question] How to rewrite internal url to pretty url? #20

Open
bytrangle opened this issue Jul 14, 2022 · 1 comment
Open

[Question] How to rewrite internal url to pretty url? #20

bytrangle opened this issue Jul 14, 2022 · 1 comment

Comments

@bytrangle
Copy link

bytrangle commented Jul 14, 2022

In a Notion page, if you link to another page also in Notion, the linked page will be rendered as:

<a href="/1a2b3c4d">...</a>

where 1a2b3c4d is the id of the linked Notion page.

If you use pretty URLs, then how to you map the link above to the pretty URL?

I haven't tested out this idea, but it seems I'll need to:

  • In onCreateNode, create new slug field for each node.
  • In onCreatePage, query the markdownString value of the page.
  • Search for any instance of relative URL, then query the Notion node with this id, then get the slug value of that node.
  • Create a new string based on markdownString, replacing the original relative URL with the new one that includes pretty url.
  • Pass the new string as context to createPage.
  • This `context prop can then be access in the template component.

Can anyone offer any guidance?

@orlowdev
Copy link
Owner

I'm not sure if I understand this correctly. If you want to map URLs to other URLs, you'll probably need to store the mappings somewhere and then create a local plugin that will use those mappings. But why don't you just create a Slug field in Notion to refer to every page? You could collect edges related to current page and use their Slug value when you compose a link.

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

2 participants