Repository navigation
Expand file tree
/
Copy pathpost.js
More file actions
executable file
·129 lines (122 loc) · 3.54 KB
/
Copy pathpost.js
File metadata and controls
executable file
·129 lines (122 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env -S bun
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { site_map, sitePost } from "./src/site/index.js";
export { site_map, sitePost };
const run = async () => {
const argv = await yargs(hideBin(process.argv))
.scriptName("post")
.usage("用法: $0 [选项] [markdown文件路径]")
.option("to", {
alias: "t",
type: "string",
describe:
"目标平台: juejin | rustcc | rust-lang | hacknews | reddit | all | auto",
default: "auto",
})
.option("dry-run", {
type: "boolean",
describe: "预览模式:读取 Cookie、检查会话并预览,不执行实际发布",
default: false,
})
.option("section", {
alias: "s",
type: "string",
describe: "目标分类 / 板块名称或 slug (如: 后端, 大家的项目, announcements)",
})
.option("tags", {
type: "string",
describe: "以英文逗号分隔的标签列表 (juejin, rustcc 可用)",
})
.option("link", {
alias: "l",
type: "string",
describe: "外部项目链接 (默认从 Markdown 提取)",
})
.option("title", {
type: "string",
describe: "自定义文章或帖子标题",
})
.option("edit", {
alias: "e",
type: "string",
describe: "编辑更新已有文章或帖子 ID (juejin, rustcc 可用)",
})
.option("as-text", {
type: "boolean",
describe: "以纯文本讨论帖形式发布 (Hacker News 可用)",
default: false,
})
.option("comment", {
type: "boolean",
describe:
"发布链接帖时是否自动追加首评 (Hacker News 可用,可用 --no-comment 关闭)",
default: true,
})
.option("post", {
alias: "p",
type: "string",
describe: "指定回复特定 Reddit 帖子 ID 或 URL",
})
.option("subreddit", {
type: "string",
describe: "目标 Reddit 子版块 (如: rust, 默认读取 conf.js)",
})
.option("flair", {
type: "string",
describe: "Reddit 帖子标签 / Flair (如: project, discussion, help 或 UUID)",
})
.option("reply", {
type: "boolean",
describe: "开启 Reddit 自动回复模式 (匹配已有帖子跟帖回复,默认直接发新帖)",
default: false,
})
.option("query", {
alias: "q",
type: "string",
describe: "检索词列表,以逗号分隔 (Reddit 回复模式可用)",
})
.option("max", {
alias: "m",
type: "number",
describe: "单次最大回复帖子数量 (Reddit 回复模式可用)",
default: 1,
})
.help("help")
.alias("h", "help")
.parse(),
positional_li = argv._.map((a) => String(a));
let target = argv.to,
file_name = positional_li.find((a) => a.endsWith(".md"));
// Allow first positional argument to specify target platform (e.g. ./post.js juejin file.md)
if (positional_li.length > 0 && site_map[positional_li[0].toLowerCase()]) {
target = positional_li[0].toLowerCase();
file_name = positional_li.slice(1).find((a) => a.endsWith(".md")) ?? file_name;
}
const [code] = await sitePost(
target,
file_name,
argv.dryRun,
argv.section,
argv.tags,
argv.link,
argv.title,
argv.edit,
{
asText: argv.asText,
comment: argv.comment,
post: argv.post,
subreddit: argv.subreddit,
flair: argv.flair,
reply: argv.reply,
query: argv.query,
max: argv.max,
},
);
if (code !== 0) {
process.exit(code);
}
};
if (import.meta.main) {
await run();
}