Skip to content

Commit

Permalink
Better journal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Khemarato Bhikkhu committed Nov 21, 2023
1 parent 4febaf0 commit 0737b0f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ external_url: "https://www.academia.edu/39327120/_Narratives_of_Buddhist_Relics_
source_url: "https://doi.org/10.1093/acrefore/9780199340378.013.587"
year: 2019
month: may
journal: "Oxford Research Encyclopedia of Religion"
journal: orer
publisher: oxford
course: form
tags:
Expand Down
7 changes: 4 additions & 3 deletions _includes/content.bibtex.liquid
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{%- if include.content.from_book -%}{%- assign book = site.content | where: "slug", include.content.from_book | where: "category", "monographs" | first -%}{%- else -%}{%- assign book = nil -%}{%- endif -%}
{%- assign series = site.series | find: "slug", include.content.series -%}
{%- assign publisher = include.content.publisher | default: book.publisher | default: series.publisher -%}{%- assign publisher = site.publishers | find: "slug", publisher | default: publisher -%}
{%- assign journal = site.journals | find: "slug", include.content.journal -%}
{%- assign publisher = include.content.publisher | default: book.publisher | default: series.publisher | default: journal.publisher -%}{%- assign publisher = site.publishers | find: "slug", publisher | default: publisher -%}
{%- assign author = nil -%}
{%- assign curlyspace = "} " -%}
{%- assign curly = "}" -%}
Expand All @@ -17,10 +18,10 @@
{% endif %}{% if include.content.editor %} editor={% assign editors = include.content.editor | split: " and " %}{% if include.useslugs %}{% for t in editors %}{% if t contains " " %}"{{ t }}"{% else %}{{ t }}{% endif %}{% unless forloop.last %} # " and " # {% endunless %}{% endfor %}{% else %}{% raw %}{{% endraw %}{% capture t %}{% include_cached content_authors_string.html authors=editors %}{% endcapture %}{{ t | strip | replace: ", and ", " and " | replace: ", ", " and " }}}{% endif %},
{% endif %}{% if include.content.publisher or publisher %} publisher={% raw %}{{% endraw %}{% if publisher %}{{ publisher.title | default: publisher | replace: "&", escand }}{% else %}{{ include.content.publisher | replace: "&", escand }}{% endif %}},
{% endif %}{% if include.content.school %} school={% raw %}{{% endraw %}{{ include.content.school }}},
{% endif %}{% if include.content.address or publisher.address %} address={% raw %}{{% endraw %}{{ include.content.address | default: publisher.address }}},
{% endif %}{% if include.content.address or publisher.address or journal.address %} address={% raw %}{{% endraw %}{{ include.content.address | default: journal.address | default: publisher.address }}},
{% endif %}{% if include.content.year %} year={{ include.content.year }},
{% endif %}{% if include.content.month %} month={{ include.content.month }},
{% endif %}{% if include.content.journal %} journal={% raw %}{{% endraw %}{% assign journal = site.journals | find: "slug", include.content.journal %}{% if journal %}{{ journal.title | replace: "&", escand }}{% else %}{{ include.content.journal | replace: "&", escand }}{% endif %}},
{% endif %}{% if include.content.journal %} journal={% raw %}{{% endraw %}{% if journal %}{{ journal.title | replace: "&", escand }}{% else %}{{ include.content.journal | replace: "&", escand }}{% endif %}},
{% endif %}{% if include.content.volume %} volume={{ include.content.volume }},
{% endif %}{% if include.content.series %} series={% raw %}{{% endraw %}{% if series %}{{ series.title }}{% else %}{{ include.content.series }}{% endif %}},
{% endif %}{% if include.content.number %} number={{ include.content.number }},
Expand Down
1 change: 1 addition & 0 deletions _journals/daedalus.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "Dædalus"
external_url: "https://direct.mit.edu/daed"
publisher: mit
---

An interdisciplinary journal published by [MIT](/publishers/mit) on behalf of the [American Academy of Arts and Sciences](https://www.amacad.org/), each quarterly issue invites a number of prominent writers addressing a particular theme.
Expand Down
2 changes: 1 addition & 1 deletion _journals/pnas.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "The Proceedings of the National Academy of Sciences"
publisher: "The National Academy of Sciences of the United States of America"
publisher: nap
address: "Washington D.C."
external_url: "https://www.pnas.org/"
openalexid: S125754415
Expand Down
4 changes: 2 additions & 2 deletions _layouts/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2 class="author">Read by {% if reader %}<a href="{{ reader.url }}">{{ reader.t
{%- endif -%}
{% if page.series %}{% assign series = site.series | find: "slug", page.series %}{% else %}{% assign series = nil %}{% endif %}
{% if page.journal %}{% assign journal = site.journals | find: "slug", page.journal %}{% endif %}
{% if page.publisher or series %}{% assign publisher = page.publisher | default: series.publisher %}{% assign publisher = site.publishers | find: "slug", publisher | default: publisher %}{% else %}{% assign publisher = nil %}{% endif %}
{% if page.publisher or series or journal %}{% assign publisher = page.publisher | default: series.publisher | default: journal.publisher %}{% assign publisher = site.publishers | find: "slug", publisher | default: publisher %}{% else %}{% assign publisher = nil %}{% endif %}

{% if tags.size > 0 %}<p class="star_desc">
About: {{ tags }}
Expand All @@ -90,7 +90,7 @@ <h2 class="author">Read by {% if reader %}<a href="{{ reader.url }}">{{ reader.t
{% endif %}
<p class="pub_desc"><i>
{%- if page.translator -%}Translated by {% assign translators = page.translator | split: " and " %}{% include_cached content_authors_string.html authors=translators link=true %}.{% endif %}
{% if page.year or publisher or booktitle or page.journal or page.series %}Published{% if page.year %} in {{ page.year }}{% endif %}{% if page.journal %} in {% if journal %}<a href="{{ journal.url }}">{{ journal.title }}</a>{% else %}{{ page.journal }}{% endif %}{% endif %}{% if booktitle %} in “{{ booktitle }}”{% endif %}{% if page.editor %} ({% assign editors = page.editor | split: " and " %}{% include_cached content_authors_string.html authors=editors link=true %} ed.){% endif %}{% if publisher %} by {% if publisher.title %}<a href="{{ publisher.url }}">{{ publisher.title }}</a>{% else %}{{ publisher }}{% endif %}{% if page.address or publisher.address or series.address %}, {{ page.address | default: series.address | default: publisher.address }}{% endif %}{% endif %}{% if page.series %} {% if page.number %}as{% else %}in{% endif %} {% if series %}<a href="{{ series.url }}">{{ series.title }}</a>{% else %}"{{ page.series }}"{% endif %}{% if page.number %} number {{ page.number }}{% endif %}{% endif %}.{% endif %}
{% if page.year or publisher or booktitle or page.journal or page.series %}Published{% if page.year %} in {{ page.year }}{% endif %}{% if page.journal %} in {% if journal %}<a href="{{ journal.url }}">{{ journal.title }}</a>{% else %}{{ page.journal }}{% endif %}{% endif %}{% if booktitle %} in “{{ booktitle }}”{% endif %}{% if page.editor %} ({% assign editors = page.editor | split: " and " %}{% include_cached content_authors_string.html authors=editors link=true %} ed.){% endif %}{% if publisher %} by {% if publisher.title %}<a href="{{ publisher.url }}">{{ publisher.title }}</a>{% else %}{{ publisher }}{% endif %}{% if page.address or publisher.address or series.address %}, {{ page.address | default: series.address | default: journal.address | default: publisher.address }}{% endif %}{% endif %}{% if page.series %} {% if page.number %}as{% else %}in{% endif %} {% if series %}<a href="{{ series.url }}">{{ series.title }}</a>{% else %}"{{ page.series }}"{% endif %}{% if page.number %} number {{ page.number }}{% endif %}{% endif %}.{% endif %}

</i></p>

Expand Down
9 changes: 8 additions & 1 deletion _layouts/publisher.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ <h3><a target="_blank" href="{{ page.external_url }}">Online here</a></h3>
<div class="post-content">
{{ content }}

{% assign journals = site.journals | where: "publisher", page.slug %}
{% assign journalslugs = journals | map: "slug" %}
{% if journals.size > 0 %}<h4>Featured Journals</h4>
{% for journal in journals %}
<div><i class="far fa-newspaper"></i> <a href="{{ journal.url }}">{{ journal.title }}</a></div>
{% endfor %}
{% endif %}
{% assign series = site.series | where: "publisher", page.slug %}
{% assign seriesslugs = series | map: "slug" %}
{% if series.size > 0 %}<h4>Featured Series</h4>
{% include content_list.html contents=series keep_rejects="true" %}
{% endif %}
{% assign allworks = site.content | where: "publisher", page.slug %}
{% assign filtered = '' | split: '' %}
{% for c in allworks %}{% unless seriesslugs contains c.series %}{% assign filtered = filtered | push: c %}{% endunless %}{% endfor %}
{% for c in allworks %}{% unless seriesslugs contains c.series or journalslugs contains c.journal %}{% assign filtered = filtered | push: c %}{% endunless %}{% endfor %}
{% if filtered.size > 0 %}<h4>Featured Publications:</h4>
{% include content_list.html contents=filtered keep_rejects="true" %}
{% endif %}
Expand Down
9 changes: 9 additions & 0 deletions _tests/bibtex.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ Bibtex pulls the address from the publisher: {% if bib contains "address={" %}Pa

Test is valid (piece has doi source): {% if testc.source_url contains "doi.org" %}Pass ✅{% else %}FAIL ❌{% endif %}
Bibtex pulls doi from source: {% if bib contains "doi={" %}Pass ✅{% else %}FAIL ❌{% endif %}

{% assign testc = site.content | find: "url", "/content/articles/notes-on-visuddhimagga-9_gombrich" %}
```
{% capture bib %}{% include content.bibtex.liquid content=testc %}{% endcapture %}{{ bib }}
```

Test is valid (piece has journal but no publisher or address): {% if testc.address or testc.publisher %}FAIL ❌{% else %}{% if testc.journal == 'jpts' %}Pass ✅{% else %}FAIL ❌{% endif %}{% endif %}
Bibtex pulls publisher from the journal: {% if bib contains "publisher=" %}Pass ✅{% else %}FAIL ❌{% endif %}
Bibtex pulls address from the publisher: {% if bib contains "address=" %}Pass ✅{% else %}FAIL ❌{% endif %}
1 change: 1 addition & 0 deletions _tests/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A series of tests checking the integrity of the _content data
| Unlinked Authors | {% assign authors = site.authors | map: "title" %}{% assign dupes = '' | split: '' %}{% for cont in site.content %}{% for auth in cont.authors %}{% if authors contains auth %}{% assign dupes = dupes | push: cont %}{% break %}{% endif %}{% endfor %}{% endfor %}{% if dupes.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | Found {{ dupes.size }} works with unlinked authors{% if dupes.size > 0 %}: {{ dupes | map: "url" | array_to_sentence_string }}{% endif %}
| Dangling Authors | {% assign authors = site.authors | map: "slug" %}{% for auth in found %}{% assign authors = authors | where_exp: "a", "a != auth" %}{% endfor %}{% assign unfound = '' | split: '' %}{% for auth in authors %}{% assign c = site.content | where: "translator", auth | size %}{% if c > 0 %}{% continue %}{% endif %}{% assign c = site.content | where: "editor", auth | size %}{% if c > 0 %}{% continue %}{% endif %}{% assign c = site.content | where: "reader", auth | size %}{% if c == 0 %}{% assign unfound = unfound | push: auth %}{% endif %}{% endfor %}{% if unfound.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | There are {{ unfound.size }} authors with no works attributed to them{% if unfound.size == 0 %}.{% else %}: {{ unfound | array_to_sentence_string }}.{% endif %}
| Content unexpectedly missing links | {% assign failures = site.content | where_exp: "c", "c.external_url == nil" | where_exp: "c", "c.drive_links == nil" | where_exp: "c", "c.source_url == nil" | where_exp: "c", "c.file_links == nil" | where_exp: "c", "c.category != 'monographs'" | where_exp: "c", "c.status != 'rejected'" | where_exp: "c", "c.slug != 'historical-dictionary-of-chan_wang-youru'" | where_exp: "c", "c.subcat != 'film'" %}{% if failures.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | There are {{ failures.size }} missing links{% if failures.size >0 %}: {{ failures | map: "slug" | array_to_sentence_string }}{% endif %}.
| Films have video files | {% assign failures = site.content | where: "subcat", "film" | where_exp: "c", "c.drive_links[0]" | where: "formats[0]", "mp3" %}{% if failures.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | There are {{ failures.size }} films with mp3s{% if failures.size > 0 %}: {{ failures | map: "slug" | array_to_sentence_string }}{% endif %}.
| https error | {% assign ec = site.content | where_exp: "c", "c.external_url contains 'http://'" %}{% assign ed = "" | split: "" %}{% for c in ec %}{% unless c.external_url contains "https://" %}{% assign ed = ed | push: c %}{% endunless %}{% endfor %}{% assign failures = ed | where_exp: "c", "c.external_url contains '.pdf'" %}{% assign ec = ed | where_exp: "c", "c.external_url contains '/article/download/'" %}{% assign failures = failures | concat: ec %}{% if failures.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | There are {{ failures.size }} links that need to be https{% if failures.size >0 %}: {{ failures | map: "slug" | array_to_sentence_string }}{% endif %}.
| Content missing year | {% assign failures = site.content | where_exp: "c", "c.year == nil" %}{% if failures.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | There are {{ failures.size }} missing years{% if failures.size >0 %}: {{ failures | map: "slug" | array_to_sentence_string }}{% endif %}.
| Invalid months | {% assign failures = "" | split: "" %}{% for cont in site.content %}{% if cont.month %}{% unless site.data.bibtex.months contains cont.month %}{% assign failures = failures | push: cont.path %}{% endunless %}{% endif %}{% endfor %}{% if failures.size == 0 %}Pass ✅{% else %}FAIL ❌{% endif %} | {{ failures.size }} bad months found{% if failures.size >0 %}: {{ failures | array_to_sentence_string }}{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions scripts/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
DOC_LINK = 'https://docs.google.com/document/d/{}/edit?usp=drivesdk'

def link_to_id(link):
ret = re.search(r'/d/([a-zA-Z0-9_-]{33}|[a-zA-Z0-9_-]{44})/?(edit|view)?(\?usp=)?(sharing|drivesdk)?$', link)
ret = re.search(r'/d/([a-zA-Z0-9_-]{33}|[a-zA-Z0-9_-]{44})/?(edit|view)?(\?usp=)?(sharing|drivesdk|drive_link)?$', link)
return ret.groups()[0] if ret else None

def folderlink_to_id(link):
Expand Down Expand Up @@ -102,7 +102,7 @@ def google_credentials():
creds.refresh(Request())
else:
if not os.path.exists(CLIENTSECRETS):
raise RuntimeError(f"{CLIENTSECRETS} does not exist.")
raise RuntimeError(f"{CLIENTSECRETS} does not exist.\nDownload it at https://console.developers.google.com/apis/credentials")
flow = InstalledAppFlow.from_client_secrets_file(
CLIENTSECRETS, SCOPES)
creds = flow.run_local_server(port=0)
Expand Down

0 comments on commit 0737b0f

Please sign in to comment.