next-staticblog 0.2.0-beta.1 → 0.2.0-beta.2
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/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/package.json +1 -1
- package/tsconfig.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function getAllPostSlugs(directory?: string): string[];
|
|
2
|
+
export declare function getAllPosts(directory?: string): {
|
|
3
|
+
slug: string;
|
|
4
|
+
metadata: Record<string, unknown>;
|
|
5
|
+
content: string;
|
|
6
|
+
}[];
|
|
7
|
+
export declare function getAllPostParams(directory?: string): {
|
|
8
|
+
slug: string;
|
|
9
|
+
}[];
|
|
10
|
+
export declare function getPostBySlug(slug: string, directory?: string): {
|
|
11
|
+
slug: string;
|
|
12
|
+
metadata: Record<string, unknown>;
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { matter } from "gray-matter-es";
|
|
4
|
+
export function getAllPostSlugs(directory = "posts/") {
|
|
5
|
+
const postsDirectory = path.join(process.cwd(), directory);
|
|
6
|
+
return fs.readdirSync(postsDirectory);
|
|
7
|
+
}
|
|
8
|
+
export function getAllPosts(directory = "posts/") {
|
|
9
|
+
const slugs = getAllPostSlugs(directory);
|
|
10
|
+
return slugs.map((slug) => getPostBySlug(slug, directory));
|
|
11
|
+
}
|
|
12
|
+
export function getAllPostParams(directory = "posts/") {
|
|
13
|
+
const slugs = getAllPostSlugs(directory);
|
|
14
|
+
return slugs.map((slug) => ({ slug: slug.replace(/\.md$/, "") }));
|
|
15
|
+
}
|
|
16
|
+
export function getPostBySlug(slug, directory = "posts/") {
|
|
17
|
+
const realSlug = slug.replace(/\.md$/, "");
|
|
18
|
+
const postsDirectory = path.join(process.cwd(), directory);
|
|
19
|
+
const fullPath = path.join(postsDirectory, `${realSlug}.md`);
|
|
20
|
+
const fileContents = fs.readFileSync(fullPath, "utf8");
|
|
21
|
+
const { data, content } = matter(fileContents);
|
|
22
|
+
return { slug: realSlug, metadata: data, content };
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-staticblog",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.2",
|
|
4
4
|
"description": "Quickly configure the markdown component in the Next.js project and create a blog page!",
|
|
5
5
|
"homepage": "https://github.com/yd-tw/next-staticblog",
|
|
6
6
|
"license": "MIT",
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"exclude": ["tests/**", "node_modules"],
|
|
3
2
|
"compilerOptions": {
|
|
4
3
|
"target": "es2017",
|
|
5
4
|
"module": "esnext",
|
|
@@ -10,5 +9,6 @@
|
|
|
10
9
|
"forceConsistentCasingInFileNames": true,
|
|
11
10
|
"strict": true,
|
|
12
11
|
"skipLibCheck": true
|
|
13
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"exclude": ["tests", "node_modules", "dist"],
|
|
14
14
|
}
|