Refactor PostParser to remove CSS styles and streamline reactions and views formatting
This commit is contained in:
+16
-58
@@ -306,42 +306,6 @@ class PostParser:
|
||||
html_content = []
|
||||
data = self.process_message(message)['html']
|
||||
|
||||
# Add CSS styles
|
||||
html_content.append('''
|
||||
<style>
|
||||
.message-footer {
|
||||
margin-top: 10px;
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
}
|
||||
.reactions-views {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.reaction {
|
||||
margin-right: 5px;
|
||||
}
|
||||
.spacer {
|
||||
display: inline-block;
|
||||
width: 1em;
|
||||
}
|
||||
.date-links {
|
||||
margin: 5px 0;
|
||||
}
|
||||
.date-links a {
|
||||
margin-right: 1em;
|
||||
color: #0088cc;
|
||||
text-decoration: none;
|
||||
}
|
||||
.date-links a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.flags {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
</style>
|
||||
''')
|
||||
|
||||
html_content.append(f'<div class="message-header">{data["header"]}</div>')
|
||||
html_content.append(f'<div class="message-media">{data["media"]}</div>')
|
||||
html_content.append(f'<div class="message-text">{data["body"]}</div>')
|
||||
@@ -361,7 +325,7 @@ class PostParser:
|
||||
|
||||
flags = self._extract_flags(message)
|
||||
if flags:
|
||||
return f'<span class="flags">🏷 {", ".join(flags)}</span>'
|
||||
return f'🏷 {" 🏷".join(flags)}'
|
||||
return ''
|
||||
|
||||
def process_message(self, message: Message) -> Dict[Any, Any]:
|
||||
@@ -611,7 +575,6 @@ class PostParser:
|
||||
try:
|
||||
parts = []
|
||||
|
||||
# First line: reactions and views
|
||||
reactions_html = ""
|
||||
views_html = ""
|
||||
if reactions := getattr(message, "reactions", None):
|
||||
@@ -619,24 +582,24 @@ class PostParser:
|
||||
# Replace None or empty emoji with replacement character
|
||||
emoji = reaction.emoji
|
||||
if emoji is None or emoji == "None" or emoji == "":
|
||||
emoji = "��" # Question mark as replacement for missing emojis
|
||||
reactions_html += f'<span class="reaction">{emoji} {reaction.count}</span>'
|
||||
reactions_html = reactions_html.rstrip()
|
||||
emoji = "�" # Question mark as replacement for missing emojis
|
||||
reactions_html += f'{emoji} {reaction.count} '
|
||||
reactions_html = reactions_html.strip()
|
||||
|
||||
if views := getattr(message, "views", None):
|
||||
views_html = f'<span class="views">👁 {views}</span>'
|
||||
views_html = f'{views} 👁'
|
||||
|
||||
# Combine reactions and views with proper spacing
|
||||
# Combine reactions and views on the same line
|
||||
if reactions_html or views_html:
|
||||
parts.append(f'<div class="reactions-views">{reactions_html} <span class="spacer"></span> {views_html}</div>')
|
||||
parts.append(f'{reactions_html} | {views_html}')
|
||||
|
||||
# Second line: date and links
|
||||
# Add date and links on the same line
|
||||
second_line_parts = []
|
||||
|
||||
# Format date as DD/MM/YY, HH:MM:SS
|
||||
if message.date:
|
||||
formatted_date = message.date.strftime("%d/%m/%y, %H:%M:%S")
|
||||
second_line_parts.append(f'<span class="date">{formatted_date}</span>')
|
||||
second_line_parts.append(formatted_date)
|
||||
|
||||
# Add links
|
||||
channel_identifier = self.get_channel_username(message)
|
||||
@@ -646,25 +609,20 @@ class PostParser:
|
||||
|
||||
if channel_identifier.startswith('-100'): # For channels with only ID
|
||||
channel_id = channel_identifier[4:] # Remove '-100' prefix for web links
|
||||
links.append(f'<a href="tg://resolve?domain=c/{channel_id}&post={message.id}">Open in Telegram</a>')
|
||||
links.append(f'<a href="https://t.me/c/{channel_id}/{message.id}">Open in Web</a>')
|
||||
links.append(f'Open in Telegram')
|
||||
links.append(f'Open in Web')
|
||||
else: # For channels with username
|
||||
links.append(f'<a href="tg://resolve?domain={channel_identifier}&post={message.id}">Open in Telegram</a>')
|
||||
links.append(f'<a href="https://t.me/{channel_identifier}/{message.id}">Open in Web</a>')
|
||||
links.append(f'Open in Telegram')
|
||||
links.append(f'Open in Web')
|
||||
if Config['show_bridge_link']:
|
||||
token = Config['token']
|
||||
links.append(f'<a href="{base_url}/html/{channel_identifier}/{message.id}?token={token}&debug=true">Open in Bridge</a>')
|
||||
links.append(f'Open in Bridge')
|
||||
second_line_parts.extend(links)
|
||||
|
||||
if second_line_parts:
|
||||
spacer = " <span class=\"spacer\"></span> "
|
||||
parts.append(f'<div class="date-links">{spacer.join(second_line_parts)}</div>')
|
||||
parts.append(' | '.join(second_line_parts))
|
||||
|
||||
# Third line: flags (if any)
|
||||
if flags := self._format_flags(message):
|
||||
parts.append(f'<div class="flags">{flags}</div>')
|
||||
|
||||
result_html = '\n'.join(parts) if parts else None
|
||||
result_html = '<br>'.join(parts) if parts else None
|
||||
return self._sanitize_html(result_html) if result_html else None
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user