JanDW / wildpeaches

Mind-sized STEM ideas and experiments blog, beyond the textbook.
https://wildpeaches.xyz
0 stars 0 forks source link

Hero images #20

Open JanDW opened 4 years ago

JanDW commented 4 years ago

I'm experimenting with adding hero images to the blogposts.

I figured unsplash.com would be the best source of images, so I started thinking about integrating with it. I want to specify the image ID in the blog post's front matter. When Eleventy builds the site it should look up the image on unsplash API GET /photos/:id

Of course, the image will always be the same, so I don't want Eleventy to call the API for each and every build. To that end, I'm using @11ty/eleventy-cache-assets to cache the API calls.

JanDW commented 4 years ago

Paste of my bearnotes


Loading unsplash hero images

wildpeaches

Using environment variables

Environment variables on Netlify

Responsive images

Responsive images - Learn web development | MDN

API calls to unsplash

Public authentication

Pass the access key in a request header:

⚠️ access key should not be shared or put on website!

Authorization: Client-ID {public key}

Read more: Public Authentication. Access the public as well as the secret key at Unspash | wild peaches

Netlify Environment Variables: The Cheat Codes of the Internet ― Scotch.io

Getting a hero photo

Additional resources

URLSearchParams - Web APIs | MDN

JanDW commented 3 years ago

Deprioritizing for now. If proceeding create separate layout that can be swapped out in the front matter. Also allow for images other than unsplash.