diff --git a/bin/add_revision.py b/bin/add_revision.py index 58254b54d3..34a65b66dc 100755 --- a/bin/add_revision.py +++ b/bin/add_revision.py @@ -45,7 +45,7 @@ import tempfile from anthology.utils import deconstruct_anthology_id, indent -from anthology.data import ANTHOLOGY_URL +from anthology.data import ANTHOLOGY_PDF import lxml.etree as ET import urllib.request @@ -131,7 +131,7 @@ def main(args): # (essentially backing up the original version) revised_file_v1_path = os.path.join(output_dir, f'{args.anthology_id}{change_letter}1.pdf') - current_version = ANTHOLOGY_URL.format(args.anthology_id) + current_version = ANTHOLOGY_PDF.format(args.anthology_id) if args.do: try: print(f'-> Downloading file from {args.path} to {revised_file_v1_path}', file=sys.stderr) diff --git a/bin/anthology/data.py b/bin/anthology/data.py index 0464de08f7..d4944b4029 100644 --- a/bin/anthology/data.py +++ b/bin/anthology/data.py @@ -24,6 +24,8 @@ ANTHOLOGY_PREFIX = "https://www.aclweb.org/anthology" ANTHOLOGY_URL = ANTHOLOGY_PREFIX + '/{}' +ANTHOLOGY_PDF = ANTHOLOGY_PREFIX + '/{}.pdf' + ATTACHMENT_URL = ANTHOLOGY_PREFIX + '/attachments/{}' # Names of XML elements that may appear multiple times diff --git a/bin/anthology/papers.py b/bin/anthology/papers.py index 9548ae2d2b..4dd43e5fe5 100644 --- a/bin/anthology/papers.py +++ b/bin/anthology/papers.py @@ -77,7 +77,7 @@ def from_xml(xml_element, *args): tag, paper.full_id, item['url'] ) ) - item['url'] = data.ANTHOLOGY_URL.format(item['url']) + item['url'] = data.ANTHOLOGY_PDF.format(item['url']) if 'attachment' in paper.attrib: for item in paper.attrib['attachment']: @@ -90,7 +90,7 @@ def from_xml(xml_element, *args): paper.attrib['revision'].insert(0, { "value": "{}v1".format(paper.full_id), "id": "1", - "url": data.ANTHOLOGY_URL.format( "{}v1".format(paper.full_id)) } ) + "url": data.ANTHOLOGY_PDF.format( "{}v1".format(paper.full_id)) } ) paper.attrib["title"] = paper.get_title("plain") paper.attrib["booktitle"] = paper.get_booktitle("plain") diff --git a/bin/anthology/utils.py b/bin/anthology/utils.py index 82340ce7d8..315e482af6 100644 --- a/bin/anthology/utils.py +++ b/bin/anthology/utils.py @@ -116,12 +116,12 @@ def remove_extra_whitespace(text): return re.sub(" +", " ", text.replace("\n", "").strip()) -def infer_url(filename, prefix=data.ANTHOLOGY_URL): +def infer_url(filename, prefix=data.ANTHOLOGY_PREFIX): """If URL is relative, return the full Anthology URL. """ if urlparse(filename).netloc: return filename - return prefix.format(filename) + return f"{prefix}/{filename}" def infer_attachment_url(filename, parent_id=None): @@ -298,8 +298,11 @@ def parse_element(xml_element): value = element.text if tag == "url": + # Use the tag 'pdf' instead of 'url' + tag = 'pdf' + # Convert relative URLs to canonical ones - value = element.text if element.text.startswith('http') else data.ANTHOLOGY_URL.format(element.text) + value = element.text if element.text.startswith('http') else data.ANTHOLOGY_PDF.format(element.text) if tag in data.LIST_ELEMENTS: try: diff --git a/bin/create_bibtex.py b/bin/create_bibtex.py index 487561fe23..cb49454cdf 100755 --- a/bin/create_bibtex.py +++ b/bin/create_bibtex.py @@ -52,7 +52,7 @@ def create_bibtex(anthology, trgdir, clean=False): "{}/anthology.bib.gz".format(trgdir), "wt", encoding="utf-8" ) as file_full: for volume_id, volume in tqdm(anthology.volumes.items()): - volume_dir = "{}/papers/{}/{}".format(trgdir, volume_id[0], volume_id[:3]) + volume_dir = trgdir if not os.path.exists(volume_dir): os.makedirs(volume_dir) with open( diff --git a/hugo/config.toml b/hugo/config.toml index d838056f7e..59b9d749ce 100644 --- a/hugo/config.toml +++ b/hugo/config.toml @@ -4,6 +4,10 @@ disablePathToLower = true staticDir = ["static", "data-export"] +[permalinks] + papers = "/:filename/" + + [menu] [[menu.footer]] diff --git a/hugo/layouts/papers/list-entry.html b/hugo/layouts/papers/list-entry.html index 340c15c1cb..d5ac493e92 100644 --- a/hugo/layouts/papers/list-entry.html +++ b/hugo/layouts/papers/list-entry.html @@ -2,17 +2,13 @@ {{ $paper := index (index $.Site.Data.papers $volume_id) .Params.anthology_id }}

- {{- with $paper.url -}} + {{- with $paper.pdf -}} pdf - {{- if and (hasPrefix . $.Site.Params.baseURL) (eq . (strings.TrimSuffix ".pdf" .)) -}} - pdf - {{- end -}} {{- end -}} - {{- $bibfile := printf "/papers/%s/%s/%s.bib" (slicestr $volume_id 0 1) $volume_id .Params.anthology_id -}} - {{- if (fileExists (printf "/data-export/%s" $bibfile)) -}} - + {{- if (fileExists (printf "/data-export/%s.bib" .Params.anthology_id)) -}} + bib {{- end -}} diff --git a/hugo/layouts/papers/single.html b/hugo/layouts/papers/single.html index a927562b2b..12dd84956f 100644 --- a/hugo/layouts/papers/single.html +++ b/hugo/layouts/papers/single.html @@ -17,7 +17,7 @@ {{ with $volume.meta_issue }}{{ end }} {{ with $volume.meta_date }}{{ end }} {{ end }} -{{ with $paper.url }} +{{ with $paper.pdf }} {{ end }} {{ with $paper.page_first }}{{ end }} @@ -49,10 +49,13 @@ {{ $anthology_id := .Params.anthology_id }} {{ $volume_id := slicestr .Params.anthology_id 0 3 }} {{ $paper := index (index .Site.Data.papers $volume_id) .Params.anthology_id }} -{{ $bibfile := printf "/papers/%s/%s/%s.bib" (slicestr $volume_id 0 1) $volume_id $anthology_id }}

- {{ $paper.title_html | safeHTML }} + {{ with $paper.pdf }} + {{ $paper.title_html | safeHTML }} + {{ else }} + {{ $paper.title_html | safeHTML }} + {{ end }}

{{ with $paper.author }}

@@ -139,7 +142,7 @@

Abstract
Pages:
{{ with $paper.pages }}{{ . }}{{ end }}
URL:
-
{{ with $paper.url }}{{ . }}{{ end }}
+
{{ with $paper.pdf }}{{ . }}{{ end }}
DOI:
{{ with $paper.doi }}{{ . }}{{ end }}
Bib Export formats:
- {{ if (fileExists (printf "/data-export/%s" $bibfile)) }} - BibTeX + {{ if (fileExists (printf "/data-export/%s.bib" $anthology_id)) }} + BibTeX {{ end }} - {{ $expfile := printf "/papers/%s/%s/%s.xml" (slicestr $volume_id 0 1) $volume_id $anthology_id }} - {{ if (fileExists (printf "/data-export/%s" $expfile)) }} - MODS XML + {{ if (fileExists (printf "/data-export/%s.xml" $anthology_id)) }} + MODS XML {{ end }} - {{ $endfile := printf "/papers/%s/%s/%s.endf" (slicestr $volume_id 0 1) $volume_id $anthology_id }} - {{ if (fileExists (printf "/data-export/%s" $endfile)) }} - EndNote + {{ if (fileExists (printf "/data-export/%s.endf" $anthology_id)) }} + EndNote {{ end }} - {{ if (fileExists (printf "/data-export/%s" $bibfile)) }} - + {{ if (fileExists (printf "/data-export/%s.bib" $anthology_id)) }} + {{ end }}
@@ -187,14 +188,14 @@
Abstract
{{ end }} {{ else }} - {{ with $paper.url }} - + {{ with $paper.pdf }} + PDF {{ end }} {{ end }} - {{ if (fileExists (printf "/data-export/%s" $bibfile)) }} - + {{ if (fileExists (printf "/data-export/%s.bib" $anthology_id)) }} + BibTeX {{ end }} diff --git a/hugo/layouts/volumes/single.html b/hugo/layouts/volumes/single.html index c3fd957cb0..082b899cd1 100644 --- a/hugo/layouts/volumes/single.html +++ b/hugo/layouts/volumes/single.html @@ -7,7 +7,11 @@ {{ $paper := index .Site.Data.volumes .Params.anthology_id }}

- {{ $paper.title_html | safeHTML }} + {{ with $paper.pdf }} + {{ $paper.title_html | safeHTML }} + {{ else }} + {{ $paper.title_html | safeHTML }} + {{ end }}

{{ with $paper.editor }}

@@ -63,7 +67,7 @@

Publisher:
{{ with $paper.publisher }}{{ . }}{{ end }}
URL:
-
{{ with $paper.url }}{{ . }}{{ end }}
+
{{ with $paper.pdf }}{{ . }}{{ end }}
DOI:
{{ with $paper.doi }}{{ . }}{{ end }}