Compare commits
2 Commits
0f24bc5ec9
...
c1918b45b3
| Author | SHA256 | Date | |
|---|---|---|---|
| c1918b45b3 | |||
| a9389042d9 |
@@ -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)
|
||||
return mark_safe(html_content)
|
||||
|
||||
@@ -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 @@
|
||||
<div class="contact-description">
|
||||
如果您有任何问题或想与我交流,可以通过以下方式联系我:
|
||||
</div>
|
||||
|
||||
|
||||
<ul class="contact-details">
|
||||
{% if site_settings.contact_email %}
|
||||
<li>
|
||||
<span class="contact-label">邮箱:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_email }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="contact-label">邮箱:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_email }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if site_settings.contact_wechat %}
|
||||
<li>
|
||||
<span class="contact-label">微信:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_wechat }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="contact-label">微信:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_wechat }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if site_settings.contact_linkedin %}
|
||||
<li>
|
||||
<span class="contact-label">LinkedIn:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_linkedin }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="contact-label">LinkedIn:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_linkedin }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if site_settings.contact_github %}
|
||||
<li>
|
||||
<span class="contact-label">GitHub:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_github }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="contact-label">GitHub:</span>
|
||||
<span class="contact-value">{{ site_settings.contact_github }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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阅读器订阅时请复制链接地址。
|
||||
</div>
|
||||
|
||||
|
||||
<ul class="rss-feed-list">
|
||||
<li>
|
||||
<a href="{% url 'rss_feed' %}" class="rss-feed-link" target="_blank">最新文章</a>
|
||||
@@ -285,10 +285,11 @@
|
||||
<div class="rss-feed-description">包含所有博客文章</div>
|
||||
</li>
|
||||
{% for category in categories %}
|
||||
<li>
|
||||
<a href="{% url 'category_feed' category.id %}" class="rss-feed-link" target="_blank">{{ category.name }}分类</a>
|
||||
<div class="rss-feed-description">{{ category.name }}分类下的最新博客文章</div>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'category_feed' category.id %}" class="rss-feed-link"
|
||||
target="_blank">{{ category.name }}分类</a>
|
||||
<div class="rss-feed-description">{{ category.name }}分类下的最新博客文章</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -13,4 +13,4 @@ urlpatterns = [
|
||||
path('rss/category/<int:category_id>/', CategoryPostsFeed(), name='category_feed'),
|
||||
path('rss/recent/', RecentPostsFeed(), name='recent_feed'),
|
||||
path('rss/all/', AllPostsFeed(), name='all_feed'),
|
||||
]
|
||||
]
|
||||
|
||||
@@ -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
|
||||
})
|
||||
})
|
||||
|
||||
@@ -163,4 +163,3 @@ try:
|
||||
from .local_settings import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user