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AA+B,UAAe,CAClE,QAAS,CACP,OAAQ,+CAUZ,GAPmB,MAAf,EAAI,SACN,QAAY,MAAM,gCAAgC,UAAe,CAC/D,QAAS,CACP,OAAQ,gDAIK,MAAf,EAAI,OACN,MAAM,IAAI,MAAM,kCAElB,IAAI,SAAe,EAAI,QAAQ,IAAI,SAC/B,EAAQ,gBAAgB,EAAI,QAAQ,IAAI,SAE5C,KAAO,GAAS,EAAM,MACpB,QAAY,MAAM,EAAM,KAAK,KAC7B,EAAQ,EAAM,cAAc,EAAI,QAAQ,IAAI,UAC5C,EAAQ,gBAAgB,EAAI,QAAQ,IAAI,SAE1C,OAAO,CACT,CAEA,eAAe,iBAAiB,EAAO,GACrC,MAAM,QAAY,MAChB,0BAA0B,KAAS,2BAErC,GAAmB,MAAf,EAAI,OACN,OAAO,EAAI,MAEf,CAEA,eAAe,YAAY,EAAO,GAChC,MAAM,QAAY,MAChB,0BAA0B,KAAS,sBAErC,GAAmB,MAAf,EAAI,OACN,OAAO,EAAI,MAEf,CAEA,eAAe,UAAU,EAAO,EAAU,GACxC,IAAI,EAeJ,GAdI,EACF,QAAY,MACV,0BAA0B,KAAS,YAAmB,MAGxD,QAAY,MACV,0BAA0B,KAAS,YAAmB,SAErC,MAAf,EAAI,SACN,QAAY,MACV,0BAA0B,KAAS,uBAItB,MAAf,EAAI,OACN,OAAO,EAAI,QAEf,CA3EA,OAAO,QAAU","file":"/npm/github-cms@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/github-cms@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fetch = require('node-fetch')\nconst parseLinkHeader = require('parse-link-header')\nconst matter = require('gray-matter')\nconst fs = require('fs')\nconst path = require('path')\n\nasync function fetchContent(\n  owner,\n  directory,\n  filter = false,\n  json = false,\n  verbose = false\n) {\n  if (verbose) {\n    console.log('Fetching repository list for account:', owner)\n  }\n  const repos = await fetchRepoList(owner)\n  if (verbose) {\n    console.log(`Found ${repos.length} repositories`)\n  }\n\n  fs.mkdirSync(directory, { recursive: true })\n\n  for (const repo of repos) {\n    if (verbose) {\n      console.log('Fetching data for repository:', repo.title)\n    }\n\n    const frontmatter = await fetchFrontmatter(owner, repo.title)\n    if (frontmatter || !filter) {\n      // Frontmatter\n      let content\n      if (frontmatter) {\n        const config = matter(frontmatter)\n        Object.assign(repo, config.data)\n        content = config.content\n      }\n\n      // Logo\n      const logo = await fetchLogo(owner, repo.title, repo.logo)\n      if (logo) {\n        const logoFilename = repo.title + path.extname(repo.logo || '*.png')\n        fs.writeFileSync(path.join(directory, logoFilename), logo)\n        repo.logo = logoFilename\n      } else {\n        delete repo.logo\n      }\n\n      // Content\n      if (!json) {\n        if (!content || content.trim().length === 0) {\n          content = (await fetchReadme(owner, repo.title)) || ''\n        }\n        fs.writeFileSync(\n          path.join(directory, `${repo.title}.md`),\n          matter.stringify(content, repo)\n        )\n      }\n    }\n  }\n  if (json) {\n    fs.writeFileSync(\n      path.join(directory, `repositories.json`),\n      JSON.stringify(repos)\n    )\n  }\n}\n\nmodule.exports = fetchContent\n\nfunction mapRepo(r) {\n  return {\n    title: r.name,\n    description: r.description || '',\n    url: r.html_url,\n    tags: r.topics || []\n  }\n}\n\nasync function fetchRepoList(owner) {\n  let res = await fetch(`https://api.github.com/orgs/${owner}/repos`, {\n    headers: {\n      Accept: 'application/vnd.github.mercy-preview+json'\n    }\n  })\n  if (res.status === 404) {\n    res = await fetch(`https://api.github.com/users/${owner}/repos`, {\n      headers: {\n        Accept: 'application/vnd.github.mercy-preview+json'\n      }\n    })\n  }\n  if (res.status === 404) {\n    throw new Error('User or organization not found')\n  }\n  let repos = (await res.json()).map(mapRepo)\n  let pages = parseLinkHeader(res.headers.get('link'))\n\n  while (pages && pages.next) {\n    res = await fetch(pages.next.url)\n    repos = repos.concat((await res.json()).map(mapRepo))\n    pages = parseLinkHeader(res.headers.get('link'))\n  }\n  return repos\n}\n\nasync function fetchFrontmatter(owner, repoName) {\n  const res = await fetch(\n    `https://raw.github.com/${owner}/${repoName}/master/.github-cms.md`\n  )\n  if (res.status === 200) {\n    return res.text()\n  }\n}\n\nasync function fetchReadme(owner, repoName) {\n  const res = await fetch(\n    `https://raw.github.com/${owner}/${repoName}/master/README.md`\n  )\n  if (res.status === 200) {\n    return res.text()\n  }\n}\n\nasync function fetchLogo(owner, repoName, logoPath) {\n  let res\n  if (logoPath) {\n    res = await fetch(\n      `https://raw.github.com/${owner}/${repoName}/master/${logoPath}`\n    )\n  } else {\n    res = await fetch(\n      `https://raw.github.com/${owner}/${repoName}/master/${repoName}.png`\n    )\n    if (res.status === 404) {\n      res = await fetch(\n        `https://raw.github.com/${owner}/${repoName}/master/logo.png`\n      )\n    }\n  }\n  if (res.status === 200) {\n    return res.buffer()\n  }\n}\n"]}