gatsby-source-notion-api
gatsby-source-notion-api copied to clipboard
[Question] How to rewrite internal url to pretty url?
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 newslugfield for each node. - In
onCreatePage, query themarkdownStringvalue of the page. - Search for any instance of relative URL, then query the Notion node with this id, then get the
slugvalue 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?
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.