Skip to content

Commit

Permalink
Add GDrive Preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
Khemarato Bhikkhu committed Jan 6, 2025
1 parent 3ac9b8c commit 8f18b8f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gem "jekyll-sass-converter", ">= 3.0", "< 4.0"
group :jekyll_plugins do
gem "jekyll-feed", github: 'buddhist-uni/jekyll-feed', branch: 'collection-tags'
gem "jekyll-sitemap", "~> 1.4.0"
gem "jekyll-seo-tag", github: "buddhist-uni/jekyll-seo-tag", ref: '5a9a962'
gem "jekyll-seo-tag", github: "buddhist-uni/jekyll-seo-tag", ref: 'ccdde88'
gem "jekyll-last-modified-at", github: "buddhist-uni/jekyll-last-modified-at", branch: 'post-date'
gem 'jekyll-include-cache'
end
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ GIT

GIT
remote: https://github.com/buddhist-uni/jekyll-seo-tag.git
revision: 5a9a962027516970a0983d3ed5b006d363504aa7
ref: 5a9a962
revision: ccdde8891a22676ee900d2e5963ba54aa26b186f
ref: ccdde88
specs:
jekyll-seo-tag (2.7.1)
jekyll (>= 3.8, < 5.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors:
- "Stephen A. Evans"
external_url: "https://journal.equinoxpub.com/BSR/article/view/8892"
drive_links:
- "https://drive.google.com/file/d/135c1u_bJGU453uYcyYv_jW8m3WiY7sRc/view?usp=drive_link"
- "https://drive.google.com/file/d/1IL2PUov4g1CKN5XPy4-HuvK8ootRnYYL/view?usp=sharing"
file_links:
- "smallpdfs/stephen-a-evans_2009_epistemology-of-the-brahmajala-sutta.pdf"
course: epistemology
Expand Down
7 changes: 6 additions & 1 deletion _layouts/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
<img src="https://buddhistuniversity.net/assets/imgs/covers/{{ page.olid }}.jpg" alt="the book cover">
{% elsif page.image %}
<img src="{{page.image}}">
{% endif %}
{%- elsif page.drive_links[0] -%}{%- if 'pdf,mp4' contains page.formats[0] -%}
{%- assign dlink = page.drive_links[0] | split: "/" -%}
{%- assign dlink = dlink[5] -%}
{%- if dlink.size == 28 or dlink.size == 33 or dlink.size == 44 -%}
<img src="https://drive.google.com/thumbnail?authuser=0&sz=h500&id={{ dlink }}">
{%- endif -%}{%- endif -%}{%- endif -%}
{% assign title = page.title | markdownify | remove: '<p>' | remove: '</p>' | split: ": " %}
<h1 class="post-title">{% if page.subcat %}{% include content_icon.html category=page.category subcat=page.subcat %} {% endif %}{{ title | first }}
{%- if title.size > 1 -%}<span style="color:transparent">: </span><div class="post-subtitle">{{ title | shift | join: ": " }}</div>{%- endif -%}</h1>
Expand Down
32 changes: 32 additions & 0 deletions scripts/ensure_drive_links_are_shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/python3

import gdrive
import website

website.load()

all_public_gids = []

for page in website.content:
if page.drive_links:
for glink in page.drive_links:
gid = gdrive.link_to_id(glink)
if gid:
all_public_gids.append(gid)

print(f"Fetching permissions info about {len(all_public_gids)} Google Drive files...")
all_files = gdrive.batch_get_files_by_id(all_public_gids, "id,name,permissions,ownedByMe")
print("Looking for those missing public permissions...")
for file in all_files:
if not file['ownedByMe']:
continue
is_publicly_shared = False
for permission in file['permissions']:
if permission['type'] == 'anyone':
is_publicly_shared = True
break
if not is_publicly_shared:
print(f"Sharing \"{file['name']}\" with everyone...")
gdrive.share_drive_file_with_everyone(file['id'])

print("Done!")
6 changes: 6 additions & 0 deletions scripts/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ def download_folder_contents_to(gdfid: str, target_directory: Path | str, recurs
follow_links=follow_links,
)

def share_drive_file_with_everyone(file_id: str):
return session().permissions().create(
fileId=file_id,
body={"role": "reader", "type": "anyone"},
).execute()

def batch_get_files_by_id(IDs: list, fields: str):
ret = []
if len(IDs) > 100:
Expand Down

0 comments on commit 8f18b8f

Please sign in to comment.