Remove code line numbers in RSS

This commit is contained in:
Gabriel Augendre 2021-04-10 15:41:50 +02:00
parent eb4c4330f7
commit fc7b14192c
4 changed files with 20 additions and 7 deletions

View file

@ -15,7 +15,8 @@ from django.utils import timezone
from articles.utils import (
build_full_absolute_url,
format_article_content,
format_article_content_for_html,
format_article_content_for_rss,
get_html_to_text_converter,
truncate_words_after_char_count,
)
@ -94,7 +95,11 @@ class Article(models.Model):
@cached_property
def get_formatted_content(self):
return format_article_content(self.content)
return format_article_content_for_html(self.content)
@cached_property
def get_formatted_content_for_rss(self):
return format_article_content_for_rss(self.content)
def publish(self):
if not self.published_at:

View file

@ -3,7 +3,7 @@ from django.test import Client
from django.urls import reverse
from articles.models import Article
from articles.utils import format_article_content
from articles.utils import format_article_content_for_html
@pytest.mark.django_db
@ -42,7 +42,7 @@ def test_render_article_change_content(published_article: Article, client: Clien
api_res = post_article(client, published_article, preview_content)
assert api_res.status_code == 200
api_content = api_res.content.decode("utf-8") # type: str
html_preview_content = format_article_content(preview_content)
html_preview_content = format_article_content_for_html(preview_content)
assert html_preview_content in api_content

View file

@ -15,12 +15,20 @@ def build_full_absolute_url(request, url):
return (settings.BLOG["base_url"] + url)[::-1].replace("//", "/", 1)[::-1]
def format_article_content(content):
def format_article_content_for_rss(content):
return _format_article_content(content, linenums=False)
def format_article_content_for_html(content):
return _format_article_content(content, linenums=True)
def _format_article_content(content, linenums: bool):
md = markdown.Markdown(
extensions=[
"extra",
"admonition",
CodeHiliteExtension(linenums=True, guess_lang=False),
CodeHiliteExtension(linenums=linenums, guess_lang=False),
LazyLoadingImageExtension(),
]
)

View file

@ -19,7 +19,7 @@ class CompleteFeed(Feed):
return self.get_queryset(obj)[: self.FEED_LIMIT]
def item_description(self, item: Article):
return item.get_formatted_content
return item.get_formatted_content_for_rss
def item_pubdate(self, item: Article):
return item.published_at