@plttn/mkd 0.0.2 → 0.1.5
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.cjs +423 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +397 -20
- package/dist/index.js.map +1 -1
- package/package.json +12 -18
- package/dist/commands/new.d.ts +0 -10
- package/dist/commands/new.js +0 -76
- package/dist/commands/new.js.map +0 -1
- package/dist/commands/publish.d.ts +0 -6
- package/dist/commands/publish.js +0 -42
- package/dist/commands/publish.js.map +0 -1
- package/dist/commands/retract.d.ts +0 -6
- package/dist/commands/retract.js +0 -42
- package/dist/commands/retract.js.map +0 -1
- package/dist/commands/update.d.ts +0 -6
- package/dist/commands/update.js +0 -42
- package/dist/commands/update.js.map +0 -1
- package/dist/lib/commands.d.ts +0 -19
- package/dist/lib/commands.js +0 -38
- package/dist/lib/commands.js.map +0 -1
- package/dist/lib/deps.d.ts +0 -17
- package/dist/lib/deps.js +0 -35
- package/dist/lib/deps.js.map +0 -1
- package/dist/lib/tags.d.ts +0 -14
- package/dist/lib/tags.js +0 -70
- package/dist/lib/tags.js.map +0 -1
package/dist/commands/publish.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { command } from "cmd-ts";
|
|
2
|
-
import { autocompleteMultiselect, isCancel, intro, outro, } from "@clack/prompts";
|
|
3
|
-
import matter from "gray-matter";
|
|
4
|
-
import { readPosts, parseFrontmatter, postsToOptions, selectedValuesToPosts, } from "../lib/commands";
|
|
5
|
-
export function makePublishCommand({ config, pfs }) {
|
|
6
|
-
return command({
|
|
7
|
-
name: "publish",
|
|
8
|
-
description: "Undraft a post",
|
|
9
|
-
args: {},
|
|
10
|
-
handler: async () => {
|
|
11
|
-
const posts = await readPosts(pfs, config);
|
|
12
|
-
const drafts = posts.filter((post) => parseFrontmatter(post)[config.draftKey] === true);
|
|
13
|
-
const selected = await getPostsToPublish(drafts, config);
|
|
14
|
-
for (const draft of selected) {
|
|
15
|
-
await updateDraftFrontMatter(draft, { config, pfs });
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
async function getPostsToPublish(drafts, config) {
|
|
21
|
-
const options = postsToOptions(drafts, config);
|
|
22
|
-
intro("Publishing posts");
|
|
23
|
-
const selected = await autocompleteMultiselect({
|
|
24
|
-
message: "Select posts to publish",
|
|
25
|
-
options,
|
|
26
|
-
});
|
|
27
|
-
if (isCancel(selected)) {
|
|
28
|
-
outro("Publishing cancelled.");
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
outro("Posts undrafted...");
|
|
32
|
-
return selectedValuesToPosts(selected, drafts);
|
|
33
|
-
}
|
|
34
|
-
async function updateDraftFrontMatter(draft, deps) {
|
|
35
|
-
const parsed = matter(draft.content);
|
|
36
|
-
const fm = parsed.data;
|
|
37
|
-
fm[deps.config.draftKey] = false;
|
|
38
|
-
const updatedContent = matter.stringify(parsed.content, fm);
|
|
39
|
-
await deps.pfs.write(`${deps.config.blogDir}/${draft.file}`, updatedContent);
|
|
40
|
-
return { ...draft, content: updatedContent };
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=publish.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EACL,uBAAuB,EACvB,QAAQ,EACR,KAAK,EACL,KAAK,GACN,MAAM,gBAAgB,CAAC;AACxB,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,qBAAqB,GAEtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAAE,GAAG,EAAQ;IACtD,OAAO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AAM,EAAE,GAAG,MAAM,CAAC,IAA+B,CAAC;IAClD,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IACjC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;IAC7E,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Deps } from "../lib/deps";
|
|
2
|
-
export declare function makeUnPublishCommand({ config, pfs }: Deps): Partial<import("cmd-ts/dist/cjs/argparser").Register> & {
|
|
3
|
-
parse(context: import("cmd-ts/dist/cjs/argparser").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser").ParsingResult<{}>>;
|
|
4
|
-
} & import("cmd-ts/dist/cjs/helpdoc").PrintHelp & import("cmd-ts/dist/cjs/helpdoc").ProvidesHelp & import("cmd-ts/dist/cjs/helpdoc").Named & Partial<import("cmd-ts/dist/cjs/helpdoc").Versioned> & import("cmd-ts/dist/cjs/argparser").Register & import("cmd-ts/dist/cjs/runner").Handling<{}, Promise<void>> & {
|
|
5
|
-
run(context: import("cmd-ts/dist/cjs/argparser").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser").ParsingResult<Promise<void>>>;
|
|
6
|
-
} & Partial<import("cmd-ts/dist/cjs/helpdoc").Versioned & import("cmd-ts/dist/cjs/helpdoc").Descriptive & import("cmd-ts/dist/cjs/helpdoc").Aliased>;
|
package/dist/commands/retract.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { command } from "cmd-ts";
|
|
2
|
-
import { autocomplete, isCancel, intro, outro } from "@clack/prompts";
|
|
3
|
-
import matter from "gray-matter";
|
|
4
|
-
import { readPosts, postsToOptions, findPostByFile, } from "../lib/commands";
|
|
5
|
-
export function makeUnPublishCommand({ config, pfs }) {
|
|
6
|
-
return command({
|
|
7
|
-
name: "unpublish",
|
|
8
|
-
description: "Unpublish a post",
|
|
9
|
-
args: {},
|
|
10
|
-
handler: async () => {
|
|
11
|
-
const posts = await readPosts(pfs, config);
|
|
12
|
-
const post = await getPostToUnpub(posts, config);
|
|
13
|
-
if (!post)
|
|
14
|
-
return;
|
|
15
|
-
await unpubPost(post, { config, pfs });
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function getPostToUnpub(posts, config) {
|
|
20
|
-
const options = postsToOptions(posts, config);
|
|
21
|
-
intro("Unpublish a post");
|
|
22
|
-
const selected = await autocomplete({
|
|
23
|
-
message: "Select post to unpublish",
|
|
24
|
-
options,
|
|
25
|
-
});
|
|
26
|
-
if (isCancel(selected)) {
|
|
27
|
-
outro("Unpublish cancelled.");
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
outro("Post unpublished.");
|
|
31
|
-
const found = findPostByFile(posts, selected);
|
|
32
|
-
return found ?? null;
|
|
33
|
-
}
|
|
34
|
-
async function unpubPost(post, deps) {
|
|
35
|
-
const parsed = matter(post.content);
|
|
36
|
-
const fm = parsed.data;
|
|
37
|
-
fm[deps.config.draftKey] = true;
|
|
38
|
-
const updatedContent = matter.stringify(parsed.content, fm);
|
|
39
|
-
await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
|
|
40
|
-
return { ...post, content: updatedContent };
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=retract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retract.js","sourceRoot":"","sources":["../../src/commands/retract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,QA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AE,IAAU;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,IAA+B,CAAC;IAClD,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IAChC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;IAC5E,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Deps } from "../lib/deps";
|
|
2
|
-
export declare function makeUpdateCommand({ config, pfs }: Deps): Partial<import("cmd-ts/dist/cjs/argparser").Register> & {
|
|
3
|
-
parse(context: import("cmd-ts/dist/cjs/argparser").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser").ParsingResult<{}>>;
|
|
4
|
-
} & import("cmd-ts/dist/cjs/helpdoc").PrintHelp & import("cmd-ts/dist/cjs/helpdoc").ProvidesHelp & import("cmd-ts/dist/cjs/helpdoc").Named & Partial<import("cmd-ts/dist/cjs/helpdoc").Versioned> & import("cmd-ts/dist/cjs/argparser").Register & import("cmd-ts/dist/cjs/runner").Handling<{}, Promise<void>> & {
|
|
5
|
-
run(context: import("cmd-ts/dist/cjs/argparser").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser").ParsingResult<Promise<void>>>;
|
|
6
|
-
} & Partial<import("cmd-ts/dist/cjs/helpdoc").Versioned & import("cmd-ts/dist/cjs/helpdoc").Descriptive & import("cmd-ts/dist/cjs/helpdoc").Aliased>;
|
package/dist/commands/update.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { command } from "cmd-ts";
|
|
2
|
-
import { autocomplete, isCancel, intro, outro } from "@clack/prompts";
|
|
3
|
-
import matter from "gray-matter";
|
|
4
|
-
import { readPosts, postsToOptions, findPostByFile, } from "../lib/commands";
|
|
5
|
-
export function makeUpdateCommand({ config, pfs }) {
|
|
6
|
-
return command({
|
|
7
|
-
name: "update",
|
|
8
|
-
description: "Update a post's modified date",
|
|
9
|
-
args: {},
|
|
10
|
-
handler: async () => {
|
|
11
|
-
const posts = await readPosts(pfs, config);
|
|
12
|
-
const post = await getPostToUpdate(posts, config);
|
|
13
|
-
if (!post)
|
|
14
|
-
return;
|
|
15
|
-
await updatePostDate(post, { config, pfs });
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function getPostToUpdate(posts, config) {
|
|
20
|
-
const options = postsToOptions(posts, config);
|
|
21
|
-
intro("Update a post");
|
|
22
|
-
const selected = await autocomplete({
|
|
23
|
-
message: "Select post to update",
|
|
24
|
-
options,
|
|
25
|
-
});
|
|
26
|
-
if (isCancel(selected)) {
|
|
27
|
-
outro("Update cancelled.");
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
outro("Post updated.");
|
|
31
|
-
const found = findPostByFile(posts, selected);
|
|
32
|
-
return found ?? null;
|
|
33
|
-
}
|
|
34
|
-
async function updatePostDate(post, deps) {
|
|
35
|
-
const parsed = matter(post.content);
|
|
36
|
-
const fm = parsed.data;
|
|
37
|
-
fm[deps.config.modifiedAtKey] = new Date();
|
|
38
|
-
const updatedContent = matter.stringify(parsed.content, fm);
|
|
39
|
-
await deps.pfs.write(`${deps.config.blogDir}/${post.file}`, updatedContent);
|
|
40
|
-
return { ...post, content: updatedContent };
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO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IAAI,IAAI,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,IAAU,EAAE,IAAU;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,IAA+B,CAAC;IAClD,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IAC3C,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;IAC5E,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAC9C,CAAC"}
|
package/dist/lib/commands.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Config, Deps } from "./deps";
|
|
2
|
-
export type Post = {
|
|
3
|
-
file: string;
|
|
4
|
-
content: string;
|
|
5
|
-
};
|
|
6
|
-
export type Frontmatter = Record<string, unknown>;
|
|
7
|
-
/** Read all files from the blog directory and return them as Post objects */
|
|
8
|
-
export declare function readPosts(pfs: Deps["pfs"], config: Config): Promise<Post[]>;
|
|
9
|
-
/** Parse frontmatter from a Post */
|
|
10
|
-
export declare function parseFrontmatter(post: Post): Frontmatter;
|
|
11
|
-
/** Convert Posts to prompt option objects (value/label/hint) */
|
|
12
|
-
export declare function postsToOptions(posts: Post[], config: Config): {
|
|
13
|
-
value: string;
|
|
14
|
-
label: string;
|
|
15
|
-
hint: string;
|
|
16
|
-
}[];
|
|
17
|
-
/** Take the raw selected values returned by the prompt and return matching Post[] */
|
|
18
|
-
export declare function selectedValuesToPosts(selected: string[] | symbol, posts: Post[]): Post[];
|
|
19
|
-
export declare function findPostByFile(posts: Post[], fileName: string): Post | undefined;
|
package/dist/lib/commands.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import matter from "gray-matter";
|
|
2
|
-
/** Read all files from the blog directory and return them as Post objects */
|
|
3
|
-
export async function readPosts(pfs, config) {
|
|
4
|
-
const files = (await pfs.readdir(config.blogDir));
|
|
5
|
-
const posts = [];
|
|
6
|
-
for (const file of files) {
|
|
7
|
-
const content = await pfs.read(`${config.blogDir}/${file}`);
|
|
8
|
-
posts.push({ file, content });
|
|
9
|
-
}
|
|
10
|
-
return posts;
|
|
11
|
-
}
|
|
12
|
-
/** Parse frontmatter from a Post */
|
|
13
|
-
export function parseFrontmatter(post) {
|
|
14
|
-
const { data } = matter(post.content);
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
/** Convert Posts to prompt option objects (value/label/hint) */
|
|
18
|
-
export function postsToOptions(posts, config) {
|
|
19
|
-
return posts.map((post) => {
|
|
20
|
-
const fm = parseFrontmatter(post);
|
|
21
|
-
const title = String(fm[config.titleKey] ?? post.file);
|
|
22
|
-
return {
|
|
23
|
-
value: post.file,
|
|
24
|
-
label: title,
|
|
25
|
-
hint: post.file,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/** Take the raw selected values returned by the prompt and return matching Post[] */
|
|
30
|
-
export function selectedValuesToPosts(selected, posts) {
|
|
31
|
-
if (typeof selected === "symbol")
|
|
32
|
-
return [];
|
|
33
|
-
return posts.filter((p) => selected.includes(p.file));
|
|
34
|
-
}
|
|
35
|
-
export function findPostByFile(posts, fileName) {
|
|
36
|
-
return posts.find((p) => p.file === fileName);
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=commands.js.map
|
package/dist/lib/commands.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/lib/commands.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CA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C;IAC5C,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,QAAgB;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/lib/deps.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PoweredFileSystem } from "pwd-fs";
|
|
2
|
-
export type Config = {
|
|
3
|
-
blogDir: string;
|
|
4
|
-
titleKey: string;
|
|
5
|
-
author: string;
|
|
6
|
-
publishedAtKey: string;
|
|
7
|
-
modifiedAtKey: string;
|
|
8
|
-
authorKey: string;
|
|
9
|
-
draftKey: string;
|
|
10
|
-
descriptionKey: string;
|
|
11
|
-
tagsKey: string;
|
|
12
|
-
};
|
|
13
|
-
export type Deps = {
|
|
14
|
-
config: Config;
|
|
15
|
-
pfs: PoweredFileSystem;
|
|
16
|
-
};
|
|
17
|
-
export declare function loadConfig(pfs: PoweredFileSystem): Promise<Config>;
|
package/dist/lib/deps.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const defaultConfig = {
|
|
2
|
-
blogDir: "./src/blog",
|
|
3
|
-
titleKey: "title",
|
|
4
|
-
author: "",
|
|
5
|
-
publishedAtKey: "publishedAt",
|
|
6
|
-
modifiedAtKey: "updatedAt",
|
|
7
|
-
authorKey: "author",
|
|
8
|
-
draftKey: "draft",
|
|
9
|
-
descriptionKey: "description",
|
|
10
|
-
tagsKey: "tags",
|
|
11
|
-
};
|
|
12
|
-
export async function loadConfig(pfs) {
|
|
13
|
-
try {
|
|
14
|
-
const raw = await pfs.read("./mkd.json");
|
|
15
|
-
if (!raw.trim()) {
|
|
16
|
-
return defaultConfig;
|
|
17
|
-
}
|
|
18
|
-
const parsed = JSON.parse(raw);
|
|
19
|
-
if (!isRecord(parsed)) {
|
|
20
|
-
return defaultConfig;
|
|
21
|
-
}
|
|
22
|
-
const { $schema: _schema, ...config } = parsed;
|
|
23
|
-
return {
|
|
24
|
-
...defaultConfig,
|
|
25
|
-
...config,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return defaultConfig;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function isRecord(value) {
|
|
33
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=deps.js.map
|
package/dist/lib/deps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deps.js","sourceRoot":"","sources":["../../src/lib/deps.ts"],"names":[],"mappings":"AAmBA,MAAM,aAAa,GAAW;IAC5B,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,EAAE;IACV,cAAc,EAAE,aAAa;IAC7B,aAAa,EAAE,WAAW;IAC1B,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,OAAO;IACjB,cAAc,EAAE,aAAa;IAC7B,OAAO,EAAE,MAAM;CAChB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAsB;IACrD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEzC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAChB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE/B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;QAE/C,OAAO;YACL,GAAG,aAAa;YAChB,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,aAAa,CAAC;IACvB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/lib/tags.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Deps } from "./deps";
|
|
2
|
-
export type GetAllTagsOptions = {
|
|
3
|
-
concurrency?: number;
|
|
4
|
-
lowerCase?: boolean;
|
|
5
|
-
sort?: boolean;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Read all markdown files in `config.blogDir`, extract tags using the configured `tagsKey`,
|
|
9
|
-
* normalize & dedupe them, and return the list.
|
|
10
|
-
*
|
|
11
|
-
* This implementation uses the PoweredFileSystem API (pfs) for all path resolution and IO
|
|
12
|
-
* instead of `path.join` so it respects the pfs instance's `pwd` resolution semantics.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getAllTags(deps: Deps, opts?: GetAllTagsOptions): Promise<string[]>;
|
package/dist/lib/tags.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import matter from "gray-matter";
|
|
2
|
-
/**
|
|
3
|
-
* Read all markdown files in `config.blogDir`, extract tags using the configured `tagsKey`,
|
|
4
|
-
* normalize & dedupe them, and return the list.
|
|
5
|
-
*
|
|
6
|
-
* This implementation uses the PoweredFileSystem API (pfs) for all path resolution and IO
|
|
7
|
-
* instead of `path.join` so it respects the pfs instance's `pwd` resolution semantics.
|
|
8
|
-
*/
|
|
9
|
-
export async function getAllTags(deps, opts = {}) {
|
|
10
|
-
const { pfs, config } = deps;
|
|
11
|
-
const { concurrency = 8, lowerCase = true, sort = true } = opts;
|
|
12
|
-
const files = (await pfs.readdir(config.blogDir));
|
|
13
|
-
const mdFiles = files.filter((f) => f.endsWith(".md") || f.endsWith(".markdown"));
|
|
14
|
-
// split into batches of size `concurrency`
|
|
15
|
-
const batches = [];
|
|
16
|
-
for (let i = 0; i < mdFiles.length; i += concurrency) {
|
|
17
|
-
batches.push(mdFiles.slice(i, i + concurrency));
|
|
18
|
-
}
|
|
19
|
-
const tagSet = new Set();
|
|
20
|
-
async function parseFile(file) {
|
|
21
|
-
try {
|
|
22
|
-
// Resolve using pfs so it respects the base directory configured on the instance
|
|
23
|
-
const filePath = pfs.resolve(`${config.blogDir}/${file}`);
|
|
24
|
-
const content = await pfs.read(filePath);
|
|
25
|
-
const { data } = matter(content);
|
|
26
|
-
const raw = data[config.tagsKey];
|
|
27
|
-
return parseRawTags(raw);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// ignore single-file failures
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
for (const batch of batches) {
|
|
35
|
-
const results = await Promise.all(batch.map(parseFile));
|
|
36
|
-
for (const tags of results) {
|
|
37
|
-
for (let t of tags) {
|
|
38
|
-
if (!t)
|
|
39
|
-
continue;
|
|
40
|
-
t = t.trim();
|
|
41
|
-
if (!t)
|
|
42
|
-
continue;
|
|
43
|
-
if (lowerCase)
|
|
44
|
-
t = t.toLowerCase();
|
|
45
|
-
tagSet.add(t);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const out = Array.from(tagSet);
|
|
50
|
-
if (sort)
|
|
51
|
-
out.sort();
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
function parseRawTags(raw) {
|
|
55
|
-
if (!raw)
|
|
56
|
-
return [];
|
|
57
|
-
if (Array.isArray(raw))
|
|
58
|
-
return raw.map(String).flatMap(splitOnSeparators).map((s) => s.trim()).filter(Boolean);
|
|
59
|
-
if (typeof raw === "string")
|
|
60
|
-
return splitOnSeparators(raw).map((s) => s.trim()).filter(Boolean);
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
function splitOnSeparators(s) {
|
|
64
|
-
// Accept comma separated values and newline-separated lists, plus plain single tag strings
|
|
65
|
-
if (s.includes(",") || s.includes("\n")) {
|
|
66
|
-
return s.split(/[,\n]+/).map((x) => x.trim()).filter(Boolean);
|
|
67
|
-
}
|
|
68
|
-
return [s];
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=tags.js.map
|
package/dist/lib/tags.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/lib/tags.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AASjC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAAU,EACV,OAA0B,EAAE;IAE5B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,WAAW,GAAG,CAAC,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAEhE,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAa,CAAC;IAC9D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IAElF,2CAA2C;IAC3C,MAAM,OAAO,GAAe,EAAE,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC;QACrD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,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