Skip to content

Commit 24cf071

Browse files
committed
Use cached covers
1 parent 7f33989 commit 24cf071

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎.github/workflows/links.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
uses: lycheeverse/lychee-action@v1.9.0
3737
with:
3838
lycheeVersion: '0.12.0'
39-
args: --user-agent "${{ env.USER_AGENT }}" --base=https://buddhistuniversity.net --exclude-link-local --timeout=30 --retry-wait-time=3 --max-redirects=8 --exclude=researchgate.net --exclude=illeakyw.sirv.com --exclude=googleapis.com --exclude=google.com --exclude=apple.com --exclude=accesstoinsight.org --exclude=suttacentral.net --exclude=dhammawheel.com --exclude=doi.org --exclude=archive.org --exclude=github.com --exclude=openlibrary.org --exclude=google-analytics.com --exclude=worldcat.org --exclude=ssrn.com --exclude=schema.org --exclude=substack.com --exclude=science.org --exclude=pnas.org --exclude=tandfonline.com --exclude=archive.is --exclude=wiley.com --exclude=gstatic.com --exclude-mail --verbose --no-progress --cache --exclude-path=prod/content 'prod/**/*.html' 'main/_content/*/*.txt' prod/site.webmanifest prod/browserconfig.xml
39+
args: --user-agent "${{ env.USER_AGENT }}" --base=https://buddhistuniversity.net --exclude-link-local --timeout=30 --retry-wait-time=3 --max-redirects=8 --exclude=researchgate.net --exclude=illeakyw.sirv.com --exclude=googleapis.com --exclude=google.com --exclude=apple.com --exclude=accesstoinsight.org --exclude=suttacentral.net --exclude=dhammawheel.com --exclude=doi.org --exclude=archive.org --exclude=github.com --exclude=google-analytics.com --exclude=worldcat.org --exclude=ssrn.com --exclude=schema.org --exclude=substack.com --exclude=science.org --exclude=pnas.org --exclude=tandfonline.com --exclude=archive.is --exclude=wiley.com --exclude=gstatic.com --exclude-mail --verbose --no-progress --cache --exclude-path=prod/content 'prod/**/*.html' 'main/_content/*/*.txt' prod/site.webmanifest prod/browserconfig.xml
4040
- name: Create GitHub Issue
4141
uses: peter-evans/create-issue-from-file@v4
4242
with:

‎_content/monographs/walking-the-noble-path_tnh.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: "Walking the Noble Path"
33
authors: [tnh]
44
year: 2012
5+
olid: OL51559150M
56
publisher: parallax
67
tags:
78
- ethics

‎_includes/featured_content_list.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="featured_content_list"><ul>
77
{% for c in sorted %}
88
<li class="featured_content_list_item">
9-
{% if c.olid %}<div class="ol-cover"><a href="{{ c.url }}">{{ c.title | markdownify | strip_html }}<img src="https://covers.openlibrary.org/b/olid/{{ c.olid }}-L.jpg" alt="{{ c.title }}"></a></div>{% else %}
9+
{% if c.olid %}<div class="ol-cover"><a href="{{ c.url }}">{{ c.title | markdownify | strip_html }}<img src="https://buddhistuniversity.net/assets/imgs/covers/{{ c.olid }}.jpg" alt="{{ c.title }}"></a></div>{% else %}
1010
<div class="content_title">{% capture foo %}{% include simple_content_title.html content=c %}{% endcapture %}{{ foo | strip_newlines }}</div>{% endif %}
1111
<div class="star_label">{% unless c.stars == 3 %}<span class="RatingLabel-{{ c.stars }}">{% include starlabel.html stars=c.stars %}</span>{% endunless %}</div>
1212
{% unless c.olid %}{% assign supex = false %}{% if c.external_url contains 'youtu' %}{% unless c.external_url contains "list" %}

‎_layouts/content.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<script>window.topic_category="{{ page.course | default: 'archive' }}";</script>
2525
<div class="back"><a href="/content/">Content</a> / <a href="/content/{{ page.category }}/">{{ category.title }}</a> /</div>
2626
{% if page.olid %}
27-
<img src="https://covers.openlibrary.org/b/olid/{{ page.olid }}-L.jpg?default=false" alt="the book cover">
27+
<img src="https://buddhistuniversity.net/assets/imgs/covers/{{ page.olid }}.jpg" alt="the book cover">
2828
{% endif %}
2929
{% assign title = page.title | markdownify | remove: '<p>' | remove: '</p>' | split: ": " %}
3030
<h1 class="post-title">{% if page.subcat %}{% include content_icon.html category=page.category subcat=page.subcat %} {% endif %}{{ title | first }}

‎scripts/dl-book-covers.py‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,27 @@
1111
BOOKCOVER_DIR.mkdir()
1212

1313
def download_cover(olid):
14-
response = requests.get(f"https://covers.openlibrary.org/b/olid/{olid}-L.jpg?default=false")
15-
assert response.status_code == 200
16-
with open(BOOKCOVER_DIR.joinpath(f"{olid}.jpg"), "wb") as f:
17-
f.write(response.content)
14+
retries = 0
15+
while retries < 4:
16+
if retries > 0:
17+
print(" Retrying...")
18+
try:
19+
response = requests.get(
20+
f"https://covers.openlibrary.org/b/olid/{olid}-L.jpg?default=false",
21+
timeout=15,
22+
allow_redirects=True,
23+
)
24+
if response.status_code == 200 and response.content:
25+
with open(BOOKCOVER_DIR.joinpath(f"{olid}.jpg"), "wb") as f:
26+
f.write(response.content)
27+
return True
28+
else:
29+
print(f" Failed to download with status {response.status_code}")
30+
except requests.exceptions.RequestException as e:
31+
print(f" Failed to download with error {e}")
32+
retries += 1
33+
raise RuntimeError(f"Failed to download {olid} 4 times")
34+
1835

1936
website.load()
2037
for page in website.content:

0 commit comments

Comments
 (0)