We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Volume page aliases generated incorrectly
The Volume page Spoken Language Translation [here](https://aclweb.org/anthology/volumes/spoken-language-translation/) does not exist. Same with the [Tutorials volume](https://aclweb.org/anthology/volumes/tutorials/). I couldn't concoct any other volume names to test out, but both pages appear on Google.

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

--- 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                     "aliases": [
117                         slugify(entry["title"]),
118                         "/papers/{}/{}/{}/".format(
119                             anthology_id[0], anthology_id[:3], anthology_id
120                         ),
121                     ],
122                 },
123                 default_flow_style=False,
124                 stream=f,
125             )
126             print("---", file=f)
127 
128     return data
129 
130 
131 def create_people(srcdir, clean=False):
132     """Creates page stubs for all authors/editors in the Anthology."""
133     log.info("Creating stubs for people...")
134     if not check_directory("{}/content/people".format(srcdir), clean=clean):
135         return
136 
137     for yamlfile in tqdm(glob("{}/data/people/*.yaml".format(srcdir))):
138         log.debug("Processing {}".format(yamlfile))
139         with open(yamlfile, "r") as f:
140             data = yaml.load(f, Loader=Loader)
141         # Create a page stub for each person
142         for name, entry in data.items():
143             person_dir = "{}/content/people/{}".format(srcdir, name[0])
144             if not os.path.exists(person_dir):
145                 os.makedirs(person_dir)
146             yaml_data = {
147                 "name": name,
148                 "title": entry["full"],
149                 "lastname": entry["last"],
150             }
151             with open("{}/{}.md".format(person_dir, name), "w") as f:
152                 print("---", file=f)
153                 # "lastname" is dumped to allow sorting by it in Hugo
154                 yaml.dump(yaml_data, default_flow_style=False, stream=f)
155                 print("---", file=f)
156 
157     return data
158 
159 
160 def create_venues_and_events(srcdir, clean=False):
161     """Creates page stubs for all venues and events in the Anthology."""
162     yamlfile = "{}/data/venues.yaml".format(srcdir)
163     log.debug("Processing {}".format(yamlfile))
164     with open(yamlfile, "r") as f:
165         data = yaml.load(f, Loader=Loader)
166 
167     log.info("Creating stubs for venues...")
168     if not check_directory("{}/content/venues".format(srcdir), clean=clean):
169         return
170     # Create a paper stub for each venue (e.g. ACL)
171     for venue, venue_data in data.items():
172         venue_str = venue_data["slug"]
173         with open("{}/content/venues/{}.md".format(srcdir, venue_str), "w") as f:
174             print("---", file=f)
175             yaml_data = {"venue": venue, "title": venue_data["name"]}
176             if venue_data["is_toplevel"]:
177                 main_letter = venue_data["main_letter"]
178                 yaml_data["aliases"] = ["/papers/{}/".format(main_letter)]
179             yaml.dump(yaml_data, default_flow_style=False, stream=f)
180             print("---", file=f)
181 
182     log.info("Creating stubs for events...")
183     if not check_directory("{}/content/events".format(srcdir), clean=clean):
184         return
185     # Create a paper stub for each event (= venue + year, e.g. ACL 2018)
186     for venue, venue_data in data.items():
187         venue_str = venue_data["slug"]
188         for year in venue_data["volumes_by_year"]:
189             with open(
190                 "{}/content/events/{}-{}.md".format(srcdir, venue_str, year), "w"
191             ) as f:
192                 print("---", file=f)
193                 yaml_data = {
194                     "venue": venue,
195                     "year": year,
196                     "title": "{} ({})".format(venue_data["name"], year),
197                 }
198                 if venue_data["is_toplevel"]:
199                     main_letter = venue_data["main_letter"]
200                     main_prefix = main_letter + year[-2:]  # e.g., P05
201                     yaml_data["aliases"] = [
202                         "/papers/{}/{}/".format(main_letter, main_prefix)
203                     ]
204                 yaml.dump(yaml_data, default_flow_style=False, stream=f)
205                 print("---", file=f)
206 
207 
208 def create_sigs(srcdir, clean=False):
209     """Creates page stubs for all SIGs in the Anthology."""
210     yamlfile = "{}/data/sigs.yaml".format(srcdir)
211     log.debug("Processing {}".format(yamlfile))
212     with open(yamlfile, "r") as f:
213         data = yaml.load(f, Loader=Loader)
214 
215     log.info("Creating stubs for SIGs...")
216     if not check_directory("{}/content/sigs".format(srcdir), clean=clean):
217         return
218     # Create a paper stub for each SIGS (e.g. SIGMORPHON)
219     for sig, sig_data in data.items():
220         sig_str = sig_data["slug"]
221         with open("{}/content/sigs/{}.md".format(srcdir, sig_str), "w") as f:
222             print("---", file=f)
223             yaml.dump(
224                 {
225                     "acronym": sig,
226                     "short_acronym": sig[3:] if sig.startswith("SIG") else sig,
227                     "title": sig_data["name"],
228                 },
229                 default_flow_style=False,
230                 stream=f,
231             )
232             print("---", file=f)
233 
234 
235 if __name__ == "__main__":
236     args = docopt(__doc__)
237     scriptdir = os.path.dirname(os.path.abspath(__file__))
238     if "{scriptdir}" in args["--dir"]:
239         args["--dir"] = args["--dir"].format(scriptdir=scriptdir)
240     dir_ = os.path.abspath(args["--dir"])
241 
242     log_level = log.DEBUG if args["--debug"] else log.INFO
243     log.basicConfig(format="%(levelname)-8s %(message)s", level=log_level)
244     tracker = SeverityTracker()
245     log.getLogger().addHandler(tracker)
246 
247     create_papers(dir_, clean=args["--clean"])
248     create_volumes(dir_, clean=args["--clean"])
249     create_people(dir_, clean=args["--clean"])
250     create_venues_and_events(dir_, clean=args["--clean"])
251     create_sigs(dir_, clean=args["--clean"])
252 
253     if tracker.highest >= log.ERROR:
254         exit(1)
255
```
--- 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
@@ -114,7 +114,7 @@
                     "anthology_id": anthology_id,
                     "title": entry["title"],
                     "aliases": [
-                        slugify(entry["title"]),
+                        "/volumes/{}/".format(slugify(entry["title"])),
                         "/papers/{}/{}/{}/".format(
                             anthology_id[0], anthology_id[:3], anthology_id
                         ),

{"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@@ -114,7 +114,7 @@\n                     \"anthology_id\": anthology_id,\n                     \"title\": entry[\"title\"],\n                     \"aliases\": [\n-                        slugify(entry[\"title\"]),\n+                        \"/volumes/{}/\".format(slugify(entry[\"title\"])),\n                         \"/papers/{}/{}/{}/\".format(\n                             anthology_id[0], anthology_id[:3], anthology_id\n                         ),\n", "issue": "Volume page aliases generated incorrectly\nThe Volume page Spoken Language Translation [here](https://aclweb.org/anthology/volumes/spoken-language-translation/) does not exist. Same with the [Tutorials volume](https://aclweb.org/anthology/volumes/tutorials/). I couldn't concoct any other volume names to test out, but both pages appear on Google.\r\n\r\n_Originally posted by @aryamccarthy in https://github.com/acl-org/acl-anthology/issues/170#issuecomment-507788799_\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                    \"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"}], "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                        \"/volumes/{}/\".format(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"}]}