From 8f18b8f7cec4a6e64457f5ecc0e044162076820c Mon Sep 17 00:00:00 2001 From: Khemarato Bhikkhu Date: Mon, 6 Jan 2025 21:11:41 +0700 Subject: [PATCH] Add GDrive Preview images --- Gemfile | 2 +- Gemfile.lock | 4 +-- ...of-the-brahmajala-sutta_stephen-a-evans.md | 2 +- _layouts/content.html | 7 +++- scripts/ensure_drive_links_are_shared.py | 32 +++++++++++++++++++ scripts/gdrive.py | 6 ++++ 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 scripts/ensure_drive_links_are_shared.py diff --git a/Gemfile b/Gemfile index 8272044acf..6530c81e21 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index febf46a555..68db6db679 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/_content/articles/epistemology-of-the-brahmajala-sutta_stephen-a-evans.md b/_content/articles/epistemology-of-the-brahmajala-sutta_stephen-a-evans.md index 4dbe174640..4f982cb13e 100644 --- a/_content/articles/epistemology-of-the-brahmajala-sutta_stephen-a-evans.md +++ b/_content/articles/epistemology-of-the-brahmajala-sutta_stephen-a-evans.md @@ -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 diff --git a/_layouts/content.html b/_layouts/content.html index 306e7094e8..74891cce41 100644 --- a/_layouts/content.html +++ b/_layouts/content.html @@ -27,7 +27,12 @@ the book cover {% elsif 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 -%} + + {%- endif -%}{%- endif -%}{%- endif -%} {% assign title = page.title | markdownify | remove: '

' | remove: '

' | split: ": " %}

{% if page.subcat %}{% include content_icon.html category=page.category subcat=page.subcat %} {% endif %}{{ title | first }} {%- if title.size > 1 -%}:
{{ title | shift | join: ": " }}
{%- endif -%}

diff --git a/scripts/ensure_drive_links_are_shared.py b/scripts/ensure_drive_links_are_shared.py new file mode 100644 index 0000000000..3e69795007 --- /dev/null +++ b/scripts/ensure_drive_links_are_shared.py @@ -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!") \ No newline at end of file diff --git a/scripts/gdrive.py b/scripts/gdrive.py index b9564fbd65..8fa6056a81 100644 --- a/scripts/gdrive.py +++ b/scripts/gdrive.py @@ -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: