Bridgy-Fed通知スクリプトを書き換えた

noteだけでなくblogのほうも更新があるとBridgy-Fedに通知されるようにスクリプトを書き換えた。

const child_process = await import('child_process')const MAX_MENTION_SENDS = 10const sleep = (sec) => new Promise((res) => setTimeout(res, sec * 1000))async function sendWebmention(oldCommitHash, newCommitHash) {  const diff = child_process  .spawnSync('git', ['diff', '--name-only', oldCommitHash, newCommitHash])  .stdout.toString()  const files = diff.split('\n')  const filter_list =[    {      path: "src/content/blog/",      url: "https://ubanis.com/"    },    {      path: "src/content/note/",      url: "https://ubanis.com/note/"    }  ]  var url_list = []  for(const s of filter_list) {    const filtered = files.filter((file) => file.indexOf(s.path) !== -1)    const mentionlist = {file: filtered,url: s.url}    console.log(mentionlist)    for (let i = 0; i < mentionlist.file.length && i < MAX_MENTION_SENDS; ++i) {      const filePath = mentionlist.file[i].split('/')      const linkPath = filePath.slice(3)      const tempurl = mentionlist.url + linkPath.join('/')      const url = tempurl.replace(/\.mdx|\.md/g, "")      // eslint-disable-next-line no-console      url_list.push(url);    }  }  if (url_list.length >= 1) {    await sleep(110)    for(const url of url_list) {      console.log('sending webmention of ' + url)      child_process.spawnSync('curl', [        'https://fed.brid.gy/webmention',        '-d',        `source=${encodeURIComponent(url)}`,        '-d',        `target=https://fed.brid.gy`,      ])    }  }}const args = process.argv.slice(2)sendWebmention(args[0], args[1])