pdehaan / 11ty-dashboard

This Week in Eleventy dashboard
0 stars 0 forks source link

Show recently added new sites from the 11ty-website ? #4

Open pdehaan opened 4 years ago

pdehaan commented 4 years ago

Problem: I only find these interesting, if the sites in https://github.com/11ty/11ty-website/tree/master/_data/sites list a source_url in their JSON file and I can view the site's source.

For example, https://github.com/11ty/11ty-website/blob/master/_data/sites/11ty.json

"source_url": "https://github.com/11ty/11ty-website",

Current stats:

11ty-website $ ls -lash _data/sites/*.json | wc -l #  174
11ty-website $ git grep "source_url" _data/sites/*.json | wc -l # 105

So currently 105 of 174 (60.34%) of the listed sites are public source.

The problem would be determining when the sites were added, and displaying only those added in the specified time period.

https://octokit.github.io/rest.js/v17#repos-get-contents might be useful jump off point. But we might be able to filter the files by date (if available) and then iterate over each file, read the contents and only return values that have a "source_url" property.

pdehaan commented 4 years ago
const lib = require("./utils/github-client");

main();

async function main() {
  const res = await lib.getContents("11ty", "11ty-website", "_data/sites");
  console.log(res);
}

This returns an array of files with the following objects:

  {
    name: 'kula-blog.json',
    path: '_data/sites/kula-blog.json',
    sha: 'd9eb368093804e3c4f7f898e009ca304bcf9ebec',
    size: 139,
    url: 'https://api.github.com/repos/11ty/11ty-website/contents/_data/sites/kula-blog.json?ref=master',
    html_url: 'https://github.com/11ty/11ty-website/blob/master/_data/sites/kula-blog.json',
    git_url: 'https://api.github.com/repos/11ty/11ty-website/git/blobs/d9eb368093804e3c4f7f898e009ca304bcf9ebec',
    download_url: 'https://raw.githubusercontent.com/11ty/11ty-website/master/_data/sites/kula-blog.json',
    type: 'file',
    _links: {
      self: 'https://api.github.com/repos/11ty/11ty-website/contents/_data/sites/kula-blog.json?ref=master',
      git: 'https://api.github.com/repos/11ty/11ty-website/git/blobs/d9eb368093804e3c4f7f898e009ca304bcf9ebec',
      html: 'https://github.com/11ty/11ty-website/blob/master/_data/sites/kula-blog.json'
    }
  },
  ... 74 more items
]

There doesn't seem to be any timestamps or anything in the response, so we'd still need to figure out how to calculate "freshness". Plus, we don't get file contents.

https://api.github.com/repos/11ty/11ty-website/git/blobs/d9eb368093804e3c4f7f898e009ca304bcf9ebec

This gives us a base64 encoded string of the file contents, which should be easy enough to decode (no doubt at the expense of API requests and inefficiency and still doesnt include timestamps).