File tree 2 files changed +5
-5
lines changed
2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
- cache
2
+ cache *
3
3
static /index.html
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import ejs from 'ejs';
6
6
import { Event , Post } from './types' ;
7
7
8
8
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 ( ) )
12
12
return fetch ( url )
13
13
. then ( r => r . text ( ) )
14
14
. then ( t => fs . promises . writeFile ( cachePath , t ) . then ( ( ) => t ) )
@@ -55,7 +55,7 @@ const monthAndDay = (date: Date) => {
55
55
return date . toLocaleString ( 'default' , { month : 'short' } ) + ' ' + date . getDate ( )
56
56
}
57
57
58
- cacheOrFetch ( 'https://techcrunch.com/' , 'index.html' ) . then ( html => {
58
+ cacheOrFetch ( 'https://techcrunch.com/' , 'index.html' , process . env . NODE_ENV !== 'production' ) . then ( html => {
59
59
const dom = new JSDOM ( html , { url : 'https://techcrunch.com/' } ) ;
60
60
const data = JSON . parse ( dom . window . document . querySelector ( 'script#tc-app-js-extra' ) ! . textContent ! . split ( ' = ' ) . slice ( 1 ) . join ( ' = ' ) . trim ( ) . slice ( 0 , - 1 ) ) ;
61
61
const featured = data . feature_islands . homepage . map ( parsePost ) ;
You can’t perform that action at this time.
0 commit comments