Smarter generation of OGP/Schema.org/etc. metadata, with HTML tags stripped out so the result looks nice and clean
This commit is contained in:
parent
b8a74443c9
commit
ea241577f1
3 changed files with 17 additions and 4 deletions
|
@ -13,7 +13,7 @@ from model_utils.models import TimeStampedModel
|
|||
from users.models import Profile
|
||||
|
||||
from . import kinds
|
||||
from lemoncurry import requests
|
||||
from lemoncurry import requests, utils
|
||||
ENTRY_KINDS = [(k.id, k.id) for k in kinds.all]
|
||||
|
||||
|
||||
|
@ -98,12 +98,12 @@ class Entry(ModelMeta, TimeStampedModel):
|
|||
def title(self):
|
||||
if self.name:
|
||||
return self.name
|
||||
return shorten(self.paragraphs[0], width=100, placeholder='…')
|
||||
return shorten(utils.to_plain(self.paragraphs[0]), width=100, placeholder='…')
|
||||
|
||||
@property
|
||||
def excerpt(self):
|
||||
try:
|
||||
return self.paragraphs[0 if self.name else 1]
|
||||
return utils.to_plain(self.paragraphs[0 if self.name else 1])
|
||||
except IndexError:
|
||||
return ' '
|
||||
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
import html
|
||||
import json
|
||||
from accept_types import get_best_match
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.http import HttpResponseForbidden, HttpResponseBadRequest
|
||||
from django.utils.html import strip_tags
|
||||
from os.path import join
|
||||
from shorturls import default_converter as converter
|
||||
from shorturls.templatetags.shorturl import ShortURL
|
||||
from types import SimpleNamespace
|
||||
from urllib.parse import urlencode, urljoin
|
||||
|
||||
from .templatetags.markdown import markdown
|
||||
|
||||
cache = SimpleNamespace(package_json=None)
|
||||
|
||||
|
||||
|
@ -63,3 +67,7 @@ def bad_req(message):
|
|||
|
||||
def forbid(message):
|
||||
return HttpResponseForbidden(message, content_type='text/plain')
|
||||
|
||||
|
||||
def to_plain(md):
|
||||
return html.unescape(strip_tags(markdown(md)))
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.contrib.sites.models import Site as DjangoSite
|
|||
from django.utils.functional import cached_property
|
||||
from meta.models import ModelMeta
|
||||
from urllib.parse import urljoin
|
||||
from lemoncurry import utils
|
||||
|
||||
|
||||
def avatar_path(instance, name):
|
||||
|
@ -45,6 +46,10 @@ class User(ModelMeta, AbstractUser):
|
|||
def get_absolute_url(self):
|
||||
return self.url
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return utils.to_plain(self.note)
|
||||
|
||||
@property
|
||||
def avatar_url(self):
|
||||
return self.avatar.url
|
||||
|
@ -81,7 +86,7 @@ class User(ModelMeta, AbstractUser):
|
|||
|
||||
_metadata = {
|
||||
'image': 'avatar_url',
|
||||
'description': 'note',
|
||||
'description': 'description',
|
||||
'og_type': 'profile',
|
||||
'og_profile_id': 'facebook_id',
|
||||
'twitter_creator': 'twitter_username',
|
||||
|
|
Loading…
Reference in a new issue