This commit is contained in:
huqi 2020-11-29 17:44:19 +08:00
parent 225f9af73f
commit 554db3f3d7
5 changed files with 34 additions and 15 deletions

12
mod.ts
View File

@ -5,11 +5,11 @@ import { weiboSearch } from "./weibo-search.ts";
import { toutiaoSearch } from "./toutiao-search.ts";
export async function init() {
await zhihuVideo();
await zhihuQuestions();
await zhihuSearch();
await weiboSearch();
await toutiaoSearch();
await zhihuVideo();
await zhihuQuestions();
await zhihuSearch();
await weiboSearch();
await toutiaoSearch();
}
init()
init();

View File

@ -155,7 +155,10 @@ Deno.test("createArchive4Question", function (): void {
{ title: "hello", url: "world" },
];
assertStringIncludes(createArchive4Question(words, "2020-02-02"), "# 2020-02-02");
assertStringIncludes(
createArchive4Question(words, "2020-02-02"),
"# 2020-02-02",
);
assertStringIncludes(createArchive4Question(words, "2020-02-02"), "共 2 条");
});
@ -178,7 +181,10 @@ Deno.test("createArchive4Video", function (): void {
{ title: "hello", url: "world" },
];
assertStringIncludes(createArchive4Video(words, "2020-02-02"), "# 2020-02-02");
assertStringIncludes(
createArchive4Video(words, "2020-02-02"),
"# 2020-02-02",
);
assertStringIncludes(createArchive4Video(words, "2020-02-02"), "共 2 条");
});

View File

@ -68,12 +68,14 @@ export async function createReadme4Video(words: Question[]): Promise<string> {
);
}
export async function createReadme4Question(words: Question[]): Promise<string> {
export async function createReadme4Question(
words: Question[],
): Promise<string> {
const readme = await Deno.readTextFile("./README.md");
return readme.replace(
/<!-- BEGIN ZHIHUQUESTIONS -->[\W\w]*<!-- END ZHIHUQUESTIONS -->/,
createQuestionList(words),
);
/<!-- BEGIN ZHIHUQUESTIONS -->[\W\w]*<!-- END ZHIHUQUESTIONS -->/,
createQuestionList(words),
);
}
export async function createReadme4Search(
@ -155,7 +157,10 @@ ${
<!-- END TOUTIAO -->`;
}
export function createArchive4Question(words: Question[], date: string): string {
export function createArchive4Question(
words: Question[],
date: string,
): string {
return `# ${date}\n
${words.length} \n
${createQuestionList(words)}

View File

@ -6,7 +6,11 @@ import { exists } from "std/fs/mod.ts";
// import { config } from 'dotenv/mod.ts'
import type { ZhihuQuestionList, Question } from "./types.ts";
import { createArchive4Question, createReadme4Question, mergeQuestions } from "./utils.ts";
import {
createArchive4Question,
createReadme4Question,
mergeQuestions,
} from "./utils.ts";
const response = await fetch(
"https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=100",

View File

@ -5,7 +5,11 @@ import { join } from "std/path/mod.ts";
import { exists } from "std/fs/mod.ts";
import type { ZhihuVideoList, Question } from "./types.ts";
import { createArchive4Video, createReadme4Video, mergeQuestions } from "./utils.ts";
import {
createArchive4Video,
createReadme4Video,
mergeQuestions,
} from "./utils.ts";
const response = await fetch(
"https://www.zhihu.com/api/v3/feed/topstory/hot-lists/zvideo?limit=100",