Skip to content

Commit 0e30e73

Browse files
committed
Make caching customizable
1 parent 9d23289 commit 0e30e73

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
2-
cache
2+
cache*
33
static/index.html

generate.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import ejs from 'ejs';
66
import { Event, Post } from './types';
77

88

9-
const cacheOrFetch = (url: string, slug: string): Promise<string> => {
10-
const cachePath = path.join('cache', slug);
11-
if (false && fs.existsSync(cachePath)) return fs.promises.readFile(cachePath).then(b => b.toString())
9+
const cacheOrFetch = (url: string, slug: string, cache: boolean): Promise<string> => {
10+
const cachePath = path.join('cache.' + slug);
11+
if (cache && fs.existsSync(cachePath)) return fs.promises.readFile(cachePath).then(b => b.toString())
1212
return fetch(url)
1313
.then(r => r.text())
1414
.then(t => fs.promises.writeFile(cachePath, t).then(() => t))
@@ -55,7 +55,7 @@ const monthAndDay = (date: Date) => {
5555
return date.toLocaleString('default', { month: 'short' }) + ' ' + date.getDate()
5656
}
5757

58-
cacheOrFetch('https://techcrunch.com/', 'index.html').then(html => {
58+
cacheOrFetch('https://techcrunch.com/', 'index.html', process.env.NODE_ENV !== 'production').then(html => {
5959
const dom = new JSDOM(html, { url: 'https://techcrunch.com/' });
6060
const data = JSON.parse(dom.window.document.querySelector('script#tc-app-js-extra')!.textContent!.split(' = ').slice(1).join(' = ').trim().slice(0, -1));
6161
const featured = data.feature_islands.homepage.map(parsePost);

0 commit comments

Comments
 (0)