diff --git a/myblog/blog/models.py b/myblog/blog/models.py index c3c81bd..5a75596 100644 --- a/myblog/blog/models.py +++ b/myblog/blog/models.py @@ -30,14 +30,14 @@ class SiteSettings(models.Model): class Meta: verbose_name = "站点设置" verbose_name_plural = "站点设置" - + def __str__(self): return "站点设置" class Post(models.Model): title = models.CharField(max_length=100) - content = MDTextField() # ✅ 改成这里 + content = MDTextField() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) publish_date = models.DateTimeField(default=timezone.now) @@ -98,4 +98,4 @@ class Post(models.Model): # 将emoji shortcode转换为实际的emoji字符 html_content = emoji.emojize(html_content, language='alias') - return mark_safe(html_content) \ No newline at end of file + return mark_safe(html_content) diff --git a/myblog/blog/templates/blog/contact.html b/myblog/blog/templates/blog/contact.html index 9422353..e3af3de 100644 --- a/myblog/blog/templates/blog/contact.html +++ b/myblog/blog/templates/blog/contact.html @@ -122,7 +122,7 @@ background-color: white; padding: 5px 0; } - + .contact-info { background-color: #f9f9f9; padding: 15px; @@ -130,23 +130,23 @@ margin-top: 20px; border: 1px solid #eee; } - + .contact-info h3 { margin-top: 0; color: #333; border-bottom: 2px solid #007cba; padding-bottom: 10px; } - + .contact-info ul { padding-left: 20px; } - + .contact-info li { margin: 10px 0; color: #666; } - + /* 添加联系我主内容区域样式 */ .contact-main { background-color: #f9f9f9; @@ -154,68 +154,68 @@ border-radius: 5px; border: 1px solid #eee; } - + .contact-main h2 { color: #333; border-bottom: 2px solid #007cba; padding-bottom: 10px; } - + .contact-description { margin: 15px 0; line-height: 1.6; color: #666; } - + .contact-details { list-style: none; padding: 0; } - + .contact-details li { padding: 10px 0; border-bottom: 1px solid #eee; } - + .contact-details li:last-child { border-bottom: none; } - + .contact-label { font-weight: bold; color: #333; display: inline-block; width: 80px; } - + .contact-value { color: #666; } - + /* 添加导航栏样式 */ .top-nav { background-color: #007cba; padding: 10px 0; margin-bottom: 20px; } - + .nav-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; } - + .nav-links { list-style: none; padding: 0; margin: 0; display: flex; } - + .nav-links li { margin-right: 20px; } - + .nav-links li a { color: white; text-decoration: none; @@ -223,7 +223,7 @@ border-radius: 4px; transition: background-color 0.3s; } - + .nav-links li a:hover { background-color: rgba(255, 255, 255, 0.2); } @@ -287,31 +287,31 @@
如果您有任何问题或想与我交流,可以通过以下方式联系我:
- + diff --git a/myblog/blog/templates/blog/detail.html b/myblog/blog/templates/blog/detail.html index 3b4699b..88681b9 100644 --- a/myblog/blog/templates/blog/detail.html +++ b/myblog/blog/templates/blog/detail.html @@ -159,31 +159,31 @@ background-color: white; padding: 5px 0; } - + /* 添加导航栏样式 */ .top-nav { background-color: #007cba; padding: 10px 0; margin-bottom: 20px; } - + .nav-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; } - + .nav-links { list-style: none; padding: 0; margin: 0; display: flex; } - + .nav-links li { margin-right: 20px; } - + .nav-links li a { color: white; text-decoration: none; @@ -191,7 +191,7 @@ border-radius: 4px; transition: background-color 0.3s; } - + .nav-links li a:hover { background-color: rgba(255, 255, 255, 0.2); } diff --git a/myblog/blog/templates/blog/index.html b/myblog/blog/templates/blog/index.html index 5702253..d3753db 100644 --- a/myblog/blog/templates/blog/index.html +++ b/myblog/blog/templates/blog/index.html @@ -159,31 +159,31 @@ footer { } - + /* 添加导航栏样式 */ .top-nav { background-color: #007cba; padding: 10px 0; margin-bottom: 20px; } - + .nav-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; } - + .nav-links { list-style: none; padding: 0; margin: 0; display: flex; } - + .nav-links li { margin-right: 20px; } - + .nav-links li a { color: white; text-decoration: none; @@ -191,7 +191,7 @@ border-radius: 4px; transition: background-color 0.3s; } - + .nav-links li a:hover { background-color: rgba(255, 255, 255, 0.2); } diff --git a/myblog/blog/templates/blog/rss.html b/myblog/blog/templates/blog/rss.html index e7ec029..2bd24b9 100644 --- a/myblog/blog/templates/blog/rss.html +++ b/myblog/blog/templates/blog/rss.html @@ -122,31 +122,31 @@ background-color: white; padding: 5px 0; } - + /* 添加导航栏样式 */ .top-nav { background-color: #007cba; padding: 10px 0; margin-bottom: 20px; } - + .nav-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; } - + .nav-links { list-style: none; padding: 0; margin: 0; display: flex; } - + .nav-links li { margin-right: 20px; } - + .nav-links li a { color: white; text-decoration: none; @@ -154,11 +154,11 @@ border-radius: 4px; transition: background-color 0.3s; } - + .nav-links li a:hover { background-color: rgba(255, 255, 255, 0.2); } - + /* RSS主内容区域样式 */ .rss-main { background-color: #f9f9f9; @@ -166,44 +166,44 @@ border-radius: 5px; border: 1px solid #eee; } - + .rss-main h2 { color: #333; border-bottom: 2px solid #ff6600; padding-bottom: 10px; } - + .rss-description { margin: 15px 0; line-height: 1.6; color: #666; } - + .rss-feed-list { list-style: none; padding: 0; } - + .rss-feed-list li { padding: 10px 0; border-bottom: 1px solid #eee; } - + .rss-feed-list li:last-child { border-bottom: none; } - + .rss-feed-link { font-size: 16px; font-weight: bold; color: #007cba; text-decoration: none; } - + .rss-feed-link:hover { text-decoration: underline; } - + .rss-feed-description { font-size: 14px; color: #999; @@ -270,7 +270,7 @@ RSS是一种用于发布经常更新的内容的网页格式。通过RSS阅读器,您可以订阅我们的内容,及时获取最新文章更新。 点击下面的链接可以在浏览器中查看RSS内容,使用RSS阅读器订阅时请复制链接地址。 - + diff --git a/myblog/blog/urls.py b/myblog/blog/urls.py index ce133ec..548d240 100644 --- a/myblog/blog/urls.py +++ b/myblog/blog/urls.py @@ -13,4 +13,4 @@ urlpatterns = [ path('rss/category//', CategoryPostsFeed(), name='category_feed'), path('rss/recent/', RecentPostsFeed(), name='recent_feed'), path('rss/all/', AllPostsFeed(), name='all_feed'), -] \ No newline at end of file +] diff --git a/myblog/blog/views.py b/myblog/blog/views.py index 859b769..3a42796 100644 --- a/myblog/blog/views.py +++ b/myblog/blog/views.py @@ -7,16 +7,16 @@ from .models import Post, Category, SiteSettings def index(request): # 获取所有分类 categories = Category.objects.all() - + # 获取查询参数中的分类ID category_id = request.GET.get('category') - + # 获取搜索关键词 query = request.GET.get('q') - + # 获取搜索类型参数 search_type = request.GET.get('search_type', 'all') - + # 获取站点设置,如果不存在则使用默认值 try: site_settings = SiteSettings.objects.first() @@ -24,7 +24,7 @@ def index(request): except SiteSettings.DoesNotExist: site_settings = None summary_length = 50 - + # 根据分类和搜索关键词筛选文章 if query: # 根据搜索类型执行不同的搜索 @@ -39,16 +39,15 @@ def index(request): posts = Post.objects.filter(category_id=category_id) else: posts = Post.objects.all() - + posts = posts.order_by('-publish_date').distinct() - + # 为每篇文章添加摘要(根据设置的字符长度) for post in posts: - # 移除HTML标签并截取前N个字符作为摘要 import re clean_content = re.sub(r'<[^>]+>', '', post.get_markdown_content()) post.summary = clean_content[:summary_length] + '...' if len(clean_content) > summary_length else clean_content - + return render(request, 'blog/index.html', { 'posts': posts, 'categories': categories, @@ -66,7 +65,10 @@ def detail(request, post_id): site_settings = SiteSettings.objects.first() except SiteSettings.DoesNotExist: site_settings = None - return render(request, 'blog/detail.html', {'post': post, 'categories': categories, 'site_settings': site_settings}) + return render(request, 'blog/detail.html', { + 'post': post, + 'categories': categories, + 'site_settings': site_settings}) # 添加RSS页面视图 @@ -90,4 +92,4 @@ def contact_page(request): site_settings = None return render(request, 'blog/contact.html', { 'site_settings': site_settings - }) \ No newline at end of file + }) diff --git a/myblog/myblog/settings.py b/myblog/myblog/settings.py index 1866ed6..291e408 100644 --- a/myblog/myblog/settings.py +++ b/myblog/myblog/settings.py @@ -163,4 +163,3 @@ try: from .local_settings import * except ImportError: pass -