forked from timlrx/tailwind-nextjs-starter-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* blog subroute support * docs: update readme and blog Co-authored-by: mrhut10 <[email protected]>
- Loading branch information
Showing
14 changed files
with
99 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ public/sitemap.xml | |
# production | ||
/build | ||
*.xml | ||
# rss feed | ||
/public/index.xml | ||
|
||
# misc | ||
.DS_Store | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
data/blog/nested-route/introducing-multi-part-posts-with-nested-routing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: Introducing Multi-part Posts with Nested Routing | ||
date: '2021-05-02' | ||
tags: ['multi-author', 'next-js', 'feature'] | ||
draft: false | ||
summary: 'The blog template supports posts in nested sub-folders. This can be used to group posts of similar content e.g. a multi-part course. This post is itself an example of a nested route!' | ||
--- | ||
|
||
# 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. | ||
|
||
## Use Cases | ||
|
||
Here's 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](https://nextjs.org/docs/advanced-features/i18n-routing)) | ||
|
||
## Note | ||
|
||
- The previous/next post links at bottom of the template is 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x) | ||
|
||
const flatternArray = (input) => | ||
input.reduce((acc, item) => [...acc, ...(Array.isArray(item) ? item : [item])], []) | ||
|
||
const map = (fn) => (input) => input.map(fn) | ||
|
||
const walkDir = (fullPath) => { | ||
return fs.statSync(fullPath).isFile() ? fullPath : getAllFilesRecursively(fullPath) | ||
} | ||
|
||
const pathJoinPrefix = (prefix) => (extraPath) => path.join(prefix, extraPath) | ||
|
||
const getAllFilesRecursively = (folder) => | ||
pipe(fs.readdirSync, map(pipe(pathJoinPrefix(folder), walkDir)), flatternArray)(folder) | ||
|
||
export default getAllFilesRecursively |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export const kebabCase = (str) => | ||
const kebabCase = (str) => | ||
str && | ||
str | ||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) | ||
.map((x) => x.toLowerCase()) | ||
.join('-') | ||
|
||
export default kebabCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.