We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Create shortened volume links
@mjpost https://aclweb.org/anthology/volumes/sem-2012-the-first-joint-conference-on-lexical-and-computational-semantics-volume-1-proceedings-of-the-main-conference-and-the-shared-task-and-volume-2-proceedings-of-the-sixth-international-workshop-on-semantic-evaluation-semeval-2012/

The URL of the PDF is:
https://www.aclweb.org/anthology/S12-1

For a paper:
https://aclweb.org/anthology/papers/S/S12/S12-1000/
(the title is the same, but the content not).

The PDF:
https://www.aclweb.org/anthology/S12-1000

It would be much easier to reference the first link if it was https://aclweb.org/anthology/papers/S/S12/S12-1/.

_Originally posted by @Aspie96 in https://github.com/acl-org/acl-anthology/issues/170#issuecomment-504191669_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bin/create_hugo_pages.py`
Content:
```
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2019 Marcel Bollmann <marcel@bollmann.me>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 
18 """Usage: create_hugo_pages.py [--dir=DIR] [-c] [--debug]
19 
20 Creates page stubs for the full anthology based on the YAML data files.
21 
22 This script can only be run after create_hugo_yaml.py!
23 
24 Options:
25   --dir=DIR                Hugo project directory. [default: {scriptdir}/../build/]
26   --debug                  Output debug-level log messages.
27   -c, --clean              Delete existing files in target directory before generation.
28   -h, --help               Display this helpful text.
29 """
30 
31 from docopt import docopt
32 from glob import glob
33 from slugify import slugify
34 from tqdm import tqdm
35 import logging as log
36 import os
37 import shutil
38 import yaml
39 
40 try:
41     from yaml import CLoader as Loader
42 except ImportError:
43     from yaml import Loader
44 
45 from anthology.utils import SeverityTracker
46 
47 
48 def check_directory(cdir, clean=False):
49     if not os.path.isdir(cdir) and not os.path.exists(cdir):
50         os.mkdir(cdir)
51         return True
52     entries = os.listdir(cdir)
53     if "_index.md" in entries:
54         entries.remove("_index.md")
55     if entries and not clean:
56         log.critical("Directory already exists and has content files: {}".format(cdir))
57         log.info(
58             "Call this script with the -c/--clean flag to automatically DELETE existing files"
59         )
60         return False
61     for entry in entries:
62         entry = "{}/{}".format(cdir, entry)
63         if os.path.isdir(entry):
64             shutil.rmtree(entry)
65         else:
66             os.remove(entry)
67     return True
68 
69 
70 def create_papers(srcdir, clean=False):
71     """Creates page stubs for all papers in the Anthology."""
72     log.info("Creating stubs for papers...")
73     if not check_directory("{}/content/papers".format(srcdir), clean=clean):
74         return
75 
76     # Go through all paper volumes
77     for yamlfile in tqdm(glob("{}/data/papers/*.yaml".format(srcdir))):
78         log.debug("Processing {}".format(yamlfile))
79         with open(yamlfile, "r") as f:
80             data = yaml.load(f, Loader=Loader)
81         # Create a paper stub for each entry in the volume
82         for anthology_id, entry in data.items():
83             paper_dir = "{}/content/papers/{}/{}".format(
84                 srcdir, anthology_id[0], anthology_id[:3]
85             )
86             if not os.path.exists(paper_dir):
87                 os.makedirs(paper_dir)
88             with open("{}/{}.md".format(paper_dir, anthology_id), "w") as f:
89                 print("---", file=f)
90                 yaml.dump(
91                     {"anthology_id": anthology_id, "title": entry["title"]},
92                     default_flow_style=False,
93                     stream=f,
94                 )
95                 print("---", file=f)
96 
97 
98 def create_volumes(srcdir, clean=False):
99     """Creates page stubs for all proceedings volumes in the Anthology."""
100     log.info("Creating stubs for volumes...")
101     if not check_directory("{}/content/volumes".format(srcdir), clean=clean):
102         return
103 
104     yamlfile = "{}/data/volumes.yaml".format(srcdir)
105     log.debug("Processing {}".format(yamlfile))
106     with open(yamlfile, "r") as f:
107         data = yaml.load(f, Loader=Loader)
108     # Create a paper stub for each proceedings volume
109     for anthology_id, entry in data.items():
110         with open("{}/content/volumes/{}.md".format(srcdir, anthology_id), "w") as f:
111             print("---", file=f)
112             yaml.dump(
113                 {
114                     "anthology_id": anthology_id,
115                     "title": entry["title"],
116                     "slug": slugify(entry["title"]),
117                 },
118                 default_flow_style=False,
119                 stream=f,
120             )
121             print("---", file=f)
122 
123     return data
124 
125 
126 def create_people(srcdir, clean=False):
127     """Creates page stubs for all authors/editors in the Anthology."""
128     log.info("Creating stubs for people...")
129     if not check_directory("{}/content/people".format(srcdir), clean=clean):
130         return
131 
132     for yamlfile in tqdm(glob("{}/data/people/*.yaml".format(srcdir))):
133         log.debug("Processing {}".format(yamlfile))
134         with open(yamlfile, "r") as f:
135             data = yaml.load(f, Loader=Loader)
136         # Create a page stub for each person
137         for name, entry in data.items():
138             person_dir = "{}/content/people/{}".format(srcdir, name[0])
139             if not os.path.exists(person_dir):
140                 os.makedirs(person_dir)
141             yaml_data = {
142                 "name": name,
143                 "title": entry["full"],
144                 "lastname": entry["last"],
145             }
146             with open("{}/{}.md".format(person_dir, name), "w") as f:
147                 print("---", file=f)
148                 # "lastname" is dumped to allow sorting by it in Hugo
149                 yaml.dump(yaml_data, default_flow_style=False, stream=f)
150                 print("---", file=f)
151 
152     return data
153 
154 
155 def create_venues_and_events(srcdir, clean=False):
156     """Creates page stubs for all venues and events in the Anthology."""
157     yamlfile = "{}/data/venues.yaml".format(srcdir)
158     log.debug("Processing {}".format(yamlfile))
159     with open(yamlfile, "r") as f:
160         data = yaml.load(f, Loader=Loader)
161 
162     log.info("Creating stubs for venues...")
163     if not check_directory("{}/content/venues".format(srcdir), clean=clean):
164         return
165     # Create a paper stub for each venue (e.g. ACL)
166     for venue, venue_data in data.items():
167         venue_str = venue_data["slug"]
168         with open("{}/content/venues/{}.md".format(srcdir, venue_str), "w") as f:
169             print("---", file=f)
170             yaml_data = {"venue": venue, "title": venue_data["name"]}
171             if venue_data["is_toplevel"]:
172                 main_letter = venue_data["main_letter"]
173                 yaml_data["aliases"] = ["/papers/{}/".format(main_letter)]
174             yaml.dump(yaml_data, default_flow_style=False, stream=f)
175             print("---", file=f)
176 
177     log.info("Creating stubs for events...")
178     if not check_directory("{}/content/events".format(srcdir), clean=clean):
179         return
180     # Create a paper stub for each event (= venue + year, e.g. ACL 2018)
181     for venue, venue_data in data.items():
182         venue_str = venue_data["slug"]
183         for year in venue_data["volumes_by_year"]:
184             with open(
185                 "{}/content/events/{}-{}.md".format(srcdir, venue_str, year), "w"
186             ) as f:
187                 print("---", file=f)
188                 yaml_data = {
189                     "venue": venue,
190                     "year": year,
191                     "title": "{} ({})".format(venue_data["name"], year),
192                 }
193                 if venue_data["is_toplevel"]:
194                     main_letter = venue_data["main_letter"]
195                     main_prefix = main_letter + year[-2:]  # e.g., P05
196                     yaml_data["aliases"] = [
197                         "/papers/{}/{}/".format(main_letter, main_prefix)
198                     ]
199                 yaml.dump(yaml_data, default_flow_style=False, stream=f)
200                 print("---", file=f)
201 
202 
203 def create_sigs(srcdir, clean=False):
204     """Creates page stubs for all SIGs in the Anthology."""
205     yamlfile = "{}/data/sigs.yaml".format(srcdir)
206     log.debug("Processing {}".format(yamlfile))
207     with open(yamlfile, "r") as f:
208         data = yaml.load(f, Loader=Loader)
209 
210     log.info("Creating stubs for SIGs...")
211     if not check_directory("{}/content/sigs".format(srcdir), clean=clean):
212         return
213     # Create a paper stub for each SIGS (e.g. SIGMORPHON)
214     for sig, sig_data in data.items():
215         sig_str = sig_data["slug"]
216         with open("{}/content/sigs/{}.md".format(srcdir, sig_str), "w") as f:
217             print("---", file=f)
218             yaml.dump(
219                 {
220                     "acronym": sig,
221                     "short_acronym": sig[3:] if sig.startswith("SIG") else sig,
222                     "title": sig_data["name"],
223                 },
224                 default_flow_style=False,
225                 stream=f,
226             )
227             print("---", file=f)
228 
229 
230 if __name__ == "__main__":
231     args = docopt(__doc__)
232     scriptdir = os.path.dirname(os.path.abspath(__file__))
233     if "{scriptdir}" in args["--dir"]:
234         args["--dir"] = args["--dir"].format(scriptdir=scriptdir)
235     dir_ = os.path.abspath(args["--dir"])
236 
237     log_level = log.DEBUG if args["--debug"] else log.INFO
238     log.basicConfig(format="%(levelname)-8s %(message)s", level=log_level)
239     tracker = SeverityTracker()
240     log.getLogger().addHandler(tracker)
241 
242     create_papers(dir_, clean=args["--clean"])
243     create_volumes(dir_, clean=args["--clean"])
244     create_people(dir_, clean=args["--clean"])
245     create_venues_and_events(dir_, clean=args["--clean"])
246     create_sigs(dir_, clean=args["--clean"])
247 
248     if tracker.highest >= log.ERROR:
249         exit(1)
250
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bin/create_hugo_pages.py b/bin/create_hugo_pages.py
--- a/bin/create_hugo_pages.py
+++ b/bin/create_hugo_pages.py
@@ -113,7 +113,12 @@
                 {
                     "anthology_id": anthology_id,
                     "title": entry["title"],
-                    "slug": slugify(entry["title"]),
+                    "aliases": [
+                        slugify(entry["title"]),
+                        "/papers/{}/{}/{}/".format(
+                            anthology_id[0], anthology_id[:3], anthology_id
+                        ),
+                    ],
                 },
                 default_flow_style=False,
                 stream=f,

{"golden_diff": "diff --git a/bin/create_hugo_pages.py b/bin/create_hugo_pages.py\n--- a/bin/create_hugo_pages.py\n+++ b/bin/create_hugo_pages.py\n@@ -113,7 +113,12 @@\n                 {\n                     \"anthology_id\": anthology_id,\n                     \"title\": entry[\"title\"],\n-                    \"slug\": slugify(entry[\"title\"]),\n+                    \"aliases\": [\n+                        slugify(entry[\"title\"]),\n+                        \"/papers/{}/{}/{}/\".format(\n+                            anthology_id[0], anthology_id[:3], anthology_id\n+                        ),\n+                    ],\n                 },\n                 default_flow_style=False,\n                 stream=f,\n", "issue": "Create shortened volume links\n@mjpost https://aclweb.org/anthology/volumes/sem-2012-the-first-joint-conference-on-lexical-and-computational-semantics-volume-1-proceedings-of-the-main-conference-and-the-shared-task-and-volume-2-proceedings-of-the-sixth-international-workshop-on-semantic-evaluation-semeval-2012/\r\n\r\nThe URL of the PDF is:\r\nhttps://www.aclweb.org/anthology/S12-1\r\n\r\nFor a paper:\r\nhttps://aclweb.org/anthology/papers/S/S12/S12-1000/\r\n(the title is the same, but the content not).\r\n\r\nThe PDF:\r\nhttps://www.aclweb.org/anthology/S12-1000\r\n\r\nIt would be much easier to reference the first link if it was https://aclweb.org/anthology/papers/S/S12/S12-1/.\r\n\r\n_Originally posted by @Aspie96 in https://github.com/acl-org/acl-anthology/issues/170#issuecomment-504191669_\n", "before_files": [{"content": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n#\n# Copyright 2019 Marcel Bollmann <marcel@bollmann.me>\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Usage: create_hugo_pages.py [--dir=DIR] [-c] [--debug]\n\nCreates page stubs for the full anthology based on the YAML data files.\n\nThis script can only be run after create_hugo_yaml.py!\n\nOptions:\n  --dir=DIR                Hugo project directory. [default: {scriptdir}/../build/]\n  --debug                  Output debug-level log messages.\n  -c, --clean              Delete existing files in target directory before generation.\n  -h, --help               Display this helpful text.\n\"\"\"\n\nfrom docopt import docopt\nfrom glob import glob\nfrom slugify import slugify\nfrom tqdm import tqdm\nimport logging as log\nimport os\nimport shutil\nimport yaml\n\ntry:\n    from yaml import CLoader as Loader\nexcept ImportError:\n    from yaml import Loader\n\nfrom anthology.utils import SeverityTracker\n\n\ndef check_directory(cdir, clean=False):\n    if not os.path.isdir(cdir) and not os.path.exists(cdir):\n        os.mkdir(cdir)\n        return True\n    entries = os.listdir(cdir)\n    if \"_index.md\" in entries:\n        entries.remove(\"_index.md\")\n    if entries and not clean:\n        log.critical(\"Directory already exists and has content files: {}\".format(cdir))\n        log.info(\n            \"Call this script with the -c/--clean flag to automatically DELETE existing files\"\n        )\n        return False\n    for entry in entries:\n        entry = \"{}/{}\".format(cdir, entry)\n        if os.path.isdir(entry):\n            shutil.rmtree(entry)\n        else:\n            os.remove(entry)\n    return True\n\n\ndef create_papers(srcdir, clean=False):\n    \"\"\"Creates page stubs for all papers in the Anthology.\"\"\"\n    log.info(\"Creating stubs for papers...\")\n    if not check_directory(\"{}/content/papers\".format(srcdir), clean=clean):\n        return\n\n    # Go through all paper volumes\n    for yamlfile in tqdm(glob(\"{}/data/papers/*.yaml\".format(srcdir))):\n        log.debug(\"Processing {}\".format(yamlfile))\n        with open(yamlfile, \"r\") as f:\n            data = yaml.load(f, Loader=Loader)\n        # Create a paper stub for each entry in the volume\n        for anthology_id, entry in data.items():\n            paper_dir = \"{}/content/papers/{}/{}\".format(\n                srcdir, anthology_id[0], anthology_id[:3]\n            )\n            if not os.path.exists(paper_dir):\n                os.makedirs(paper_dir)\n            with open(\"{}/{}.md\".format(paper_dir, anthology_id), \"w\") as f:\n                print(\"---\", file=f)\n                yaml.dump(\n                    {\"anthology_id\": anthology_id, \"title\": entry[\"title\"]},\n                    default_flow_style=False,\n                    stream=f,\n                )\n                print(\"---\", file=f)\n\n\ndef create_volumes(srcdir, clean=False):\n    \"\"\"Creates page stubs for all proceedings volumes in the Anthology.\"\"\"\n    log.info(\"Creating stubs for volumes...\")\n    if not check_directory(\"{}/content/volumes\".format(srcdir), clean=clean):\n        return\n\n    yamlfile = \"{}/data/volumes.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n    # Create a paper stub for each proceedings volume\n    for anthology_id, entry in data.items():\n        with open(\"{}/content/volumes/{}.md\".format(srcdir, anthology_id), \"w\") as f:\n            print(\"---\", file=f)\n            yaml.dump(\n                {\n                    \"anthology_id\": anthology_id,\n                    \"title\": entry[\"title\"],\n                    \"slug\": slugify(entry[\"title\"]),\n                },\n                default_flow_style=False,\n                stream=f,\n            )\n            print(\"---\", file=f)\n\n    return data\n\n\ndef create_people(srcdir, clean=False):\n    \"\"\"Creates page stubs for all authors/editors in the Anthology.\"\"\"\n    log.info(\"Creating stubs for people...\")\n    if not check_directory(\"{}/content/people\".format(srcdir), clean=clean):\n        return\n\n    for yamlfile in tqdm(glob(\"{}/data/people/*.yaml\".format(srcdir))):\n        log.debug(\"Processing {}\".format(yamlfile))\n        with open(yamlfile, \"r\") as f:\n            data = yaml.load(f, Loader=Loader)\n        # Create a page stub for each person\n        for name, entry in data.items():\n            person_dir = \"{}/content/people/{}\".format(srcdir, name[0])\n            if not os.path.exists(person_dir):\n                os.makedirs(person_dir)\n            yaml_data = {\n                \"name\": name,\n                \"title\": entry[\"full\"],\n                \"lastname\": entry[\"last\"],\n            }\n            with open(\"{}/{}.md\".format(person_dir, name), \"w\") as f:\n                print(\"---\", file=f)\n                # \"lastname\" is dumped to allow sorting by it in Hugo\n                yaml.dump(yaml_data, default_flow_style=False, stream=f)\n                print(\"---\", file=f)\n\n    return data\n\n\ndef create_venues_and_events(srcdir, clean=False):\n    \"\"\"Creates page stubs for all venues and events in the Anthology.\"\"\"\n    yamlfile = \"{}/data/venues.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n\n    log.info(\"Creating stubs for venues...\")\n    if not check_directory(\"{}/content/venues\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each venue (e.g. ACL)\n    for venue, venue_data in data.items():\n        venue_str = venue_data[\"slug\"]\n        with open(\"{}/content/venues/{}.md\".format(srcdir, venue_str), \"w\") as f:\n            print(\"---\", file=f)\n            yaml_data = {\"venue\": venue, \"title\": venue_data[\"name\"]}\n            if venue_data[\"is_toplevel\"]:\n                main_letter = venue_data[\"main_letter\"]\n                yaml_data[\"aliases\"] = [\"/papers/{}/\".format(main_letter)]\n            yaml.dump(yaml_data, default_flow_style=False, stream=f)\n            print(\"---\", file=f)\n\n    log.info(\"Creating stubs for events...\")\n    if not check_directory(\"{}/content/events\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each event (= venue + year, e.g. ACL 2018)\n    for venue, venue_data in data.items():\n        venue_str = venue_data[\"slug\"]\n        for year in venue_data[\"volumes_by_year\"]:\n            with open(\n                \"{}/content/events/{}-{}.md\".format(srcdir, venue_str, year), \"w\"\n            ) as f:\n                print(\"---\", file=f)\n                yaml_data = {\n                    \"venue\": venue,\n                    \"year\": year,\n                    \"title\": \"{} ({})\".format(venue_data[\"name\"], year),\n                }\n                if venue_data[\"is_toplevel\"]:\n                    main_letter = venue_data[\"main_letter\"]\n                    main_prefix = main_letter + year[-2:]  # e.g., P05\n                    yaml_data[\"aliases\"] = [\n                        \"/papers/{}/{}/\".format(main_letter, main_prefix)\n                    ]\n                yaml.dump(yaml_data, default_flow_style=False, stream=f)\n                print(\"---\", file=f)\n\n\ndef create_sigs(srcdir, clean=False):\n    \"\"\"Creates page stubs for all SIGs in the Anthology.\"\"\"\n    yamlfile = \"{}/data/sigs.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n\n    log.info(\"Creating stubs for SIGs...\")\n    if not check_directory(\"{}/content/sigs\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each SIGS (e.g. SIGMORPHON)\n    for sig, sig_data in data.items():\n        sig_str = sig_data[\"slug\"]\n        with open(\"{}/content/sigs/{}.md\".format(srcdir, sig_str), \"w\") as f:\n            print(\"---\", file=f)\n            yaml.dump(\n                {\n                    \"acronym\": sig,\n                    \"short_acronym\": sig[3:] if sig.startswith(\"SIG\") else sig,\n                    \"title\": sig_data[\"name\"],\n                },\n                default_flow_style=False,\n                stream=f,\n            )\n            print(\"---\", file=f)\n\n\nif __name__ == \"__main__\":\n    args = docopt(__doc__)\n    scriptdir = os.path.dirname(os.path.abspath(__file__))\n    if \"{scriptdir}\" in args[\"--dir\"]:\n        args[\"--dir\"] = args[\"--dir\"].format(scriptdir=scriptdir)\n    dir_ = os.path.abspath(args[\"--dir\"])\n\n    log_level = log.DEBUG if args[\"--debug\"] else log.INFO\n    log.basicConfig(format=\"%(levelname)-8s %(message)s\", level=log_level)\n    tracker = SeverityTracker()\n    log.getLogger().addHandler(tracker)\n\n    create_papers(dir_, clean=args[\"--clean\"])\n    create_volumes(dir_, clean=args[\"--clean\"])\n    create_people(dir_, clean=args[\"--clean\"])\n    create_venues_and_events(dir_, clean=args[\"--clean\"])\n    create_sigs(dir_, clean=args[\"--clean\"])\n\n    if tracker.highest >= log.ERROR:\n        exit(1)\n", "path": "bin/create_hugo_pages.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n#\n# Copyright 2019 Marcel Bollmann <marcel@bollmann.me>\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Usage: create_hugo_pages.py [--dir=DIR] [-c] [--debug]\n\nCreates page stubs for the full anthology based on the YAML data files.\n\nThis script can only be run after create_hugo_yaml.py!\n\nOptions:\n  --dir=DIR                Hugo project directory. [default: {scriptdir}/../build/]\n  --debug                  Output debug-level log messages.\n  -c, --clean              Delete existing files in target directory before generation.\n  -h, --help               Display this helpful text.\n\"\"\"\n\nfrom docopt import docopt\nfrom glob import glob\nfrom slugify import slugify\nfrom tqdm import tqdm\nimport logging as log\nimport os\nimport shutil\nimport yaml\n\ntry:\n    from yaml import CLoader as Loader\nexcept ImportError:\n    from yaml import Loader\n\nfrom anthology.utils import SeverityTracker\n\n\ndef check_directory(cdir, clean=False):\n    if not os.path.isdir(cdir) and not os.path.exists(cdir):\n        os.mkdir(cdir)\n        return True\n    entries = os.listdir(cdir)\n    if \"_index.md\" in entries:\n        entries.remove(\"_index.md\")\n    if entries and not clean:\n        log.critical(\"Directory already exists and has content files: {}\".format(cdir))\n        log.info(\n            \"Call this script with the -c/--clean flag to automatically DELETE existing files\"\n        )\n        return False\n    for entry in entries:\n        entry = \"{}/{}\".format(cdir, entry)\n        if os.path.isdir(entry):\n            shutil.rmtree(entry)\n        else:\n            os.remove(entry)\n    return True\n\n\ndef create_papers(srcdir, clean=False):\n    \"\"\"Creates page stubs for all papers in the Anthology.\"\"\"\n    log.info(\"Creating stubs for papers...\")\n    if not check_directory(\"{}/content/papers\".format(srcdir), clean=clean):\n        return\n\n    # Go through all paper volumes\n    for yamlfile in tqdm(glob(\"{}/data/papers/*.yaml\".format(srcdir))):\n        log.debug(\"Processing {}\".format(yamlfile))\n        with open(yamlfile, \"r\") as f:\n            data = yaml.load(f, Loader=Loader)\n        # Create a paper stub for each entry in the volume\n        for anthology_id, entry in data.items():\n            paper_dir = \"{}/content/papers/{}/{}\".format(\n                srcdir, anthology_id[0], anthology_id[:3]\n            )\n            if not os.path.exists(paper_dir):\n                os.makedirs(paper_dir)\n            with open(\"{}/{}.md\".format(paper_dir, anthology_id), \"w\") as f:\n                print(\"---\", file=f)\n                yaml.dump(\n                    {\"anthology_id\": anthology_id, \"title\": entry[\"title\"]},\n                    default_flow_style=False,\n                    stream=f,\n                )\n                print(\"---\", file=f)\n\n\ndef create_volumes(srcdir, clean=False):\n    \"\"\"Creates page stubs for all proceedings volumes in the Anthology.\"\"\"\n    log.info(\"Creating stubs for volumes...\")\n    if not check_directory(\"{}/content/volumes\".format(srcdir), clean=clean):\n        return\n\n    yamlfile = \"{}/data/volumes.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n    # Create a paper stub for each proceedings volume\n    for anthology_id, entry in data.items():\n        with open(\"{}/content/volumes/{}.md\".format(srcdir, anthology_id), \"w\") as f:\n            print(\"---\", file=f)\n            yaml.dump(\n                {\n                    \"anthology_id\": anthology_id,\n                    \"title\": entry[\"title\"],\n                    \"aliases\": [\n                        slugify(entry[\"title\"]),\n                        \"/papers/{}/{}/{}/\".format(\n                            anthology_id[0], anthology_id[:3], anthology_id\n                        ),\n                    ],\n                },\n                default_flow_style=False,\n                stream=f,\n            )\n            print(\"---\", file=f)\n\n    return data\n\n\ndef create_people(srcdir, clean=False):\n    \"\"\"Creates page stubs for all authors/editors in the Anthology.\"\"\"\n    log.info(\"Creating stubs for people...\")\n    if not check_directory(\"{}/content/people\".format(srcdir), clean=clean):\n        return\n\n    for yamlfile in tqdm(glob(\"{}/data/people/*.yaml\".format(srcdir))):\n        log.debug(\"Processing {}\".format(yamlfile))\n        with open(yamlfile, \"r\") as f:\n            data = yaml.load(f, Loader=Loader)\n        # Create a page stub for each person\n        for name, entry in data.items():\n            person_dir = \"{}/content/people/{}\".format(srcdir, name[0])\n            if not os.path.exists(person_dir):\n                os.makedirs(person_dir)\n            yaml_data = {\n                \"name\": name,\n                \"title\": entry[\"full\"],\n                \"lastname\": entry[\"last\"],\n            }\n            with open(\"{}/{}.md\".format(person_dir, name), \"w\") as f:\n                print(\"---\", file=f)\n                # \"lastname\" is dumped to allow sorting by it in Hugo\n                yaml.dump(yaml_data, default_flow_style=False, stream=f)\n                print(\"---\", file=f)\n\n    return data\n\n\ndef create_venues_and_events(srcdir, clean=False):\n    \"\"\"Creates page stubs for all venues and events in the Anthology.\"\"\"\n    yamlfile = \"{}/data/venues.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n\n    log.info(\"Creating stubs for venues...\")\n    if not check_directory(\"{}/content/venues\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each venue (e.g. ACL)\n    for venue, venue_data in data.items():\n        venue_str = venue_data[\"slug\"]\n        with open(\"{}/content/venues/{}.md\".format(srcdir, venue_str), \"w\") as f:\n            print(\"---\", file=f)\n            yaml_data = {\"venue\": venue, \"title\": venue_data[\"name\"]}\n            if venue_data[\"is_toplevel\"]:\n                main_letter = venue_data[\"main_letter\"]\n                yaml_data[\"aliases\"] = [\"/papers/{}/\".format(main_letter)]\n            yaml.dump(yaml_data, default_flow_style=False, stream=f)\n            print(\"---\", file=f)\n\n    log.info(\"Creating stubs for events...\")\n    if not check_directory(\"{}/content/events\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each event (= venue + year, e.g. ACL 2018)\n    for venue, venue_data in data.items():\n        venue_str = venue_data[\"slug\"]\n        for year in venue_data[\"volumes_by_year\"]:\n            with open(\n                \"{}/content/events/{}-{}.md\".format(srcdir, venue_str, year), \"w\"\n            ) as f:\n                print(\"---\", file=f)\n                yaml_data = {\n                    \"venue\": venue,\n                    \"year\": year,\n                    \"title\": \"{} ({})\".format(venue_data[\"name\"], year),\n                }\n                if venue_data[\"is_toplevel\"]:\n                    main_letter = venue_data[\"main_letter\"]\n                    main_prefix = main_letter + year[-2:]  # e.g., P05\n                    yaml_data[\"aliases\"] = [\n                        \"/papers/{}/{}/\".format(main_letter, main_prefix)\n                    ]\n                yaml.dump(yaml_data, default_flow_style=False, stream=f)\n                print(\"---\", file=f)\n\n\ndef create_sigs(srcdir, clean=False):\n    \"\"\"Creates page stubs for all SIGs in the Anthology.\"\"\"\n    yamlfile = \"{}/data/sigs.yaml\".format(srcdir)\n    log.debug(\"Processing {}\".format(yamlfile))\n    with open(yamlfile, \"r\") as f:\n        data = yaml.load(f, Loader=Loader)\n\n    log.info(\"Creating stubs for SIGs...\")\n    if not check_directory(\"{}/content/sigs\".format(srcdir), clean=clean):\n        return\n    # Create a paper stub for each SIGS (e.g. SIGMORPHON)\n    for sig, sig_data in data.items():\n        sig_str = sig_data[\"slug\"]\n        with open(\"{}/content/sigs/{}.md\".format(srcdir, sig_str), \"w\") as f:\n            print(\"---\", file=f)\n            yaml.dump(\n                {\n                    \"acronym\": sig,\n                    \"short_acronym\": sig[3:] if sig.startswith(\"SIG\") else sig,\n                    \"title\": sig_data[\"name\"],\n                },\n                default_flow_style=False,\n                stream=f,\n            )\n            print(\"---\", file=f)\n\n\nif __name__ == \"__main__\":\n    args = docopt(__doc__)\n    scriptdir = os.path.dirname(os.path.abspath(__file__))\n    if \"{scriptdir}\" in args[\"--dir\"]:\n        args[\"--dir\"] = args[\"--dir\"].format(scriptdir=scriptdir)\n    dir_ = os.path.abspath(args[\"--dir\"])\n\n    log_level = log.DEBUG if args[\"--debug\"] else log.INFO\n    log.basicConfig(format=\"%(levelname)-8s %(message)s\", level=log_level)\n    tracker = SeverityTracker()\n    log.getLogger().addHandler(tracker)\n\n    create_papers(dir_, clean=args[\"--clean\"])\n    create_volumes(dir_, clean=args[\"--clean\"])\n    create_people(dir_, clean=args[\"--clean\"])\n    create_venues_and_events(dir_, clean=args[\"--clean\"])\n    create_sigs(dir_, clean=args[\"--clean\"])\n\n    if tracker.highest >= log.ERROR:\n        exit(1)\n", "path": "bin/create_hugo_pages.py"}]}