github.js 499 B

1234567891011121314151617181920212223
  1. let url = require('url');
  2. let axios = require('axios');
  3. module.exports = {
  4. matches (url) {
  5. return url.match(/^https?:\/\/(www\.)?github\.com\/.+\/.+/);
  6. },
  7. async getPreviewData (link_url) {
  8. try {
  9. let pathname = url.parse(link_url).pathname;
  10. let res = await axios.get('https://api.github.com/repos' + pathname);
  11. return {
  12. title: res.data.full_name,
  13. url: res.data.html_url,
  14. description: res.data.description
  15. };
  16. } catch (e) {
  17. console.log(e)
  18. return null;
  19. }
  20. }
  21. };