This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const paginationHandler = (page) => { | |
const currentPath = props.router.pathname; | |
const currentQuery = props.router.query; | |
currentQuery.page = page.selected + 1; | |
props.router.push({ | |
pathname: currentPath, | |
query: currentQuery, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wordsPerMinute = 225 | |
export function readingTime(text) { | |
return Math.ceil(wordCounter(text) / wordsPerMinute) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wordCounter(input) { | |
const text = input.split(/\s+/) | |
let wordCount = 0 | |
for (let i = 0; i < text.length; i++) { | |
if (text[i] !== ' ' && isWord(text[i])) { | |
wordCount++ | |
} | |
} | |
return wordCount | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getData(key){ | |
return new Promise(function(resolve, reject) { | |
console.log('starting get ' + key) | |
setTimeout(() => { | |
console.log('ending get ' + key) | |
resolve(key); | |
}, 1000); | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _cacheValues = new Map(); | |
const _cacheResolvedTime = new Map(); | |
const _cachePromises = new Map(); | |
const getDataCached = function (key) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (_cacheValues.has(key)) { | |
return Promise.resolve(_cacheValues.get(key)); | |
} else if (_cachePromises.has(key)) { | |
return _cachePromises.get(key); | |
} else { | |
const promise = new Promise(function (resolve, reject) { | |
return getData(key).then(data => { | |
_cacheValues.set(key, data); | |
_cachePromises.delete(key); | |
const now = new Date().getTime(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const now = new Date().getTime(); | |
if (_cacheResolvedTime.has(key)) { | |
if ((now - _cacheResolvedTime.get(key)) > 60000) { | |
_cacheResolvedTime.delete(param); | |
_cacheValues.delete(key); | |
_cachePromises.delete(key); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getDataCached('a').then(result => { console.log('first call outer: ' + result); | |
getDataCached('a').then(result => { console.log('first call inner: ' + result); }); | |
}); | |
getDataCached('b').then(result => { console.log('first call outer: ' + result); | |
getDataCached('b').then(result => { console.log('first call inner: ' + result); }); | |
}); | |
getDataCached('a').then(result => { console.log('second call outer: ' + result); | |
getDataCached('a').then(result => { console.log('second call inner: ' + result); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { TwitterClient } = require('twitter-api-client') | |
const axios = require('axios') | |
const sharp = require('sharp') | |
const Feed = require('rss-to-json') | |
const Jimp = require('jimp') | |
const fs = require('fs') | |
const numberOfFollowers = 3 | |
const widthHeightFollowerImage = 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"generate": "run-func netlify/functions/header.js handler" | |
}, | |
"dependencies": { | |
"axios": "^0.24.0", | |
"jimp": "^0.16.1", | |
"rss-to-json": "^2.0.2", | |
"run-func": "^1.0.5", | |
"sharp": "^0.29.3", |