Skip to content

Commit

Permalink
🪲 attempt to fix 2 columns adventures (#5485)
Browse files Browse the repository at this point in the history
Fixes #5473
  • Loading branch information
hasan-sh authored May 7, 2024
1 parent b9e7122 commit 438b920
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
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

0 comments on commit 438b920

Please sign in to comment.