Skip to content

Commit f7a3bad

Browse files
committed
feat: add disk cache for Hashnode and Ghost API responses
1 parent 16a3b40 commit f7a3bad

File tree

11 files changed

+400
-4
lines changed

11 files changed

+400
-4
lines changed

.github/workflows/deploy-eng.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Eng - Build and Deploy
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
bust_cache:
7+
description: 'Force fresh API fetch (bypass disk cache)'
8+
required: false
9+
type: boolean
10+
default: false
511
schedule:
612
# Here are the times for the cron:
713
#
@@ -28,6 +34,7 @@ jobs:
2834

2935
env:
3036
BUILD_LANG: ${{ matrix.languages }}
37+
BUST_CACHE: ${{ inputs.bust_cache }}
3138

3239
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
3340
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
@@ -71,8 +78,16 @@ jobs:
7178
- name: Install dependencies
7279
run: pnpm install --frozen-lockfile
7380

81+
- name: Restore Turbo cache
82+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
83+
with:
84+
path: node_modules/.cache/turbo
85+
key: turbo-${{ matrix.languages }}-${{ github.sha }}
86+
restore-keys: |
87+
turbo-${{ matrix.languages }}-
88+
7489
- name: Build site
75-
run: pnpm run build
90+
run: pnpm turbo run build
7691
env:
7792
NODE_ENV: production
7893

.github/workflows/deploy-i18n.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: i18n - Build and Deploy
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
bust_cache:
7+
description: 'Force fresh API fetch (bypass disk cache)'
8+
required: false
9+
type: boolean
10+
default: false
511
schedule:
612
# Here are the times for the cron:
713
#
@@ -29,6 +35,7 @@ jobs:
2935

3036
env:
3137
BUILD_LANG: ${{ matrix.languages }}
38+
BUST_CACHE: ${{ inputs.bust_cache }}
3239

3340
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
3441
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
@@ -88,8 +95,16 @@ jobs:
8895
- name: Install dependencies
8996
run: pnpm install --frozen-lockfile
9097

98+
- name: Restore Turbo cache
99+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
100+
with:
101+
path: node_modules/.cache/turbo
102+
key: turbo-${{ matrix.languages }}-${{ github.sha }}
103+
restore-keys: |
104+
turbo-${{ matrix.languages }}-
105+
91106
- name: Build site
92-
run: pnpm run build
107+
run: pnpm turbo run build
93108
env:
94109
NODE_ENV: production
95110

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ cypress/screenshots
8383
config/i18n/locales/**/trending.json
8484

8585
docker/languages/
86+
87+
# Turborepo
88+
.turbo

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
"cypress:run:espanol": "pnpm run cypress -- run --spec 'cypress/e2e/espanol/**/*'",
2626
"cypress:watch": "pnpm run cypress -- open",
2727
"dev": "pnpm run develop",
28+
"fetch:data": "node scripts/fetch-data.js",
2829
"predevelop": "pnpm run clean && node ./tools/download-trending.js",
2930
"develop": "cross-env ELEVENTY_ENV=dev NODE_OPTIONS=--max-old-space-size=8192 eleventy --serve",
3031
"predevelop:ci": "pnpm run clean && node ./tools/download-trending.js",
3132
"develop:ci": "cross-env ELEVENTY_ENV=ci NODE_OPTIONS=--max-old-space-size=8192 eleventy --serve",
32-
"prebuild": "pnpm run clean && node ./tools/download-trending.js",
33+
"prebuild": "pnpm run clean",
3334
"build": "cross-env ELEVENTY_ENV=prod NODE_OPTIONS=--max-old-space-size=8192 eleventy",
3435
"build:ci": "cross-env ELEVENTY_ENV=ci eleventy",
3536
"postbuild": "node ./config/i18n/generate-serve-config.js",
@@ -109,6 +110,7 @@
109110
"probe-image-size": "7.2.3",
110111
"shx": "0.4.0",
111112
"terser": "5.44.1",
113+
"turbo": "^2.8.14",
112114
"typescript": "5.9.3"
113115
},
114116
"pnpm": {

pnpm-lock.yaml

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/fetch-data.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { fetchFromHashnode } from '../utils/hashnode/fetch-from-hashnode.js';
2+
import { fetchFromGhost } from '../utils/ghost/fetch-from-ghost.js';
3+
4+
try {
5+
console.log('Downloading trending data...');
6+
await import('../tools/download-trending.js');
7+
console.log('Trending data downloaded.');
8+
9+
console.log('Fetching data from Hashnode and Ghost...');
10+
11+
const hashnodePosts = await fetchFromHashnode('posts');
12+
const hashnodePages = await fetchFromHashnode('pages');
13+
const ghostPosts = await fetchFromGhost('posts');
14+
const ghostPages = await fetchFromGhost('pages');
15+
16+
console.log(
17+
[
18+
'Fetch summary:',
19+
` Hashnode posts: ${hashnodePosts.length}`,
20+
` Hashnode pages: ${hashnodePages.length}`,
21+
` Ghost posts: ${ghostPosts.length}`,
22+
` Ghost pages: ${ghostPages.length}`
23+
].join('\n')
24+
);
25+
} catch (err) {
26+
console.error('fetch-data failed:', err);
27+
process.exit(1);
28+
}

0 commit comments

Comments
 (0)