Created
July 11, 2021 12:12
-
-
Save agatan/ce03732e03d3cae3a7e70b2ac62a0164 to your computer and use it in GitHub Desktop.
Qiita から記事を export する Deno スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from "https://deno.land/std@0.100.0/path/mod.ts"; | |
import ky from "https://cdn.skypack.dev/ky?dts"; | |
const outDir = Deno.args[0] || "output"; | |
await Deno.mkdir(outDir, { recursive: true }); | |
console.log(`Export to ${outDir}`); | |
const items = await (ky.get( | |
"https://qiita.com/api/v2/authenticated_user/items?page=1&per_page=100", | |
{ | |
headers: { "Authorization": `Bearer ${Deno.env.get("QIITA_API_KEY")}` }, | |
}, | |
)).json() as any[]; | |
console.log(`${items.length} items found`); | |
for (const item of items) { | |
console.log(item); | |
const title: string = item["title"]; | |
const body: string = item["body"]; | |
const date: string = item["created_at"]; | |
const tags: string[] = item.tags.map((t: any) => t["name"]); | |
const url: string = item["url"]; | |
const bodyWithMatter = `--- | |
title: "${title}" | |
date: ${date} | |
tags: ${JSON.stringify(tags)} | |
url: ${url} | |
--- | |
${body}`; | |
const outFilePath = path.join(outDir, title + ".md"); | |
await Deno.writeTextFile(outFilePath, bodyWithMatter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment