chalknotes 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -2
- package/src/index.js +4 -1
- package/src/lib/nextHelpers.js +36 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
const { getAllPosts } = require('./lib/getAllPosts');
|
2
2
|
const { getPostBySlug } = require('./lib/getPostBySlug');
|
3
|
+
const { getStaticPropsForPost, getStaticPathsForPosts } = require('./lib/nextHelpers');
|
3
4
|
|
4
5
|
module.exports = {
|
5
6
|
getAllPosts,
|
6
|
-
getPostBySlug
|
7
|
+
getPostBySlug,
|
8
|
+
getStaticPropsForPost,
|
9
|
+
getStaticPathsForPosts
|
7
10
|
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
const { getAllPosts } = require('./getAllPosts');
|
2
|
+
const { getPostBySlug } = require('./getPostBySlug');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Provides static props for a post page using slug
|
6
|
+
*/
|
7
|
+
const getStaticPropsForPost = async ({ params }) => {
|
8
|
+
const post = await getPostBySlug(params.slug);
|
9
|
+
|
10
|
+
return {
|
11
|
+
props: {
|
12
|
+
post
|
13
|
+
}
|
14
|
+
};
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Provides static paths for all blog posts
|
19
|
+
*/
|
20
|
+
const getStaticPathsForPosts = async () => {
|
21
|
+
const posts = await getAllPosts();
|
22
|
+
|
23
|
+
const paths = posts.map((post) => ({
|
24
|
+
params: { slug: post.slug }
|
25
|
+
}));
|
26
|
+
|
27
|
+
return {
|
28
|
+
paths,
|
29
|
+
fallback: false,
|
30
|
+
};
|
31
|
+
};
|
32
|
+
|
33
|
+
module.exports = {
|
34
|
+
getStaticPropsForPost,
|
35
|
+
getStaticPathsForPosts
|
36
|
+
};
|