-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown.ts
71 lines (58 loc) · 1.88 KB
/
markdown.ts
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
import { chunk } from "$std/collections/mod.ts";
import wallpapers from "./fresh/routes/wallpapers.json" with { type: "json" };
function link(text = "", url = "") {
return `[${text}](${url})`;
}
function image(alt = "", src = "") {
return `![${alt}](${src})`;
}
class Markdown {
content = "";
header(content = "", level = 1) {
this.content += `${"#".repeat(level)} ${content}\n\n`;
return this;
}
paragraph(content = "") {
this.content += `${content}\n\n`;
return this;
}
codeBlock(content = "", language = "bash") {
this.content += "```" + language + "\n" + content + "\n```\n\n";
return this;
}
table(rows: string[][]) {
this.content += rows.map((row) => row.join("")).join("\n\n");
return this;
}
async write(path: string, fileName: string, content = this.content) {
const file = await Deno.create(`${path}${fileName}.md`);
const data = new TextEncoder().encode(content);
await file.write(data);
await file.close();
return this;
}
}
wallpapers.sort((a, b) => Number(b.enddate) - Number(a.enddate));
const markdown = new Markdown();
const website = "https://bing-wallpaper.deno.dev";
markdown
.header("Bing Wallpaper", 1)
.paragraph(link(website, website))
.header("Local Preview", 2)
.codeBlock(`deno task start`)
.header("Get Latest Bing Wallpaper", 2)
.codeBlock("deno task wallpapers")
.header("Latest Bing Wallpaper", 2);
type Wallpaper = {
enddate: string;
url: string;
copyright: string;
};
const today = (item: Wallpaper) =>
image(`${item.enddate}`, item.url += "&rf=LaDigue_UHD.jpg&w=900&c=1");
const preview = (item: Wallpaper) =>
image(`${item.enddate}`, item.url += "&rf=LaDigue_UHD.jpg&w=272&c=1");
const wallpaper = wallpapers.shift();
if (wallpaper) markdown.paragraph(today(wallpaper));
markdown.paragraph(wallpapers.splice(0, 9).map(preview).join("\n"));
markdown.write("./", "README");