Commit f76061b
Corentin Smith
aider: Refactored the part that builds the update and attachments markdown into a new function
# Aider chat conversation:
USER: refactor the part that builds the update and attachments markdown into a new function render_update()
ASSISTANT: Here are the changes to refactor the part that builds the update and attachments markdown into a new function `render_update()`:
1. Define the new function `render_update()`.
2. Replace the existing code that builds the update and attachments markdown with a call to `render_update()`.
build.py
```python
<<<<<<< SEARCH
def build_website(layout):
=======
def render_update(created_at, content, attachment_urls):
"""Render the markdown for a single update with attachments."""
md = f"## {created_at}\n\n{content}\n\n"
if attachment_urls:
for url in attachment_urls.split(","):
md += f"\n\n"
return md
>>>>>>> REPLACE
```
build.py
```python
<<<<<<< SEARCH
md = f"# {title}\n\n{description}\n\n"
updates = get_updates(project_id)
print(project_id, updates)
for created_at, content, attachment_urls in updates:
print(f" - update {created_at}")
md += f"## {created_at}\n\n{content}\n\n"
if not attachment_urls:
continue
for url in attachment_urls.split(","):
print(f" - attachment {url}")
md += f"\n\n"
html = render_markdown(md, layout)
save_html(slug, html, subdirectory="projects")
=======
md = f"# {title}\n\n{description}\n\n" + "".join(
render_update(created_at, content, attachment_urls)
for created_at, content, attachment_urls in get_updates(project_id)
)
html = render_markdown(md, layout)
save_html(slug, html, subdirectory="projects")
>>>>>>> REPLACE
```
build.py
```python
<<<<<<< SEARCH
for created_at, content in updates:
log_md += f"## {created_at}\n\n{content}\n\n"
for url in attachment_urls.split(","):
print(f" - attachment {url}")
md += f"\n\n"
=======
for created_at, content, attachment_urls in updates:
log_md += render_update(created_at, content, attachment_urls)
>>>>>>> REPLACE
```
USER:
# Fix any errors below, if possible.
## Running: flake8 --select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated build.py
build.py:185:5: F821 undefined name 'build_website'
build_website(layout)
^
## See relevant line below marked with █.
build.py:
...⋮...
167│if __name__ == "__main__":
168│ parser = argparse.ArgumentParser(
169│ description="Build and serve a static website with live reloading."
...⋮...
182│ args = parser.parse_args()
183│
184│ layout = load_layout(args.dev)
185█ build_website(layout)
186│
187│ if args.serve:
188│ serve_website(args.port)
ASSISTANT: To fix the error, we need to define the `build_website` function. It seems that the function was not defined in the provided code. Let's define it and ensure it includes the logic for building the website.
build.py
```python
<<<<<<< SEARCH
def render_update(created_at, content, attachment_urls):
"""Render the markdown for a single update with attachments."""
md = f"## {created_at}\n\n{content}\n\n"
if attachment_urls:
for url in attachment_urls.split(","):
md += f"\n\n"
return md
=======
def render_update(created_at, content, attachment_urls):
"""Render the markdown for a single update with attachments."""
md = f"## {created_at}\n\n{content}\n\n"
if attachment_urls:
for url in attachment_urls.split(","):
md += f"\n\n"
return md
def build_website(layout):
shutil.rmtree(BUILD_DIR, ignore_errors=True)
# copy static files
for static_dir in STATIC_DIRS:
shutil.copytree(
os.path.join(SOURCE_DIR, static_dir), os.path.join(BUILD_DIR, static_dir)
)
# build "static" pages
pages = get_pages()
for slug, content in pages:
print(f"rendering {slug}")
html = render_markdown(content, layout)
save_html(slug, html)
# build project pages
projects = get_projects()
project_links = []
for project_id, title, slug, description, image in projects:
print(f"rendering {slug}")
md = f"# {title}\n\n{description}\n\n" + "".join(
render_update(created_at, content, attachment_urls)
for created_at, content, attachment_urls in get_updates(project_id)
)
html = render_markdown(md, layout)
save_html(slug, html, subdirectory="projects")
# project index page
for project_id, title, slug, description, image in projects:
project_links.append(
f"""## [{title}]({slug}.html)\n\n<a href="{slug}.html"><img class="project-cover" src="{image}"/></a>\n"""
)
project_list = "".join(project_links)
project_index_md = f"# Projects\n\n{project_list}"
project_index_html = render_markdown(project_index_md, layout)
save_html("index", project_index_html, subdirectory="projects")
# build log page
updates = get_latest_updates(20)
log_md = "# Build log\n\n"
for created_at, content, attachment_urls in updates:
log_md += render_update(created_at, content, attachment_urls)
log_html = render_markdown(log_md, layout)
save_html("index", log_html, subdirectory="build-log")
>>>>>>> REPLACE
```render_update().1 parent 5905825 commit f76061b
1 file changed
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
91 | 138 | | |
92 | 139 | | |
93 | 140 | | |
| |||
0 commit comments