next-staticblog 0.1.2 → 0.1.3
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 +4 -4
- package/dist/index.js +10 -10
- package/index.ts +10 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare function getAllPostSlugs(): string[];
|
|
2
|
-
export declare function getAllPosts(): {
|
|
1
|
+
export declare function getAllPostSlugs(filePath?: string): string[];
|
|
2
|
+
export declare function getAllPosts(filePath?: string): {
|
|
3
3
|
slug: string;
|
|
4
4
|
metadata: {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
};
|
|
7
7
|
content: string;
|
|
8
8
|
}[];
|
|
9
|
-
export declare function getAllPostParams(): {
|
|
9
|
+
export declare function getAllPostParams(filePath?: string): {
|
|
10
10
|
slug: string;
|
|
11
11
|
}[];
|
|
12
|
-
export declare function getPostBySlug(slug: string): {
|
|
12
|
+
export declare function getPostBySlug(filePath: string | undefined, slug: string): {
|
|
13
13
|
slug: string;
|
|
14
14
|
metadata: {
|
|
15
15
|
[key: string]: any;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import matter from "gray-matter";
|
|
4
|
-
const
|
|
5
|
-
export function getAllPostSlugs() {
|
|
6
|
-
return fs.readdirSync(
|
|
4
|
+
const DEFAULT_POSTS_PATH = "posts";
|
|
5
|
+
export function getAllPostSlugs(filePath = DEFAULT_POSTS_PATH) {
|
|
6
|
+
return fs.readdirSync(path.join(process.cwd(), filePath));
|
|
7
7
|
}
|
|
8
|
-
export function getAllPosts() {
|
|
9
|
-
const slugs = getAllPostSlugs();
|
|
10
|
-
return slugs.map((slug) => getPostBySlug(slug));
|
|
8
|
+
export function getAllPosts(filePath = DEFAULT_POSTS_PATH) {
|
|
9
|
+
const slugs = getAllPostSlugs(filePath);
|
|
10
|
+
return slugs.map((slug) => getPostBySlug(filePath, slug));
|
|
11
11
|
}
|
|
12
|
-
export function getAllPostParams() {
|
|
13
|
-
const slugs = getAllPostSlugs();
|
|
12
|
+
export function getAllPostParams(filePath = DEFAULT_POSTS_PATH) {
|
|
13
|
+
const slugs = getAllPostSlugs(filePath);
|
|
14
14
|
return slugs.map((slug) => ({ slug: slug.replace(/\.md$/, "") }));
|
|
15
15
|
}
|
|
16
|
-
export function getPostBySlug(slug) {
|
|
16
|
+
export function getPostBySlug(filePath = DEFAULT_POSTS_PATH, slug) {
|
|
17
17
|
const realSlug = slug.replace(/\.md$/, "");
|
|
18
|
-
const fullPath = path.join(
|
|
18
|
+
const fullPath = path.join(process.cwd(), filePath, `${realSlug}.md`);
|
|
19
19
|
const fileContents = fs.readFileSync(fullPath, "utf8");
|
|
20
20
|
const { data, content } = matter(fileContents);
|
|
21
21
|
return { slug: realSlug, metadata: data, content };
|
package/index.ts
CHANGED
|
@@ -2,25 +2,25 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import matter from "gray-matter";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const DEFAULT_POSTS_PATH = "posts";
|
|
6
6
|
|
|
7
|
-
export function getAllPostSlugs() {
|
|
8
|
-
return fs.readdirSync(
|
|
7
|
+
export function getAllPostSlugs(filePath: string = DEFAULT_POSTS_PATH) {
|
|
8
|
+
return fs.readdirSync(path.join(process.cwd(), filePath));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function getAllPosts() {
|
|
12
|
-
const slugs = getAllPostSlugs();
|
|
13
|
-
return slugs.map((slug) => getPostBySlug(slug));
|
|
11
|
+
export function getAllPosts(filePath: string = DEFAULT_POSTS_PATH) {
|
|
12
|
+
const slugs = getAllPostSlugs(filePath);
|
|
13
|
+
return slugs.map((slug) => getPostBySlug(filePath, slug));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function getAllPostParams(){
|
|
17
|
-
const slugs = getAllPostSlugs();
|
|
16
|
+
export function getAllPostParams(filePath: string = DEFAULT_POSTS_PATH) {
|
|
17
|
+
const slugs = getAllPostSlugs(filePath);
|
|
18
18
|
return slugs.map((slug) => ({ slug: slug.replace(/\.md$/, "") }));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function getPostBySlug(slug: string) {
|
|
21
|
+
export function getPostBySlug(filePath: string = DEFAULT_POSTS_PATH, slug: string) {
|
|
22
22
|
const realSlug = slug.replace(/\.md$/, "");
|
|
23
|
-
const fullPath = path.join(
|
|
23
|
+
const fullPath = path.join(process.cwd(), filePath, `${realSlug}.md`);
|
|
24
24
|
const fileContents = fs.readFileSync(fullPath, "utf8");
|
|
25
25
|
const { data, content } = matter(fileContents);
|
|
26
26
|
|