Skip to content

Commit 8f18b8f

Browse files
committed
Add GDrive Preview images
1 parent 3ac9b8c commit 8f18b8f

6 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎Gemfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ gem "jekyll-sass-converter", ">= 3.0", "< 4.0"
2020
group :jekyll_plugins do
2121
gem "jekyll-feed", github: 'buddhist-uni/jekyll-feed', branch: 'collection-tags'
2222
gem "jekyll-sitemap", "~> 1.4.0"
23-
gem "jekyll-seo-tag", github: "buddhist-uni/jekyll-seo-tag", ref: '5a9a962'
23+
gem "jekyll-seo-tag", github: "buddhist-uni/jekyll-seo-tag", ref: 'ccdde88'
2424
gem "jekyll-last-modified-at", github: "buddhist-uni/jekyll-last-modified-at", branch: 'post-date'
2525
gem 'jekyll-include-cache'
2626
end

‎Gemfile.lock‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ GIT
1717

1818
GIT
1919
remote: https://github.com/buddhist-uni/jekyll-seo-tag.git
20-
revision: 5a9a962027516970a0983d3ed5b006d363504aa7
21-
ref: 5a9a962
20+
revision: ccdde8891a22676ee900d2e5963ba54aa26b186f
21+
ref: ccdde88
2222
specs:
2323
jekyll-seo-tag (2.7.1)
2424
jekyll (>= 3.8, < 5.0)

‎_content/articles/epistemology-of-the-brahmajala-sutta_stephen-a-evans.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors:
44
- "Stephen A. Evans"
55
external_url: "https://journal.equinoxpub.com/BSR/article/view/8892"
66
drive_links:
7-
- "https://drive.google.com/file/d/135c1u_bJGU453uYcyYv_jW8m3WiY7sRc/view?usp=drive_link"
7+
- "https://drive.google.com/file/d/1IL2PUov4g1CKN5XPy4-HuvK8ootRnYYL/view?usp=sharing"
88
file_links:
99
- "smallpdfs/stephen-a-evans_2009_epistemology-of-the-brahmajala-sutta.pdf"
1010
course: epistemology

‎_layouts/content.html‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
<img src="https://buddhistuniversity.net/assets/imgs/covers/{{ page.olid }}.jpg" alt="the book cover">
2828
{% elsif page.image %}
2929
<img src="{{page.image}}">
30-
{% endif %}
30+
{%- elsif page.drive_links[0] -%}{%- if 'pdf,mp4' contains page.formats[0] -%}
31+
{%- assign dlink = page.drive_links[0] | split: "/" -%}
32+
{%- assign dlink = dlink[5] -%}
33+
{%- if dlink.size == 28 or dlink.size == 33 or dlink.size == 44 -%}
34+
<img src="https://drive.google.com/thumbnail?authuser=0&sz=h500&id={{ dlink }}">
35+
{%- endif -%}{%- endif -%}{%- endif -%}
3136
{% assign title = page.title | markdownify | remove: '<p>' | remove: '</p>' | split: ": " %}
3237
<h1 class="post-title">{% if page.subcat %}{% include content_icon.html category=page.category subcat=page.subcat %} {% endif %}{{ title | first }}
3338
{%- if title.size > 1 -%}<span style="color:transparent">: </span><div class="post-subtitle">{{ title | shift | join: ": " }}</div>{%- endif -%}</h1>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/python3
2+
3+
import gdrive
4+
import website
5+
6+
website.load()
7+
8+
all_public_gids = []
9+
10+
for page in website.content:
11+
if page.drive_links:
12+
for glink in page.drive_links:
13+
gid = gdrive.link_to_id(glink)
14+
if gid:
15+
all_public_gids.append(gid)
16+
17+
print(f"Fetching permissions info about {len(all_public_gids)} Google Drive files...")
18+
all_files = gdrive.batch_get_files_by_id(all_public_gids, "id,name,permissions,ownedByMe")
19+
print("Looking for those missing public permissions...")
20+
for file in all_files:
21+
if not file['ownedByMe']:
22+
continue
23+
is_publicly_shared = False
24+
for permission in file['permissions']:
25+
if permission['type'] == 'anyone':
26+
is_publicly_shared = True
27+
break
28+
if not is_publicly_shared:
29+
print(f"Sharing \"{file['name']}\" with everyone...")
30+
gdrive.share_drive_file_with_everyone(file['id'])
31+
32+
print("Done!")

‎scripts/gdrive.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ def download_folder_contents_to(gdfid: str, target_directory: Path | str, recurs
490490
follow_links=follow_links,
491491
)
492492

493+
def share_drive_file_with_everyone(file_id: str):
494+
return session().permissions().create(
495+
fileId=file_id,
496+
body={"role": "reader", "type": "anyone"},
497+
).execute()
498+
493499
def batch_get_files_by_id(IDs: list, fields: str):
494500
ret = []
495501
if len(IDs) > 100:

0 commit comments

Comments
 (0)