SomethingGeneric / flaskpress

Wordpress but it's actually Python + Flask
GNU General Public License v3.0
0 stars 0 forks source link

Sweep (slow): Use Mistune to render markdown content and serve through flask #4

Closed SomethingGeneric closed 1 year ago

SomethingGeneric commented 1 year ago

Details

Ideally, the code will load pages from a directory, maybe "pages/", and render them using mistune, to return at a dynamically-named flask endpoint.

Checklist - [X] `requirements.txt` > • Add Mistune to the list of required packages. - [X] `main.py` > • Import os and mistune at the top of the file. > • Create a new function named `load_and_parse_md` that takes a filename as an argument. This function should use os to load the file from the "pages/" directory and Mistune to parse the markdown content into HTML. > • Create a new Flask route that takes a filename as a dynamic part of the route. This route should call the `load_and_parse_md` function with the filename and return the resulting HTML. - [X] `tests/test_main.py` > • Import pytest, flask, and the main module at the top of the file. > • Write a test function named `test_load_and_parse_md` that tests the `load_and_parse_md` function. This test should check that the function correctly loads and parses a markdown file. > • Write a test function named `test_dynamic_route` that tests the new dynamic route. This test should check that the route correctly serves the parsed markdown content.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/SomethingGeneric/flaskpress/pull/5.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/SomethingGeneric/flaskpress/blob/c3ff0dc14ac9fb7d530ebade0af1bc47dfaec97b/README.md#L1-L1 https://github.com/SomethingGeneric/flaskpress/blob/c3ff0dc14ac9fb7d530ebade0af1bc47dfaec97b/sweep.yaml#L1-L13 https://github.com/SomethingGeneric/flaskpress/blob/c3ff0dc14ac9fb7d530ebade0af1bc47dfaec97b/requirements.txt#L1-L2 https://github.com/SomethingGeneric/flaskpress/blob/c3ff0dc14ac9fb7d530ebade0af1bc47dfaec97b/main.py#L1-L48 https://github.com/SomethingGeneric/flaskpress/blob/c3ff0dc14ac9fb7d530ebade0af1bc47dfaec97b/LICENSE#L1-L306

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
requirements.txt Modify requirements.txt with contents:
• Add Mistune to the list of required packages.
main.py Modify main.py with contents:
• Import os and mistune at the top of the file.
• Create a new function named load_and_parse_md that takes a filename as an argument. This function should use os to load the file from the "pages/" directory and Mistune to parse the markdown content into HTML.
• Create a new Flask route that takes a filename as a dynamic part of the route. This route should call the load_and_parse_md function with the filename and return the resulting HTML.
tests/test_main.py Create tests/test_main.py with contents:
• Import pytest, flask, and the main module at the top of the file.
• Write a test function named test_load_and_parse_md that tests the load_and_parse_md function. This test should check that the function correctly loads and parses a markdown file.
• Write a test function named test_dynamic_route that tests the new dynamic route. This test should check that the route correctly serves the parsed markdown content.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add Mistune support for rendering markdown content sweep/mistune-support

Description

This PR adds support for rendering markdown content using Mistune and serving it through Flask. It introduces a new function to load and parse markdown files, sets up a dynamic route to serve the parsed markdown content, and includes tests to ensure the new feature works as expected.

Summary of Changes

  • Added Mistune to the requirements.txt file to ensure it's installed when setting up the project.
  • Created a new function, load_and_parse_md, to load and parse markdown files using Mistune.
  • Set up a new dynamic route in Flask that serves the parsed markdown content. The endpoint is named based on the name of the markdown file.
  • Added tests to cover the new functionality, including testing the load_and_parse_md function and the dynamic route.

Please review and merge this PR to enable rendering markdown content in flaskpress.


Step 4: ⌨️ Coding

File Instructions Progress Error logs
requirements.txt Modify requirements.txt with contents:
• Add Mistune to the list of required packages.
✅ Commit 410053c ```
Cloning into 'flaskpress'...
remote: Not Found
fatal: repository 'https://github.com/flaskpress.git/' not found
```
main.py Modify main.py with contents:
• Import os and mistune at the top of the file.
• Create a new function named load_and_parse_md that takes a filename as an argument. This function should use os to load the file from the "pages/" directory and Mistune to parse the markdown content into HTML.
• Create a new Flask route that takes a filename as a dynamic part of the route. This route should call the load_and_parse_md function with the filename and return the resulting HTML.
✅ Commit d014c2a ```
Cloning into 'flaskpress'...
remote: Not Found
fatal: repository 'https://github.com/flaskpress.git/' not found
```
tests/test_main.py Create tests/test_main.py with contents:
• Import pytest, flask, and the main module at the top of the file.
• Write a test function named test_load_and_parse_md that tests the load_and_parse_md function. This test should check that the function correctly loads and parses a markdown file.
• Write a test function named test_dynamic_route that tests the new dynamic route. This test should check that the route correctly serves the parsed markdown content.
✅ Commit e3fe345 No errors. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/mistune-support.

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. Join Our Discord

SomethingGeneric commented 1 year ago

Nice work! Please just add a small block to make sure that the pages directory exists on startup, and create it if not