-
-
Save eai04191/c3a74f60c06b1e33ed081086986bea10 to your computer and use it in GitHub Desktop.
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
const fs = require("fs"); | |
const ogs = require("open-graph-scraper"); | |
const axios = require("axios"); | |
const makeDoc = async () => { | |
console.log("gistからリストを取得します..."); | |
const avatars = await getAvatarList(); | |
console.log("avatars", avatars); | |
console.log("OGPを取得します..."); | |
let ogps = []; | |
// 負荷のためあえて直列にやる | |
for (let boothUrl of avatars) { | |
const ogp = await getOGP(boothUrl); | |
ogps.push(ogp); | |
} | |
console.log("OGPs", ogps); | |
console.log("htmlを作成します..."); | |
const table = makeTable(ogps); | |
fs.writeFileSync("wiki.md", table); | |
console.log("done."); | |
}; | |
const getAvatarList = async () => { | |
return axios | |
.get( | |
"https://gist.githubusercontent.com/owatan/6c9703a9e3f5c1038084dbb19e8283cf/raw" | |
) | |
.then((response) => response.data) | |
.then((rawText) => | |
rawText.match(/https:\/\/(.+)?booth\.pm\/(ja\/)?items\/\d+$/gm) | |
); | |
}; | |
const getOGP = (boothUrl) => { | |
return ogs({ url: boothUrl }).then((data) => { | |
const { error, result, response } = data; | |
return result; | |
}); | |
}; | |
const makeTable = (ogps) => { | |
const cellSize = 210; // px | |
const imageSize = cellSize - 10; | |
let table = "<table><tbody><tr>"; | |
ogps.forEach((ogp, index) => { | |
table += ` | |
<td align="center" width="${cellSize};"> | |
<a href="${ogp.ogUrl}"> | |
<img src="${ogp.ogImage.url}" width="${imageSize}px;" /> | |
<br /> | |
<sub><b>${ogp.ogTitle}</b></sub> | |
</a> | |
</td> | |
`.replace(/\s{4,}/gm, ""); | |
// markdownが壊れるので余計なスペースを消す | |
// 改行処理 3の倍数で改行する | |
if (!((index + 1) % 3)) { | |
table += "</tr><tr>"; | |
} | |
}); | |
table += "</tr></tbody></table>"; | |
return table; | |
}; | |
makeDoc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment