forked from 00dani/lemoncurry
Implement simple 'excerpt' feature to shorten each entry's content for syndicated preview
This commit is contained in:
parent
ecdd63b9d7
commit
4ac0bcde43
1 changed files with 12 additions and 6 deletions
|
@ -2,6 +2,7 @@ from django.contrib.auth import get_user_model
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
from textwrap import shorten
|
||||||
|
|
||||||
from meta.models import ModelMeta
|
from meta.models import ModelMeta
|
||||||
from users.models import Profile
|
from users.models import Profile
|
||||||
|
@ -39,12 +40,21 @@ class Entry(ModelMeta, models.Model):
|
||||||
updated = models.DateTimeField()
|
updated = models.DateTimeField()
|
||||||
|
|
||||||
_metadata = {
|
_metadata = {
|
||||||
'description': 'content',
|
'description': 'excerpt',
|
||||||
'image': 'image_url',
|
'image': 'image_url',
|
||||||
'twitter_creator': 'twitter_creator',
|
'twitter_creator': 'twitter_creator',
|
||||||
'og_profile_id': 'og_profile_id',
|
'og_profile_id': 'og_profile_id',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def title(self):
|
||||||
|
return self.name if self.name else self.excerpt
|
||||||
|
|
||||||
|
@property
|
||||||
|
def excerpt(self):
|
||||||
|
first_line = self.content.split('\n')[0]
|
||||||
|
return shorten(first_line, width=100, placeholder='…')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def twitter_creator(self):
|
def twitter_creator(self):
|
||||||
return self.author.twitter_username
|
return self.author.twitter_username
|
||||||
|
@ -58,11 +68,7 @@ class Entry(ModelMeta, models.Model):
|
||||||
return self.photo.url if self.photo else self.author.avatar_url
|
return self.photo.url if self.photo else self.author.avatar_url
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{kind} {id}: {content}'.format(
|
return '{0} {1}: {2}'.format(self.kind, self.id, self.title)
|
||||||
kind=self.kind,
|
|
||||||
id=self.id,
|
|
||||||
content=self.content
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
|
|
Loading…
Reference in a new issue