Introducing Multi-part Posts with Nested Routing
- 文章發表於
Nested Routes
The blog template supports posts in nested sub-folders. This helps in organisation and can be used to group posts of similar content e.g. a multi-part series. This post is itself an example of a nested route! It's located in the /data/blog/nested-route
folder.
How
Simplify create multiple folders inside the main /data/blog
folder and add your .md
/.mdx
files to them. You can even create something like /data/blog/nested-route/deeply-nested-route/my-post.md
We use Next.js catch all routes to handle the routing and path creations.
How to add table of contents
import { TableOfContents } from '@/components/table-of-content/TableOfContent';<TableOfContents items={toc} />
Use Cases
Here are some reasons to use nested routes
- More logical content organisation (blogs will still be displayed based on the created date)
- Multi-part posts
- Different sub-routes for each author
- Internationalization (though it would be recommended to use Next.js built-in i8n routing)
Note
- The previous/next post links at bottom of the template are currently sorted by date. One could explore modifying the template to refer the reader to the previous/next post in the series, rather than by date.
Mock Header
random word: lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos. lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.
lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.
Inline Highlighting
Sample of inline highlighting sum = parseInt(num1) + parseInt(num2)
Code Blocks
Some Javascript code
var num1, num2, sum;num1 = prompt('Enter first number');num2 = prompt('Enter second number');sum = parseInt(num1) + parseInt(num2); // "+" means "add"alert('Sum = ' + sum); // "+" means combine into a string
Some Python code 🐍
def fib():a, b = 0, 1while True: # First iteration:yield a # yield 0 to start with and thena, b = b, a + b # a will now be 1, and b will also be 1, (0 + 1)for index, fibonacci_number in zip(range(10), fib()):print('{i:3}: {f:3}'.format(i=index, f=fibonacci_number))