@haroonwaves/blog-kit-core 1.3.1 → 2.0.0
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/README.md +1 -2
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.js +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,8 +20,7 @@ For complete documentation, API reference, and examples, please visit the
|
|
|
20
20
|
|
|
21
21
|
## Quick Links
|
|
22
22
|
|
|
23
|
-
- [
|
|
24
|
-
- [Core Package Usage](https://blog-kit.haroonwaves.com/docs/core-package)
|
|
23
|
+
- [Getting Started](https://blog-kit.haroonwaves.com/docs/getting-started)
|
|
25
24
|
- [API Reference](https://blog-kit.haroonwaves.com/docs/api-reference)
|
|
26
25
|
|
|
27
26
|
## Related Packages
|
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
getAllContentMeta: () => getAllContentMeta,
|
|
34
|
+
getContent: () => getContent
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
|
|
@@ -40,16 +40,16 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
40
40
|
var import_path = __toESM(require("path"), 1);
|
|
41
41
|
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
42
42
|
var import_reading_time = __toESM(require("reading-time"), 1);
|
|
43
|
-
function
|
|
44
|
-
const
|
|
45
|
-
if (!import_fs.default.existsSync(
|
|
46
|
-
console.warn(`
|
|
43
|
+
function getAllContentMeta(config) {
|
|
44
|
+
const contentDirectory = import_path.default.join(config.contentDirectory, config.contentSubdirectory || "blog");
|
|
45
|
+
if (!import_fs.default.existsSync(contentDirectory)) {
|
|
46
|
+
console.warn(`Content directory not found: ${contentDirectory}`);
|
|
47
47
|
return [];
|
|
48
48
|
}
|
|
49
|
-
const files = import_fs.default.readdirSync(
|
|
50
|
-
const
|
|
49
|
+
const files = import_fs.default.readdirSync(contentDirectory);
|
|
50
|
+
const allContent = files.filter((file) => file.endsWith(".md")).map((file) => {
|
|
51
51
|
const slug = file.replace(".md", "");
|
|
52
|
-
const filePath = import_path.default.join(
|
|
52
|
+
const filePath = import_path.default.join(contentDirectory, file);
|
|
53
53
|
const fileContent = import_fs.default.readFileSync(filePath, "utf8");
|
|
54
54
|
const { data, content } = (0, import_gray_matter.default)(fileContent);
|
|
55
55
|
const readingTimeText = (0, import_reading_time.default)(content).text;
|
|
@@ -61,11 +61,11 @@ function getAllBlogsMeta(config) {
|
|
|
61
61
|
}).sort((a, b) => {
|
|
62
62
|
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
|
63
63
|
});
|
|
64
|
-
return
|
|
64
|
+
return allContent;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
const filePath = import_path.default.join(
|
|
66
|
+
function getContent(slug, config) {
|
|
67
|
+
const contentDirectory = import_path.default.join(config.contentDirectory, config.contentSubdirectory || "blog");
|
|
68
|
+
const filePath = import_path.default.join(contentDirectory, `${slug}.md`);
|
|
69
69
|
if (!import_fs.default.existsSync(filePath)) {
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
@@ -78,11 +78,11 @@ function getBlog(slug, config) {
|
|
|
78
78
|
slug,
|
|
79
79
|
readingTime: readingTimeText
|
|
80
80
|
},
|
|
81
|
-
content
|
|
81
|
+
body: content
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
85
85
|
0 && (module.exports = {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
getAllContentMeta,
|
|
87
|
+
getContent
|
|
88
88
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface ContentMeta {
|
|
2
2
|
title: string;
|
|
3
3
|
description: string;
|
|
4
4
|
date: string;
|
|
@@ -6,33 +6,33 @@ interface BlogMeta {
|
|
|
6
6
|
slug: string;
|
|
7
7
|
readingTime: string;
|
|
8
8
|
}
|
|
9
|
-
interface
|
|
10
|
-
metadata:
|
|
11
|
-
|
|
9
|
+
interface Content {
|
|
10
|
+
metadata: ContentMeta;
|
|
11
|
+
body: string;
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
13
|
+
interface ContentConfig {
|
|
14
14
|
contentDirectory: string;
|
|
15
|
-
|
|
15
|
+
contentSubdirectory?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* SSR and SSG only: Get all
|
|
19
|
+
* SSR and SSG only: Get all content metadata from the filesystem.
|
|
20
20
|
* This function requires Node.js fs module and only works in server environments
|
|
21
21
|
* (Next.js SSR/SSG, Node.js scripts, etc.).
|
|
22
22
|
*
|
|
23
|
-
* @param config -
|
|
24
|
-
* @returns Array of
|
|
23
|
+
* @param config - Content kit configuration
|
|
24
|
+
* @returns Array of content metadata
|
|
25
25
|
*/
|
|
26
|
-
declare function
|
|
26
|
+
declare function getAllContentMeta(config: ContentConfig): ContentMeta[];
|
|
27
27
|
/**
|
|
28
|
-
* SSR and SSG only: Get
|
|
28
|
+
* SSR and SSG only: Get content from the filesystem.
|
|
29
29
|
* This function requires Node.js fs module and only works in server environments
|
|
30
30
|
* (Next.js SSR/SSG, Node.js scripts, etc.).
|
|
31
31
|
*
|
|
32
|
-
* @param slug -
|
|
33
|
-
* @param config -
|
|
34
|
-
* @returns
|
|
32
|
+
* @param slug - Content slug/identifier
|
|
33
|
+
* @param config - Content kit configuration
|
|
34
|
+
* @returns Content data or null if not found
|
|
35
35
|
*/
|
|
36
|
-
declare function
|
|
36
|
+
declare function getContent(slug: string, config: ContentConfig): Content | null;
|
|
37
37
|
|
|
38
|
-
export { type
|
|
38
|
+
export { type Content, type ContentConfig, type ContentMeta, getAllContentMeta, getContent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface ContentMeta {
|
|
2
2
|
title: string;
|
|
3
3
|
description: string;
|
|
4
4
|
date: string;
|
|
@@ -6,33 +6,33 @@ interface BlogMeta {
|
|
|
6
6
|
slug: string;
|
|
7
7
|
readingTime: string;
|
|
8
8
|
}
|
|
9
|
-
interface
|
|
10
|
-
metadata:
|
|
11
|
-
|
|
9
|
+
interface Content {
|
|
10
|
+
metadata: ContentMeta;
|
|
11
|
+
body: string;
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
13
|
+
interface ContentConfig {
|
|
14
14
|
contentDirectory: string;
|
|
15
|
-
|
|
15
|
+
contentSubdirectory?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* SSR and SSG only: Get all
|
|
19
|
+
* SSR and SSG only: Get all content metadata from the filesystem.
|
|
20
20
|
* This function requires Node.js fs module and only works in server environments
|
|
21
21
|
* (Next.js SSR/SSG, Node.js scripts, etc.).
|
|
22
22
|
*
|
|
23
|
-
* @param config -
|
|
24
|
-
* @returns Array of
|
|
23
|
+
* @param config - Content kit configuration
|
|
24
|
+
* @returns Array of content metadata
|
|
25
25
|
*/
|
|
26
|
-
declare function
|
|
26
|
+
declare function getAllContentMeta(config: ContentConfig): ContentMeta[];
|
|
27
27
|
/**
|
|
28
|
-
* SSR and SSG only: Get
|
|
28
|
+
* SSR and SSG only: Get content from the filesystem.
|
|
29
29
|
* This function requires Node.js fs module and only works in server environments
|
|
30
30
|
* (Next.js SSR/SSG, Node.js scripts, etc.).
|
|
31
31
|
*
|
|
32
|
-
* @param slug -
|
|
33
|
-
* @param config -
|
|
34
|
-
* @returns
|
|
32
|
+
* @param slug - Content slug/identifier
|
|
33
|
+
* @param config - Content kit configuration
|
|
34
|
+
* @returns Content data or null if not found
|
|
35
35
|
*/
|
|
36
|
-
declare function
|
|
36
|
+
declare function getContent(slug: string, config: ContentConfig): Content | null;
|
|
37
37
|
|
|
38
|
-
export { type
|
|
38
|
+
export { type Content, type ContentConfig, type ContentMeta, getAllContentMeta, getContent };
|
package/dist/index.js
CHANGED
|
@@ -3,16 +3,16 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import matter from "gray-matter";
|
|
5
5
|
import readingTime from "reading-time";
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
if (!fs.existsSync(
|
|
9
|
-
console.warn(`
|
|
6
|
+
function getAllContentMeta(config) {
|
|
7
|
+
const contentDirectory = path.join(config.contentDirectory, config.contentSubdirectory || "blog");
|
|
8
|
+
if (!fs.existsSync(contentDirectory)) {
|
|
9
|
+
console.warn(`Content directory not found: ${contentDirectory}`);
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
|
-
const files = fs.readdirSync(
|
|
13
|
-
const
|
|
12
|
+
const files = fs.readdirSync(contentDirectory);
|
|
13
|
+
const allContent = files.filter((file) => file.endsWith(".md")).map((file) => {
|
|
14
14
|
const slug = file.replace(".md", "");
|
|
15
|
-
const filePath = path.join(
|
|
15
|
+
const filePath = path.join(contentDirectory, file);
|
|
16
16
|
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
17
17
|
const { data, content } = matter(fileContent);
|
|
18
18
|
const readingTimeText = readingTime(content).text;
|
|
@@ -24,11 +24,11 @@ function getAllBlogsMeta(config) {
|
|
|
24
24
|
}).sort((a, b) => {
|
|
25
25
|
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
|
26
26
|
});
|
|
27
|
-
return
|
|
27
|
+
return allContent;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
const filePath = path.join(
|
|
29
|
+
function getContent(slug, config) {
|
|
30
|
+
const contentDirectory = path.join(config.contentDirectory, config.contentSubdirectory || "blog");
|
|
31
|
+
const filePath = path.join(contentDirectory, `${slug}.md`);
|
|
32
32
|
if (!fs.existsSync(filePath)) {
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
@@ -41,10 +41,10 @@ function getBlog(slug, config) {
|
|
|
41
41
|
slug,
|
|
42
42
|
readingTime: readingTimeText
|
|
43
43
|
},
|
|
44
|
-
content
|
|
44
|
+
body: content
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
getAllContentMeta,
|
|
49
|
+
getContent
|
|
50
50
|
};
|