Download images with unsplash
This commit is contained in:
parent
ce7bb446d6
commit
34acb96ec1
3 changed files with 21 additions and 0 deletions
|
@ -4,3 +4,7 @@ redirects:
|
|||
---
|
||||
|
||||
# Sibling
|
||||
|
||||
{% set this_image = unsplash("MU8w72PzRow") %}
|
||||
|
||||
![{{ this_image.description|default("", true) }}]({{ this_image.urls.regular }})
|
||||
|
|
16
hooks/unsplash.py
Normal file
16
hooks/unsplash.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from mkdocs.utils.cache import download_and_cache_url
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import json
|
||||
import jinja2
|
||||
|
||||
UNSPLASH_CACHE_TIME = timedelta(days=14)
|
||||
|
||||
def get_unsplash_image(image_id):
|
||||
client_id = os.environ["UNSPLASH_CLIENT_ID"]
|
||||
url = f"https://api.unsplash.com/photos/{image_id}?client_id={client_id}"
|
||||
return json.loads(download_and_cache_url(url, UNSPLASH_CACHE_TIME))
|
||||
|
||||
def on_env(env: jinja2.Environment, config, files):
|
||||
env.globals["unsplash"] = get_unsplash_image
|
||||
return env
|
|
@ -19,6 +19,7 @@ hooks:
|
|||
- hooks/pygments-styles.py
|
||||
- hooks/kroki.py
|
||||
- hooks/include-file.py
|
||||
- hooks/unsplash.py
|
||||
|
||||
markdown_extensions:
|
||||
- attr_list
|
||||
|
|
Loading…
Reference in a new issue