Skip to content

Commit 085c762

Browse files
feat: attempt to add Unsplash stats
1 parent e297dca commit 085c762

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

.github/workflows/astro.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858
node-version: "18"
5959
cache: ${{ steps.detect-package-manager.outputs.manager }}
6060
cache-dependency-path: ${{ env.BUILD_PATH }}/package-lock.json
61+
- name: Create .env file
62+
run: echo "UNSPLASH_ACCESS_KEY=${{ secrets.UNSPLASH_ACCESS_KEY }}" > .env
6163
- name: Setup Pages
6264
id: pages
6365
uses: actions/configure-pages@v5

src/layouts/LabsLayout.astro

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ const { frontmatter } = Astro.props;
5555
</div>
5656
</a>
5757
</section>
58-
<section class="prose max-w-6xl prose-img:border-0">
59-
<br>
58+
<section id="cards" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 mt-10">
59+
<div class="card-content card border-skin-line">
60+
<div id="unsplash-stats">
61+
<h2 class="text-lg text-skin-accent font-medium">My Unsplash Stats</h2>
62+
<p id="downloads">Downloads: </p>
63+
<p id="views">Views: </p>
64+
<p id="likes">Likes: </p>
65+
</div>
66+
</div>
6067
</section>
68+
<br>
6169
<section >
6270
<div style="display: flex; justify-content: center; max-width: 100%;">
6371
<iframe width="100%" height="337" seamless frameborder="0" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vTu8BIkLoeldqgLyVgPxmw-9fmOMu76TNv04y2OsG708ABJIJ7HLaZc234kmHDLz_g3zhjMNY3TKVqa/pubchart?oid=2021333611&amp;format=interactive"></iframe>
@@ -109,4 +117,32 @@ const { frontmatter } = Astro.props;
109117
--tw-text-opacity: 1;
110118
color: rgba(var(--color-accent), var(--tw-text-opacity));
111119
}
112-
</style>
120+
</style>
121+
122+
<script>
123+
const username = 'william_vdg';
124+
require('dotenv').config();
125+
const accessKey = process.env.UNSPLASH_ACCESS_KEY;
126+
127+
fetch(`https://api.unsplash.com/users/${username}/statistics`, {
128+
headers: {
129+
'Authorization': `Client-ID ${accessKey}`
130+
}
131+
})
132+
.then(response => response.json())
133+
.then(data => {
134+
const downloads = data.downloads?.total || 0;
135+
const views = data.views?.total || 0;
136+
const likes = data.likes?.total || 0;
137+
138+
document.getElementById('downloads').textContent = `Downloads: ${downloads}`;
139+
document.getElementById('views').textContent = `Views: ${views}`;
140+
document.getElementById('likes').textContent = `Likes: ${likes}`;
141+
})
142+
.catch(error => console.error('Error fetching user stats:', error));
143+
144+
</script>
145+
<script>
146+
147+
148+
</script>

0 commit comments

Comments
 (0)