Skip to content

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

Open
@bytrangle

Description

@bytrangle

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions