Добавил rss

This commit is contained in:
NikDizell 2026-03-08 17:16:37 +03:00
parent cd2001125f
commit d21f847bd7
3 changed files with 32 additions and 0 deletions

23
blog/feeds.py Normal file
View File

@ -0,0 +1,23 @@
from django.contrib.syndication.views import Feed
from django.urls import reverse
from .models import Article
class LatestArticlesFeed(Feed):
title = "Блог программиста 1ССНА Технологии"
description = "Свежие статьи о 1С, автоматизации и разработке"
link = "/blog/"
def items(self):
# Возвращаем последние 10 опубликованных статей
return Article.objects.filter(is_published=True).order_by('-time_create')[:10]
def item_title(self, item):
return item.title
def item_description(self, item):
# Краткое описание (можно первые 200 символов контента)
return item.content[:200] + ""
def item_link(self, item):
return reverse('blog:article_detail', args=[item.slug])

View File

@ -1,4 +1,6 @@
from django.urls import path from django.urls import path
from blog.feeds import LatestArticlesFeed
from . import views from . import views
app_name = 'blog' app_name = 'blog'
@ -6,6 +8,7 @@ app_name = 'blog'
urlpatterns = [ urlpatterns = [
path('', views.ArticleListView.as_view(), name='article_list'), path('', views.ArticleListView.as_view(), name='article_list'),
path('category/<slug:category_slug>/', views.ArticleListView.as_view(), name='category_detail'), path('category/<slug:category_slug>/', views.ArticleListView.as_view(), name='category_detail'),
path('rss/', LatestArticlesFeed(), name='rss_feed'),
path('<slug:slug>/', views.ArticleDetailView.as_view(), name='article_detail'), path('<slug:slug>/', views.ArticleDetailView.as_view(), name='article_detail'),
path('draft/<slug:slug>/', views.ArticleDraftPreviewView.as_view(), name='draft_preview'), path('draft/<slug:slug>/', views.ArticleDraftPreviewView.as_view(), name='draft_preview'),
] ]

View File

@ -55,6 +55,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="RSS-лента блога" href="{% url 'blog:rss_feed' %}">
{% block extra_css %} {% block extra_css %}
<!-- Дополнительные CSS файлы для конкретных страниц --> <!-- Дополнительные CSS файлы для конкретных страниц -->
{% endblock %} {% endblock %}
@ -307,6 +309,10 @@
<img width="88" height="31" alt="ИКС" border="0" src="https://yandex.ru/cycounter?https://nikdizell.ru&theme=light&lang=ru"> <img width="88" height="31" alt="ИКС" border="0" src="https://yandex.ru/cycounter?https://nikdizell.ru&theme=light&lang=ru">
</a> </a>
</div> </div>
<!--
<a href="{% url 'blog:rss_feed' %}" target="_blank" rel="noopener noreferrer">
RSS подписка на статьи
</a> -->
<div class="footer-copyright"> <div class="footer-copyright">
<p>&copy; 2026 ИП Сердюк Николай Александрович. Все права защищены.</p> <p>&copy; 2026 ИП Сердюк Николай Александрович. Все права защищены.</p>