|
20 | 20 | from psc.resources import Resources |
21 | 21 | from psc.resources import get_resources |
22 | 22 |
|
23 | | - |
24 | 23 | templates = Jinja2Templates(directory=HERE / "templates") |
25 | 24 |
|
26 | 25 |
|
@@ -61,6 +60,40 @@ async def gallery(request: Request) -> _TemplateResponse: |
61 | 60 | ) |
62 | 61 |
|
63 | 62 |
|
| 63 | +async def authors(request: Request) -> _TemplateResponse: |
| 64 | + """Handle the author listing page.""" |
| 65 | + these_authors: Iterator[Example] = request.app.state.resources.authors.values() |
| 66 | + root_path = ".." |
| 67 | + |
| 68 | + return templates.TemplateResponse( |
| 69 | + "authors.jinja2", |
| 70 | + dict( |
| 71 | + title="Authors", |
| 72 | + authors=these_authors, |
| 73 | + root_path=root_path, |
| 74 | + request=request, |
| 75 | + ), |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +async def author(request: Request) -> _TemplateResponse: |
| 80 | + """Handle an author page.""" |
| 81 | + author_path = PurePath(request.path_params["author_name"]) |
| 82 | + resources: Resources = request.app.state.resources |
| 83 | + this_author = resources.authors[author_path] |
| 84 | + root_path = "../../.." |
| 85 | + |
| 86 | + return templates.TemplateResponse( |
| 87 | + "example.jinja2", |
| 88 | + dict( |
| 89 | + title=this_author.title, |
| 90 | + body=this_author.body, |
| 91 | + request=request, |
| 92 | + root_path=root_path, |
| 93 | + ), |
| 94 | + ) |
| 95 | + |
| 96 | + |
64 | 97 | async def example(request: Request) -> _TemplateResponse: |
65 | 98 | """Handle an example page.""" |
66 | 99 | example_path = PurePath(request.path_params["example_name"]) |
@@ -113,6 +146,9 @@ async def content_page(request: Request) -> _TemplateResponse: |
113 | 146 | Route("/favicon.png", favicon), |
114 | 147 | Route("/gallery/index.html", gallery), |
115 | 148 | Route("/gallery", gallery), |
| 149 | + Route("/authors/index.html", authors), |
| 150 | + Route("/authors", authors), |
| 151 | + Route("/authors/{author_name}.html", author), |
116 | 152 | Route("/gallery/examples/{example_name}/index.html", example), |
117 | 153 | Route("/gallery/examples/{example_name}/", example), |
118 | 154 | Route("/pages/{page_name}.html", content_page), |
|
0 commit comments