Replies: 2 comments 3 replies
-
Hi @Andre601, Your code is quite understandable. There are not a lot of lines to generate in your output string so I don't think that "optimizing" code execution is really an issue. Perhaps, if you want to make your code more "pythonic", you can make incremental improvements:
strings = [f"<span class=\"invslot-item slot{slot}\" data-minetip-title=\"",
item_data["title"] if "title" in item_data else "Unknown Item",
'\"']
result = "\n".join(strings)
for num in range(1, 10):
strings.append("""{get_slot_html(recipe[f"slot{num}"], items, num)}""") I hope this helps. |
Beta Was this translation helpful? Give feedback.
3 replies
-
💡 As a general note, it is good news that writing macros for Mkdocs can be a motivation for learning Python. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've made a macros that automatically generates the necessary HTML in a page to depict crafting recipes based on data retrieved via a JSON file.
While the stuff works as intended do I know for a fact that my macros isn't the most efficient or easy to follow thing (primarely due to my lack of Python coding knowledge), so I now ask for some help in improving it wherever possible.
I first want to give context of what the macros generates.
Here is an example HTML that it generates:
And this would be the resulting content:

Finally is here the full
macros.py
file I currently have:Apreciate any help to improve this mess.
I'm also open for help with the JS and CSS used (This stuff isn't from me, so I have even less ideas what can/should be improved). Let me know if you want to see that stuff too.
Edit
Adding the JSON used as well, so that you can see the structure it has. Preferrably would I like to be able to remove as much as possible (i.e. be able to ommit empty values altogether).
Beta Was this translation helpful? Give feedback.
All reactions