gatsby-source-notion-api icon indicating copy to clipboard operation
gatsby-source-notion-api copied to clipboard

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

Open bytrangle opened this issue 3 years ago • 1 comments

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?

bytrangle avatar Jul 14 '22 17:07 bytrangle

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.

orlowdev avatar Aug 13 '22 16:08 orlowdev