You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
# Zxy导入Django的用户模型
|
|
from django.contrib.auth import get_user_model
|
|
# Zxy导入Django的Feed视图
|
|
from django.contrib.syndication.views import Feed
|
|
# Zxy导入Django的时区工具
|
|
from django.utils import timezone
|
|
# Zxy导入RSS 2.0 Feed生成器
|
|
from django.utils.feedgenerator import Rss201rev2Feed
|
|
|
|
# Zxy导入项目中的文章模型
|
|
from blog.models import Article
|
|
# Zxy导入Markdown工具
|
|
from djangoblog.utils import CommonMarkdown
|
|
|
|
# Zxy定义Django博客Feed
|
|
class DjangoBlogFeed(Feed):
|
|
feed_type = Rss201rev2Feed # Zxy使用RSS 2.0格式
|
|
|
|
description = '大巧无工,重剑无锋.' # ZxyFeed描述
|
|
title = "且听风吟 大巧无工,重剑无锋." # ZxyFeed标题
|
|
link = "/feed/" # ZxyFeed链接
|
|
|
|
# Zxy获取作者名称
|
|
def author_name(self):
|
|
return get_user_model().objects.first().nickname
|
|
|
|
# Zxy获取作者链接
|
|
def author_link(self):
|
|
return get_user_model().objects.first().get_absolute_url()
|
|
|
|
# Zxy获取Feed项
|
|
def items(self):
|
|
return Article.objects.filter(type='a', status='p').order_by('-pub_time')[:5] # Zxy获取最近5篇已发布的文章
|
|
|
|
# Zxy获取Feed项标题
|
|
def item_title(self, item):
|
|
return item.title
|
|
|
|
# Zxy获取Feed项描述
|
|
def item_description(self, item):
|
|
return CommonMarkdown.get_markdown(item.body) # Zxy将文章内容转换为Markdown格式
|
|
|
|
# Zxy获取Feed版权信息
|
|
def feed_copyright(self):
|
|
now = timezone.now()
|
|
return "Copyright© {year} 且听风吟".format(year=now.year) # Zxy动态生成版权年份
|
|
|
|
# Zxy获取Feed项链接
|
|
def item_link(self, item):
|
|
return item.get_absolute_url()
|
|
|
|
# Zxy获取Feed项GUID
|
|
def item_guid(self, item):
|
|
return |