Skip to content

Commit 2513719

Browse files
committed
debugging
1 parent 17658ce commit 2513719

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

.github/scripts/fetch-cats.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const https = require('https');
22
const fs = require('fs');
33

44
const API_KEY = process.env.CAT_API_KEY;
5+
console.log('API Key exists:', !!API_KEY);
6+
57
const OUTPUT_FILE = '_data/cats.json';
68

79
const options = {
@@ -12,6 +14,8 @@ const options = {
1214
}
1315
};
1416

17+
console.log('Making request to:', `https://${options.hostname}${options.path}`);
18+
1519
https.get(options, (resp) => {
1620
let data = '';
1721

@@ -20,18 +24,22 @@ https.get(options, (resp) => {
2024
});
2125

2226
resp.on('end', () => {
27+
console.log('Response received:', data.substring(0, 100) + '...');
28+
2329
// Create directory if it doesn't exist
2430
const dir = '_data';
2531
if (!fs.existsSync(dir)){
2632
fs.mkdirSync(dir);
33+
console.log('Created _data directory');
2734
}
2835

2936
// Save the cat data
3037
fs.writeFileSync(OUTPUT_FILE, data);
31-
console.log('Cat data saved successfully!');
38+
console.log('Cat data saved to:', OUTPUT_FILE);
39+
console.log('File contents:', fs.readFileSync(OUTPUT_FILE, 'utf8').substring(0, 100) + '...');
3240
});
3341

3442
}).on("error", (err) => {
35-
console.error("Error: " + err.message);
43+
console.error("Error making request:", err.message);
3644
process.exit(1);
3745
});

.github/workflows/publish.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ jobs:
3232
run: |
3333
mkdir -p _data
3434
node .github/scripts/fetch-cats.js
35+
echo "Checking if cats.json exists:"
36+
ls -l _data/
37+
echo "Contents of cats.json:"
38+
cat _data/cats.json
3539
env:
3640
CAT_API_KEY: ${{ secrets.CAT_API_KEY }}
3741

3842
- name: Render Quarto Project
39-
run: quarto render
43+
run: |
44+
echo "Contents of _data before render:"
45+
ls -l _data/
46+
quarto render
47+
echo "Contents of _site after render:"
48+
ls -l _site/
4049
4150
- name: Deploy to GitHub Pages
4251
uses: peaceiris/actions-gh-pages@v3

chapters/endpoints.qmd

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,37 @@ With this result:
7878

7979
<script>
8080
document.addEventListener('DOMContentLoaded', async () => {
81-
// prefetch the cat data
82-
const cats = await cats;
83-
84-
const wrapper = document.querySelector('.carousel-wrapper');
85-
cats.forEach(cat => {
86-
const img = document.createElement('img');
87-
img.src = cat.url;
88-
img.alt = 'Cat image';
89-
wrapper.appendChild(img);
90-
});
91-
92-
let currentIndex = 0;
93-
const totalImages = cats.length;
94-
95-
function updateCarousel() {
96-
wrapper.style.transform = `translateX(-${currentIndex * 100}%)`;
81+
try {
82+
// Wait for OJS runtime to be ready and access the cats variable
83+
const cats = await window.ojs.runtime.interpret('cats');
84+
85+
const wrapper = document.querySelector('.carousel-wrapper');
86+
cats.forEach(cat => {
87+
const img = document.createElement('img');
88+
img.src = cat.url;
89+
img.alt = 'Cat image';
90+
wrapper.appendChild(img);
91+
});
92+
93+
let currentIndex = 0;
94+
const totalImages = cats.length;
95+
96+
function updateCarousel() {
97+
wrapper.style.transform = `translateX(-${currentIndex * 100}%)`;
98+
}
99+
100+
document.querySelector('.next').addEventListener('click', () => {
101+
currentIndex = (currentIndex + 1) % totalImages;
102+
updateCarousel();
103+
});
104+
105+
document.querySelector('.prev').addEventListener('click', () => {
106+
currentIndex = (currentIndex - 1 + totalImages) % totalImages;
107+
updateCarousel();
108+
});
109+
} catch (error) {
110+
console.error('Error loading cat data:', error);
97111
}
98-
99-
document.querySelector('.next').addEventListener('click', () => {
100-
currentIndex = (currentIndex + 1) % totalImages;
101-
updateCarousel();
102-
});
103-
104-
document.querySelector('.prev').addEventListener('click', () => {
105-
currentIndex = (currentIndex - 1 + totalImages) % totalImages;
106-
updateCarousel();
107-
});
108112
});
109113
</script>
110114

0 commit comments

Comments
 (0)