feat: better meta description for thread page
This commit is contained in:
parent
15a9bf5953
commit
b9bcdf7264
2 changed files with 9 additions and 2 deletions
|
@ -6,8 +6,8 @@
|
||||||
<title>{{ app.title }}</title>
|
<title>{{ app.title }}</title>
|
||||||
<meta name="theme-color" content="#3054bf">
|
<meta name="theme-color" content="#3054bf">
|
||||||
{% if threads|length == 1 %}
|
{% if threads|length == 1 %}
|
||||||
<meta name="description" content="{{ threads[0].content }}" />
|
<meta name="description" content="{{ threads[0].content_text }}" />
|
||||||
<meta property="og:description" content="{{ threads[0].content }}" />
|
<meta property="og:description" content="{{ threads[0].content_text }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
<meta name="description" content="{{ app.description }}" />
|
<meta name="description" content="{{ app.description }}" />
|
||||||
<meta property="og:description" content="{{ app.description }}" />
|
<meta property="og:description" content="{{ app.description }}" />
|
||||||
|
|
|
@ -2,6 +2,7 @@ from flask import Blueprint, render_template
|
||||||
import requests
|
import requests
|
||||||
import datetime
|
import datetime
|
||||||
import markdown
|
import markdown
|
||||||
|
import re
|
||||||
|
|
||||||
threads = Blueprint('threads', __name__, template_folder='template')
|
threads = Blueprint('threads', __name__, template_folder='template')
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ def home():
|
||||||
def thread(id):
|
def thread(id):
|
||||||
if id in thread_ids:
|
if id in thread_ids:
|
||||||
status = fetch_thread(id)
|
status = fetch_thread(id)
|
||||||
|
status['content_text'] = clean_html(status['content']).strip()
|
||||||
return render_template('threads.html', threads=[status], app=app, attribution=attribution)
|
return render_template('threads.html', threads=[status], app=app, attribution=attribution)
|
||||||
else:
|
else:
|
||||||
return '<h1>Not Found</h1><p>¯\_(ツ)_/¯</p><a href="/">go home</a>', 404
|
return '<h1>Not Found</h1><p>¯\_(ツ)_/¯</p><a href="/">go home</a>', 404
|
||||||
|
@ -95,3 +97,8 @@ def clean_status(status):
|
||||||
def clean_dict(dict, keys):
|
def clean_dict(dict, keys):
|
||||||
return {k: dict[k] for k in keys}
|
return {k: dict[k] for k in keys}
|
||||||
|
|
||||||
|
CLEANR = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
|
||||||
|
|
||||||
|
def clean_html(raw_html):
|
||||||
|
cleantext = re.sub(CLEANR, '', raw_html)
|
||||||
|
return cleantext
|
||||||
|
|
Loading…
Reference in a new issue