Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪲 attempt to fix 2 columns adventures #5485

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,18 +1748,12 @@ def get_specific_adventure(name, level, mode):
return utils.error_page(error=404, ui_message=gettext('no_such_adventure'))

adventure["content"] = safe_format(adventure.get("content", ""), **hedy_content.KEYWORDS.get(g.keyword_lang))
if "formatted_content" in adventure:
adventure['formatted_content'] = safe_format(adventure['formatted_content'],
**hedy_content.KEYWORDS.get(g.keyword_lang))
customizations["teachers_adventure"] = True

current_adventure = Adventure(
id=adventure["id"],
author=adventure["creator"],
short_name="level",
name=adventure["name"],
image=adventure.get("image", None),
text=adventure["content"],
is_teacher_adventure=True,
is_command_adventure=False,
save_name=f"{name} {level}")
current_adventure = Adventure.from_teacher_adventure_database_row(adventure)

adventures.append(current_adventure)
prev_level, next_level = utils.find_prev_next_levels(customizations["available_levels"], level)
Expand Down
4 changes: 2 additions & 2 deletions templates/incl/adventure-tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
>
<div class="lg:flex lg:flex-row {% if adventure.is_teacher_adventure %}teacher-adv{% endif %}">
<div class="w-full {% if adventure.example_code or adventure.is_teacher_adventure %}lg:w-1/2 {% endif %} p-2 ltr:mr-2 rtl:ml-2">
{{ adventure.text|commonmark }}
{% if adventure.is_teacher_adventure %}{{ adventure.text|safe }}{% else %}{{ adventure.text|commonmark }}{% endif %}
</div>
{% if adventure.example_code %}
<div class="border"></div>
<div class="lg:w-1/2 w-full p-2 ltr:ml-2 rtl:mr-2">
{{ adventure.example_code|commonmark }}
{% if adventure.is_teacher_adventure %}{{ adventure.example_code|safe }}{% else %}{{ adventure.example_code|commonmark }}{% endif %}
</div>
{% endif %}
{% if public_adventures_page %}
Expand Down
13 changes: 10 additions & 3 deletions website/frontend_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ def halve_adventure_content(content, max_char_length=750):
example_code = ""
if len(text_without_tags) > max_char_length:
# Split text at a suitable breaking point
split_index = content.find('</p>', len(text_without_tags)//2) # Find a closing paragraph tag.
split_index = -1
chosen_tag = None
for t in ["pre", "p"]:
split_index = content.find(f'</{t}>', len(text_without_tags)//2) # Find a closing paragraph tag.
if split_index:
chosen_tag = t
break
if split_index > -1:
text = content[:split_index]
example_code = content[split_index:]
# since we find the first occurence of </chosen_tag>, we append: / + > + 1 (to start from next char) = 3
text = content[:split_index + len(chosen_tag) + 3]
example_code = content[split_index + len(chosen_tag) + 3:]
else:
# If no suitable split point found, don't truncate content
text = content
Expand Down
Loading