feat: Improve adventure story text parsing and keyword extraction
Text Processing Improvements: - Better separation of keywords from actual story text - Extract standalone keywords before <br><br> patterns - Remove keywords from main text display to show only story content - Handle both **keyword** patterns and standalone keyword lines - Clean up multiple <br> tags for better formatting User Experience: - Keywords now display as tags above story sections - Story text shows only the narrative content without keyword clutter - Example: 'Transalpina Ciungetu Stana lui stefan <br><br> Așa am pornit...' now shows keywords as tags and only 'Așa am pornit...' as story text - Better visual separation between metadata and story content Technical: - Improved Jinja2 template logic for text parsing - Added text length and word count heuristics for keyword detection - Enhanced text cleaning and formatting - Fixed template syntax errors from previous edits
This commit is contained in:
@@ -108,33 +108,61 @@
|
||||
<div class="mb-8 pb-6 {% if not loop.last %}border-b border-gray-200{% endif %}">
|
||||
{% set section_text = section.strip() %}
|
||||
|
||||
<!-- Extract keywords from **bold** text -->
|
||||
<!-- Extract keywords and clean text -->
|
||||
{% set keywords = [] %}
|
||||
{% set clean_text = section_text %}
|
||||
|
||||
<!-- Simple keyword extraction for **word** patterns -->
|
||||
<!-- Process **keyword** patterns and standalone keywords -->
|
||||
{% if '**' in section_text %}
|
||||
{% set parts = section_text.split('**') %}
|
||||
{% set clean_parts = [] %}
|
||||
{% for i in range(parts|length) %}
|
||||
{% if i % 2 == 1 %}
|
||||
{% set _ = keywords.append(parts[i]) %}
|
||||
{% set _ = clean_parts.append(parts[i]) %}
|
||||
<!-- This is a keyword between ** ** -->
|
||||
{% set _ = keywords.append(parts[i].strip()) %}
|
||||
{% else %}
|
||||
<!-- This is regular text -->
|
||||
{% set _ = clean_parts.append(parts[i]) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% set clean_text = clean_parts|join('') %}
|
||||
{% set clean_text = clean_parts|join(' ')|trim %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Also extract standalone keywords (before <br><br>) -->
|
||||
{% if '<br>' in clean_text %}
|
||||
{% set text_parts = clean_text.split('<br>') %}
|
||||
{% set first_part = text_parts[0].strip() %}
|
||||
|
||||
<!-- If first part looks like keywords (short words), extract them -->
|
||||
{% if first_part and first_part|length < 100 and ' ' in first_part %}
|
||||
{% set potential_keywords = first_part.split() %}
|
||||
{% if potential_keywords|length <= 5 %}
|
||||
<!-- Likely keywords, add them and remove from text -->
|
||||
{% for kw in potential_keywords %}
|
||||
{% if kw.strip() %}
|
||||
{% set _ = keywords.append(kw.strip()) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<!-- Keep only text after the first <br><br> -->
|
||||
{% set remaining_parts = text_parts[1:] %}
|
||||
{% set clean_text = remaining_parts|join('<br>')|trim %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Clean up multiple <br> tags -->
|
||||
{% set clean_text = clean_text.replace('<br><br><br>', '<br><br>').replace('<br> <br>', '<br><br>').strip() %}
|
||||
|
||||
<!-- Section Keywords -->
|
||||
{% if keywords %}
|
||||
<div class="mb-4">
|
||||
{% for keyword in keywords %}
|
||||
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-gradient-to-r from-amber-500 to-orange-500 text-white mr-2 mb-2">
|
||||
<i class="fas fa-tag mr-1 text-xs"></i>
|
||||
{{ keyword }}
|
||||
</span>
|
||||
{% if keyword.strip() %}
|
||||
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-gradient-to-r from-amber-500 to-orange-500 text-white mr-2 mb-2">
|
||||
<i class="fas fa-tag mr-1 text-xs"></i>
|
||||
{{ keyword.strip() }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user