fix read time for M1 macs
This commit is contained in:
parent
f30b8ec975
commit
f63673ed63
1 changed files with 8 additions and 3 deletions
|
@ -16,6 +16,7 @@ from django.db.models import F, Prefetch
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
from articles.utils import (
|
from articles.utils import (
|
||||||
build_full_absolute_url,
|
build_full_absolute_url,
|
||||||
|
@ -132,9 +133,13 @@ class Article(models.Model):
|
||||||
|
|
||||||
def get_read_time(self) -> int:
|
def get_read_time(self) -> int:
|
||||||
content = self.get_formatted_content
|
content = self.get_formatted_content
|
||||||
if content:
|
if not content:
|
||||||
return readtime.of_markdown(content).minutes
|
return 0
|
||||||
return 0
|
try:
|
||||||
|
return readtime.of_html(content).minutes
|
||||||
|
except etree.Error:
|
||||||
|
# Needed for compatibility with M1 Macs
|
||||||
|
return 0
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def get_related_articles(self) -> Sequence[Article]:
|
def get_related_articles(self) -> Sequence[Article]:
|
||||||
|
|
Reference in a new issue