1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-10-24 11:16:27 +02:00

feat: Cache github response

This commit is contained in:
Phuoc Nguyen
2022-09-22 11:00:21 +07:00
parent d25c54f261
commit 6f6500307f
7 changed files with 33 additions and 19 deletions

View File

@@ -1,11 +1,24 @@
const fetch = require('node-fetch');
const EleventyFetch = require("@11ty/eleventy-fetch")
async function fetchGitHubStars(repos) {
let json = await EleventyFetch(`https://api.github.com/repos/${repos}`, {
duration: '1d',
type: 'json'
});
return {
stargazers: json.stargazers_count,
};
}
module.exports = async function() {
return fetch('https://api.github.com/repos/phuocng/csslayout')
.then(res => res.json())
.then(json => {
return {
stargazers: json.stargazers_count
};
});
return {
'oneloc': await fetchGitHubStars('phuocng/1loc'),
'crossbrowser': await fetchGitHubStars('phuocng/cross-browser'),
'csslayout': await fetchGitHubStars('phuocng/csslayout'),
'frontendtips': await fetchGitHubStars('phuocng/frontend-tips'),
'htmldom': await fetchGitHubStars('phuocng/html-dom'),
'thisvsthat': await fetchGitHubStars('phuocng/this-vs-that'),
'reactpdfviewer': await fetchGitHubStars('react-pdf-viewer/react-pdf-viewer'),
};
};