Table of Contents
My ideal personal site is something in between a journal and wiki. A killer feature of wikis is bi-directional links. These are also known as metioned links or backlinks. If you’re reading a page, you can see all the pages that link to it; a great way to discover related content.
Contentlayer is a library that acts as like an ORM for markdown content. It has become popular in the Next.js ecosystem as a way to manage content for static sites. It’s easy to build on top of since all content is available through a strongly-typed, generated module.
allDocuments array can be iterated over to find all the documents that link to a given page. Here’s a function that returns an array of backlinks for a given slug:
Then, in your page component, you can call this function and render the results. The example below is in Next.js, but the approach can be used broadly.