Compare commits
41 Commits
1c7d752a57
...
develop
| Author | SHA256 | Date | |
|---|---|---|---|
| 5cf22beafa | |||
| f0674c29da | |||
| c1918b45b3 | |||
| a9389042d9 | |||
| 0f24bc5ec9 | |||
| 7ab9ed8e17 | |||
| 127c101c70 | |||
| 57531f8cdf | |||
| 8cd9eecdc8 | |||
| 9e4daa6dcf | |||
| 1f608c33ba | |||
| 4d0ea1a55b | |||
| 20d8180ad0 | |||
| 060388afe4 | |||
| 55d873c450 | |||
| 35e03a8b70 | |||
| c8970dc447 | |||
| dca4f7a1d0 | |||
| 3d29569c22 | |||
| 6dd9da4da0 | |||
| 807690044c | |||
| 34a133d2fb | |||
| c7082e0296 | |||
| af36ee48e2 | |||
| 7ed8aebb52 | |||
| 08ddfd6391 | |||
| 60af0f4ae3 | |||
| 479f59f0f3 | |||
| bbc3fcef08 | |||
| a32cd6aadd | |||
| 8401704aa6 | |||
| 010b45c328 | |||
| 3f9847d6fb | |||
| a8acfaf5b5 | |||
| 7bcc6460c4 | |||
| 67bc42e862 | |||
| cb64aa0911 | |||
| dbc3dac253 | |||
| 5a585b4fc9 | |||
| 99cb1d7170 | |||
| 0cb2b6e621 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -166,7 +166,7 @@ cython_debug/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea/
|
||||||
|
|
||||||
# Ruff stuff:
|
# Ruff stuff:
|
||||||
.ruff_cache/
|
.ruff_cache/
|
||||||
@@ -174,3 +174,6 @@ cython_debug/
|
|||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
|
# 忽略媒体上传目录
|
||||||
|
*/media/*
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,36 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import Post, Category, SiteSettings
|
||||||
|
from django.db import models
|
||||||
|
from mdeditor.widgets import MDEditorWidget
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
class PostAdmin(admin.ModelAdmin):
|
||||||
|
# 使用MDEditor Markdown编辑器替换默认的Textarea
|
||||||
|
formfield_overrides = {
|
||||||
|
models.TextField: {'widget': MDEditorWidget},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 设置列表显示字段
|
||||||
|
list_display = ('title', 'publish_date', 'created_at', 'updated_at')
|
||||||
|
# 设置搜索字段
|
||||||
|
search_fields = ('title', 'content')
|
||||||
|
|
||||||
|
|
||||||
|
class SiteSettingsAdmin(admin.ModelAdmin):
|
||||||
|
# 保持所有字段在列表中显示,方便直接编辑
|
||||||
|
list_display = ('id', 'summary_length', 'contact_email', 'contact_wechat', 'contact_linkedin', 'contact_github')
|
||||||
|
list_display_links = ('id',)
|
||||||
|
|
||||||
|
def has_add_permission(self, request):
|
||||||
|
# 限制只能有一个站点设置实例
|
||||||
|
return not SiteSettings.objects.exists()
|
||||||
|
|
||||||
|
def has_delete_permission(self, request, obj=None):
|
||||||
|
# 禁止删除站点设置
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# 注册自定义的PostAdmin
|
||||||
|
admin.site.register(Post, PostAdmin)
|
||||||
|
admin.site.register(Category)
|
||||||
|
admin.site.register(SiteSettings, SiteSettingsAdmin)
|
||||||
|
|||||||
96
myblog/blog/feeds.py
Normal file
96
myblog/blog/feeds.py
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
from django.contrib.syndication.views import Feed
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from .models import Post, Category
|
||||||
|
|
||||||
|
|
||||||
|
class LatestPostsFeed(Feed):
|
||||||
|
title = "六桂流芳的com"
|
||||||
|
link = "/rss/"
|
||||||
|
description = "最新博客文章"
|
||||||
|
# 添加content_type使浏览器能正确显示RSS内容
|
||||||
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Post.objects.order_by('-publish_date')[:10]
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.title
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
return item.get_markdown_content()
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return reverse('detail', args=[item.pk])
|
||||||
|
|
||||||
|
|
||||||
|
# 添加分类RSS Feed
|
||||||
|
class CategoryPostsFeed(Feed):
|
||||||
|
# 添加content_type使浏览器能正确显示RSS内容
|
||||||
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
|
def get_object(self, request, category_id):
|
||||||
|
return get_object_or_404(Category, pk=category_id)
|
||||||
|
|
||||||
|
def title(self, obj):
|
||||||
|
return f"六桂流芳的com - {obj.name}分类"
|
||||||
|
|
||||||
|
def link(self, obj):
|
||||||
|
return reverse('category_feed', args=[obj.pk])
|
||||||
|
|
||||||
|
def description(self, obj):
|
||||||
|
return f"{obj.name}分类的最新博客文章"
|
||||||
|
|
||||||
|
def items(self, obj):
|
||||||
|
return Post.objects.filter(category=obj).order_by('-publish_date')[:10]
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.title
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
return item.get_markdown_content()
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return reverse('detail', args=[item.pk])
|
||||||
|
|
||||||
|
|
||||||
|
# 添加最新RSS Feed (与全部的区别在于数量限制)
|
||||||
|
class RecentPostsFeed(Feed):
|
||||||
|
title = "六桂流芳的com - 最新文章"
|
||||||
|
link = "/rss/recent/"
|
||||||
|
description = "最新的博客文章"
|
||||||
|
# 添加content_type使浏览器能正确显示RSS内容
|
||||||
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Post.objects.order_by('-publish_date')[:20]
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.title
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
return item.get_markdown_content()
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return reverse('detail', args=[item.pk])
|
||||||
|
|
||||||
|
|
||||||
|
# 添加全部RSS Feed
|
||||||
|
class AllPostsFeed(Feed):
|
||||||
|
title = "六桂流芳的com - 全部文章"
|
||||||
|
link = "/rss/all/"
|
||||||
|
description = "全部博客文章"
|
||||||
|
# 添加content_type使浏览器能正确显示RSS内容
|
||||||
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Post.objects.order_by('-publish_date')
|
||||||
|
|
||||||
|
def item_title(self, item):
|
||||||
|
return item.title
|
||||||
|
|
||||||
|
def item_description(self, item):
|
||||||
|
return item.get_markdown_content()
|
||||||
|
|
||||||
|
def item_link(self, item):
|
||||||
|
return reverse('detail', args=[item.pk])
|
||||||
24
myblog/blog/migrations/0001_initial.py
Normal file
24
myblog/blog/migrations/0001_initial.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-07-26 10:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Post',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(max_length=100)),
|
||||||
|
('content', models.TextField()),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
19
myblog/blog/migrations/0002_post_publish_date.py
Normal file
19
myblog/blog/migrations/0002_post_publish_date.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-07-26 12:10
|
||||||
|
|
||||||
|
import django.utils.timezone
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='publish_date',
|
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
myblog/blog/migrations/0003_post_image.py
Normal file
18
myblog/blog/migrations/0003_post_image.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-07-26 13:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0002_post_publish_date'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='image',
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to='post_images/'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
myblog/blog/migrations/0004_alter_post_content.py
Normal file
19
myblog/blog/migrations/0004_alter_post_content.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-07-26 15:26
|
||||||
|
|
||||||
|
import mdeditor.fields
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0003_post_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='post',
|
||||||
|
name='content',
|
||||||
|
field=mdeditor.fields.MDTextField(),
|
||||||
|
),
|
||||||
|
]
|
||||||
17
myblog/blog/migrations/0005_remove_post_image.py
Normal file
17
myblog/blog/migrations/0005_remove_post_image.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-07-26 15:37
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0004_alter_post_content'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='post',
|
||||||
|
name='image',
|
||||||
|
),
|
||||||
|
]
|
||||||
25
myblog/blog/migrations/0006_category.py
Normal file
25
myblog/blog/migrations/0006_category.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.1 on 2025-07-27 13:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0005_remove_post_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Category',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=100, unique=True)),
|
||||||
|
('description', models.TextField(blank=True, null=True)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name_plural': 'Categories',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
19
myblog/blog/migrations/0007_post_category.py
Normal file
19
myblog/blog/migrations/0007_post_category.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1 on 2025-07-27 13:32
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0006_category'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='posts', to='blog.category'),
|
||||||
|
),
|
||||||
|
]
|
||||||
24
myblog/blog/migrations/0008_sitesettings.py
Normal file
24
myblog/blog/migrations/0008_sitesettings.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 5.1 on 2025-07-27 15:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0007_post_category'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SiteSettings',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('summary_length', models.IntegerField(default=50, help_text='文章摘要字符长度')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': '站点设置',
|
||||||
|
'verbose_name_plural': '站点设置',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Generated by Django 5.1 on 2025-07-27 15:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0008_sitesettings'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sitesettings',
|
||||||
|
name='contact_email',
|
||||||
|
field=models.EmailField(blank=True, help_text='联系邮箱', max_length=254, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sitesettings',
|
||||||
|
name='contact_github',
|
||||||
|
field=models.URLField(blank=True, help_text='GitHub链接', null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sitesettings',
|
||||||
|
name='contact_linkedin',
|
||||||
|
field=models.URLField(blank=True, help_text='LinkedIn链接', null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sitesettings',
|
||||||
|
name='contact_wechat',
|
||||||
|
field=models.CharField(blank=True, help_text='微信号', max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
myblog/blog/migrations/0010_post_status.py
Normal file
18
myblog/blog/migrations/0010_post_status.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1 on 2025-07-31 15:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0009_sitesettings_contact_email_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(choices=[('draft', '草稿'), ('published', '已发布')], default='draft', max_length=10),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,3 +1,111 @@
|
|||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
import markdown
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
from mdeditor.fields import MDTextField
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
|
# 添加 Category 模型
|
||||||
|
class Category(models.Model):
|
||||||
|
name = models.CharField(max_length=100, unique=True)
|
||||||
|
description = models.TextField(blank=True, null=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Categories"
|
||||||
|
|
||||||
|
|
||||||
|
# 添加站点设置模型
|
||||||
|
class SiteSettings(models.Model):
|
||||||
|
summary_length = models.IntegerField(default=50, help_text="文章摘要字符长度")
|
||||||
|
contact_email = models.EmailField(blank=True, null=True, help_text="联系邮箱")
|
||||||
|
contact_wechat = models.CharField(max_length=100, blank=True, null=True, help_text="微信号")
|
||||||
|
contact_linkedin = models.URLField(blank=True, null=True, help_text="LinkedIn链接")
|
||||||
|
contact_github = models.URLField(blank=True, null=True, help_text="GitHub链接")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "站点设置"
|
||||||
|
verbose_name_plural = "站点设置"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "站点设置"
|
||||||
|
|
||||||
|
|
||||||
|
class Post(models.Model):
|
||||||
|
# 添加状态选项
|
||||||
|
DRAFT = 'draft'
|
||||||
|
PUBLISHED = 'published'
|
||||||
|
STATUS_CHOICES = [
|
||||||
|
(DRAFT, '草稿'),
|
||||||
|
(PUBLISHED, '已发布'),
|
||||||
|
]
|
||||||
|
|
||||||
|
title = models.CharField(max_length=100)
|
||||||
|
content = MDTextField()
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
publish_date = models.DateTimeField(default=timezone.now)
|
||||||
|
# 添加分类字段,建立外键关系
|
||||||
|
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name='posts')
|
||||||
|
# 添加状态字段
|
||||||
|
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=DRAFT)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.title}"
|
||||||
|
|
||||||
|
def get_markdown_content(self):
|
||||||
|
import re
|
||||||
|
import emoji
|
||||||
|
content = self.content
|
||||||
|
media_url = settings.MEDIA_URL.rstrip('/')
|
||||||
|
|
||||||
|
# 统一处理所有可能的图片路径格式
|
||||||
|
# 处理Markdown格式的图片 
|
||||||
|
def replace_md_image(match):
|
||||||
|
alt_text = match.group(1)
|
||||||
|
img_path = match.group(2)
|
||||||
|
# 如果路径已经包含媒体URL则不处理
|
||||||
|
if img_path.startswith(media_url):
|
||||||
|
return match.group(0)
|
||||||
|
# 如果是相对路径,则添加媒体URL前缀
|
||||||
|
if not img_path.startswith(('http://', 'https://', '/')):
|
||||||
|
return f''
|
||||||
|
return match.group(0)
|
||||||
|
|
||||||
|
# 处理HTML格式的图片 <img src="path">
|
||||||
|
def replace_html_image(match):
|
||||||
|
quote = match.group(1) or ''
|
||||||
|
img_path = match.group(2)
|
||||||
|
# 如果路径已经包含媒体URL则不处理
|
||||||
|
if img_path.startswith(media_url):
|
||||||
|
return match.group(0)
|
||||||
|
# 如果是相对路径,则添加媒体URL前缀
|
||||||
|
if not img_path.startswith(('http://', 'https://', '/')):
|
||||||
|
return f'src="{media_url}/{img_path}"'
|
||||||
|
return match.group(0)
|
||||||
|
|
||||||
|
# 使用函数替换处理所有Markdown图片
|
||||||
|
content = re.sub(
|
||||||
|
r'!\[([^\]]*)\]\(([^)]+)\)',
|
||||||
|
replace_md_image,
|
||||||
|
content
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用函数替换处理所有HTML图片
|
||||||
|
content = re.sub(
|
||||||
|
r'src=(["\']?)([^"\'>\s]+)\1',
|
||||||
|
replace_html_image,
|
||||||
|
content
|
||||||
|
)
|
||||||
|
|
||||||
|
# 先转换markdown到HTML
|
||||||
|
html_content = markdown.markdown(content)
|
||||||
|
|
||||||
|
# 将emoji shortcode转换为实际的emoji字符
|
||||||
|
html_content = emoji.emojize(html_content, language='alias')
|
||||||
|
|
||||||
|
return mark_safe(html_content)
|
||||||
325
myblog/blog/templates/blog/contact.html
Normal file
325
myblog/blog/templates/blog/contact.html
Normal file
@@ -0,0 +1,325 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>联系我 - 六桂流芳的com</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
width: 250px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-right: 1px solid #eee;
|
||||||
|
position: -webkit-sticky;
|
||||||
|
position: sticky;
|
||||||
|
top: 20px;
|
||||||
|
align-self: flex-start;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h3 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007cba;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
display: block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a:hover,
|
||||||
|
.sidebar ul li a.active {
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"]:hover {
|
||||||
|
background-color: #005a87;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type label {
|
||||||
|
display: block;
|
||||||
|
margin: 5px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type input[type="radio"] {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content h1 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #eee;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
background-color: white;
|
||||||
|
padding: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-info {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 5px;
|
||||||
|
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;
|
||||||
|
padding: 20px;
|
||||||
|
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;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-links li a:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- 添加网站标题和导航栏 -->
|
||||||
|
<div class="top-nav">
|
||||||
|
<div class="nav-container">
|
||||||
|
<h1 style="text-align: left; margin: 0; padding: 0;">
|
||||||
|
<a href="{% url 'index' %}" style="text-decoration: none; color: white;">六桂流芳的com</a>
|
||||||
|
</h1>
|
||||||
|
<ul class="nav-links">
|
||||||
|
<li><a href="{% url 'index' %}">首页</a></li>
|
||||||
|
<li><a href="{% url 'rss_page' %}">RSS订阅</a></li>
|
||||||
|
<li><a href="{% url 'contact_page' %}">联系我</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="search-box">
|
||||||
|
<form method="get" action="{% url 'index' %}">
|
||||||
|
<input type="text" name="q" placeholder="搜索文章..." value="{{ query|default:'' }}">
|
||||||
|
<div class="search-type">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="all" checked>
|
||||||
|
全文搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="title">
|
||||||
|
标题搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="content">
|
||||||
|
内容搜索
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="搜索">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>文章分类</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'index' %}">全部文章</a></li>
|
||||||
|
{% for category in categories %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'index' %}?category={{ category.id }}">
|
||||||
|
{{ category.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<div class="contact-main">
|
||||||
|
<h2>联系我</h2>
|
||||||
|
<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>
|
||||||
|
{% endif %}
|
||||||
|
{% if site_settings.contact_wechat %}
|
||||||
|
<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>
|
||||||
|
{% endif %}
|
||||||
|
{% if site_settings.contact_github %}
|
||||||
|
<li>
|
||||||
|
<span class="contact-label">GitHub:</span>
|
||||||
|
<span class="contact-value">{{ site_settings.contact_github }}</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
270
myblog/blog/templates/blog/detail.html
Normal file
270
myblog/blog/templates/blog/detail.html
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{ post.title }}</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
width: 250px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-right: 1px solid #eee;
|
||||||
|
position: -webkit-sticky;
|
||||||
|
position: sticky;
|
||||||
|
top: 20px;
|
||||||
|
align-self: flex-start;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h3 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007cba;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
display: block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a:hover,
|
||||||
|
.sidebar ul li a.active {
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"]:hover {
|
||||||
|
background-color: #005a87;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type label {
|
||||||
|
display: block;
|
||||||
|
margin: 5px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type input[type="radio"] {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content h1 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #eee;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #999;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-content img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-content pre {
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 10px;
|
||||||
|
overflow-x: auto;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-content code {
|
||||||
|
font-family: 'Courier New', Courier, monospace;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-content pre code {
|
||||||
|
background-color: transparent;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
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;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-links li a:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- 添加网站标题和导航栏 -->
|
||||||
|
<div class="top-nav">
|
||||||
|
<div class="nav-container">
|
||||||
|
<h1 style="text-align: left; margin: 0; padding: 0;">
|
||||||
|
<a href="{% url 'index' %}" style="text-decoration: none; color: white;">六桂流芳的com</a>
|
||||||
|
</h1>
|
||||||
|
<ul class="nav-links">
|
||||||
|
<li><a href="{% url 'index' %}">首页</a></li>
|
||||||
|
<li><a href="{% url 'rss_page' %}">RSS订阅</a></li>
|
||||||
|
<li><a href="{% url 'contact_page' %}">联系我</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="search-box">
|
||||||
|
<form method="get" action="{% url 'index' %}">
|
||||||
|
<input type="text" name="q" placeholder="搜索文章..." value="{{ query|default:'' }}">
|
||||||
|
<div class="search-type">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="all" checked>
|
||||||
|
全文搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="title">
|
||||||
|
标题搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="content">
|
||||||
|
内容搜索
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="搜索">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>文章分类</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'index' %}" {% if not post.category %}class="active"{% endif %}>全部文章</a></li>
|
||||||
|
{% for category in categories %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'index' %}?category={{ category.id }}"
|
||||||
|
{% if post.category and post.category.id == category.id %}class="active"{% endif %}>
|
||||||
|
{{ category.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<h1 style="text-align: center;">{{ post.title }}</h1>
|
||||||
|
<div class="post-meta">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
|
<span>发布时间:{{ post.publish_date|date:"Y年n月j日 H:i" }}</span>
|
||||||
|
<a href="{% url 'index' %}" style="white-space: nowrap;">返回首页</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="post-content">{{ post.get_markdown_content }}</div>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
285
myblog/blog/templates/blog/index.html
Normal file
285
myblog/blog/templates/blog/index.html
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>六桂流芳的com</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
width: 250px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-right: 1px solid #eee;
|
||||||
|
position: -webkit-sticky;
|
||||||
|
position: sticky;
|
||||||
|
top: 20px;
|
||||||
|
align-self: flex-start;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h3 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007cba;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
display: block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a:hover,
|
||||||
|
.sidebar ul li a.active {
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"]:hover {
|
||||||
|
background-color: #005a87;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type label {
|
||||||
|
display: block;
|
||||||
|
margin: 5px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type input[type="radio"] {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content h1 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #eee;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.posts-list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.posts-list li {
|
||||||
|
padding: 15px 0;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.posts-list li:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #007cba;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-category {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-summary {
|
||||||
|
margin: 10px 0;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-links li a:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- 添加网站标题和导航栏 -->
|
||||||
|
<div class="top-nav">
|
||||||
|
<div class="nav-container">
|
||||||
|
<h1 style="text-align: left; margin: 0; padding: 0;">
|
||||||
|
<a href="{% url 'index' %}" style="text-decoration: none; color: white;">六桂流芳的com</a>
|
||||||
|
</h1>
|
||||||
|
<ul class="nav-links">
|
||||||
|
<li><a href="{% url 'index' %}">首页</a></li>
|
||||||
|
<li><a href="{% url 'rss_page' %}">RSS订阅</a></li>
|
||||||
|
<li><a href="{% url 'contact_page' %}">联系我</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="search-box">
|
||||||
|
<form method="get">
|
||||||
|
<input type="text" name="q" placeholder="搜索文章..." value="{{ query|default:'' }}">
|
||||||
|
|
||||||
|
<div class="search-type">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="all"
|
||||||
|
{% if search_type != 'title' and search_type != 'content' %}checked{% endif %}>
|
||||||
|
全文搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="title"
|
||||||
|
{% if search_type == 'title' %}checked{% endif %}>
|
||||||
|
标题搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="content"
|
||||||
|
{% if search_type == 'content' %}checked{% endif %}>
|
||||||
|
内容搜索
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="搜索">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>文章分类</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'index' %}" {% if not selected_category %}class="active"{% endif %}>全部文章</a></li>
|
||||||
|
{% for category in categories %}
|
||||||
|
<li>
|
||||||
|
<a href="?category={{ category.id }}"
|
||||||
|
{% if selected_category == category.id|stringformat:"s" %}class="active"{% endif %}>
|
||||||
|
{{ category.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<ul class="posts-list">
|
||||||
|
{% for post in posts %}
|
||||||
|
<li>
|
||||||
|
<div class="post-title">
|
||||||
|
<a href="{% url 'detail' post.id %}">{{ post.title }}</a>
|
||||||
|
</div>
|
||||||
|
<div class="post-meta">
|
||||||
|
发布时间:{{ post.publish_date|date:"Y年n月j日 H:i" }}
|
||||||
|
</div>
|
||||||
|
<div class="post-summary">
|
||||||
|
{{ post.summary|safe }}
|
||||||
|
</div>
|
||||||
|
{% if post.category %}
|
||||||
|
<div class="post-category">
|
||||||
|
{{ post.category.name }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer style="position: fixed; bottom: 0; width: 100%; text-align: center; font-size: 12px; color: #999; background-color: white; padding: 5px 0;">
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
303
myblog/blog/templates/blog/rss.html
Normal file
303
myblog/blog/templates/blog/rss.html
Normal file
@@ -0,0 +1,303 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>RSS订阅 - 六桂流芳的com</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
width: 250px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-right: 1px solid #eee;
|
||||||
|
position: -webkit-sticky;
|
||||||
|
position: sticky;
|
||||||
|
top: 20px;
|
||||||
|
align-self: flex-start;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h3 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007cba;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
display: block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar ul li a:hover,
|
||||||
|
.sidebar ul li a.active {
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input[type="submit"]:hover {
|
||||||
|
background-color: #005a87;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type label {
|
||||||
|
display: block;
|
||||||
|
margin: 5px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-type input[type="radio"] {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content h1 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #eee;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
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;
|
||||||
|
padding: 8px 12px;
|
||||||
|
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;
|
||||||
|
padding: 20px;
|
||||||
|
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;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- 添加网站标题和导航栏 -->
|
||||||
|
<div class="top-nav">
|
||||||
|
<div class="nav-container">
|
||||||
|
<h1 style="text-align: left; margin: 0; padding: 0;">
|
||||||
|
<a href="{% url 'index' %}" style="text-decoration: none; color: white;">六桂流芳的com</a>
|
||||||
|
</h1>
|
||||||
|
<ul class="nav-links">
|
||||||
|
<li><a href="{% url 'index' %}">首页</a></li>
|
||||||
|
<li><a href="{% url 'rss_page' %}">RSS订阅</a></li>
|
||||||
|
<li><a href="{% url 'contact_page' %}">联系我</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="search-box">
|
||||||
|
<form method="get" action="{% url 'index' %}">
|
||||||
|
<input type="text" name="q" placeholder="搜索文章..." value="{{ query|default:'' }}">
|
||||||
|
<div class="search-type">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="all" checked>
|
||||||
|
全文搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="title">
|
||||||
|
标题搜索
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="search_type" value="content">
|
||||||
|
内容搜索
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="搜索">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>文章分类</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'index' %}">全部文章</a></li>
|
||||||
|
{% for category in categories %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'index' %}?category={{ category.id }}">
|
||||||
|
{{ category.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<div class="rss-main">
|
||||||
|
<h2>RSS订阅</h2>
|
||||||
|
<div class="rss-description">
|
||||||
|
RSS是一种用于发布经常更新的内容的网页格式。通过RSS阅读器,您可以订阅我们的内容,及时获取最新文章更新。
|
||||||
|
点击下面的链接可以在浏览器中查看RSS内容,使用RSS阅读器订阅时请复制链接地址。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="rss-feed-list">
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'rss_feed' %}" class="rss-feed-link" target="_blank">最新文章</a>
|
||||||
|
<div class="rss-feed-description">包含最新的10篇博客文章</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'recent_feed' %}" class="rss-feed-link" target="_blank">最近更新</a>
|
||||||
|
<div class="rss-feed-description">包含最新的20篇博客文章</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'all_feed' %}" class="rss-feed-link" target="_blank">全部文章</a>
|
||||||
|
<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>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
myblog/blog/urls.py
Normal file
16
myblog/blog/urls.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
from .feeds import LatestPostsFeed, CategoryPostsFeed, RecentPostsFeed, AllPostsFeed
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.index, name='index'),
|
||||||
|
path('post/<int:post_id>/', views.detail, name='detail'),
|
||||||
|
# 添加RSS页面路由
|
||||||
|
path('rss/page/', views.rss_page, name='rss_page'),
|
||||||
|
# 添加联系我页面路由
|
||||||
|
path('contact/', views.contact_page, name='contact_page'),
|
||||||
|
path('rss/', LatestPostsFeed(), name='rss_feed'),
|
||||||
|
path('rss/category/<int:category_id>/', CategoryPostsFeed(), name='category_feed'),
|
||||||
|
path('rss/recent/', RecentPostsFeed(), name='recent_feed'),
|
||||||
|
path('rss/all/', AllPostsFeed(), name='all_feed'),
|
||||||
|
]
|
||||||
@@ -1,3 +1,137 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render, get_object_or_404
|
||||||
|
from .models import Post, Category, SiteSettings
|
||||||
|
|
||||||
|
def post_list(request):
|
||||||
|
# 只显示已发布的文章
|
||||||
|
posts = Post.objects.filter(status=Post.PUBLISHED).order_by('-publish_date')
|
||||||
|
categories = Category.objects.all()
|
||||||
|
|
||||||
|
# 获取站点设置
|
||||||
|
site_settings = SiteSettings.objects.first()
|
||||||
|
summary_length = site_settings.summary_length if site_settings else 50
|
||||||
|
|
||||||
|
return render(request, 'blog/post_list.html', {
|
||||||
|
'posts': posts,
|
||||||
|
'categories': categories,
|
||||||
|
'summary_length': summary_length
|
||||||
|
})
|
||||||
|
|
||||||
|
def post_detail(request, pk):
|
||||||
|
# 只允许查看已发布的文章
|
||||||
|
post = get_object_or_404(Post, pk=pk, status=Post.PUBLISHED)
|
||||||
|
categories = Category.objects.all()
|
||||||
|
|
||||||
|
return render(request, 'blog/post_detail.html', {
|
||||||
|
'post': post,
|
||||||
|
'categories': categories
|
||||||
|
})
|
||||||
|
|
||||||
|
def category_posts(request, category_id):
|
||||||
|
category = get_object_or_404(Category, id=category_id)
|
||||||
|
# 只显示该分类下已发布的文章
|
||||||
|
posts = Post.objects.filter(category=category, status=Post.PUBLISHED).order_by('-publish_date')
|
||||||
|
categories = Category.objects.all()
|
||||||
|
|
||||||
|
# 获取站点设置
|
||||||
|
site_settings = SiteSettings.objects.first()
|
||||||
|
summary_length = site_settings.summary_length if site_settings else 50
|
||||||
|
|
||||||
|
return render(request, 'blog/post_list.html', {
|
||||||
|
'posts': posts,
|
||||||
|
'categories': categories,
|
||||||
|
'current_category': category,
|
||||||
|
'summary_length': summary_length
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
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()
|
||||||
|
summary_length = site_settings.summary_length if site_settings else 50
|
||||||
|
except SiteSettings.DoesNotExist:
|
||||||
|
site_settings = None
|
||||||
|
summary_length = 50
|
||||||
|
|
||||||
|
# 根据分类和搜索关键词筛选文章
|
||||||
|
if query:
|
||||||
|
# 根据搜索类型执行不同的搜索
|
||||||
|
if search_type == 'title':
|
||||||
|
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED)
|
||||||
|
elif search_type == 'content':
|
||||||
|
posts = Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
||||||
|
else:
|
||||||
|
# 默认按标题和内容搜索
|
||||||
|
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED) | Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
||||||
|
elif category_id:
|
||||||
|
posts = Post.objects.filter(category_id=category_id, status=Post.PUBLISHED)
|
||||||
|
else:
|
||||||
|
posts = Post.objects.filter(status=Post.PUBLISHED)
|
||||||
|
|
||||||
|
posts = posts.order_by('-publish_date').distinct()
|
||||||
|
|
||||||
|
# 为每篇文章添加摘要(根据设置的字符长度)
|
||||||
|
for post in posts:
|
||||||
|
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,
|
||||||
|
'selected_category': category_id,
|
||||||
|
'query': query,
|
||||||
|
'search_type': search_type,
|
||||||
|
'site_settings': site_settings
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def detail(request, post_id):
|
||||||
|
post = get_object_or_404(Post, pk=post_id, status=Post.PUBLISHED)
|
||||||
|
categories = Category.objects.all() # 获取所有分类用于侧边栏
|
||||||
|
try:
|
||||||
|
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})
|
||||||
|
|
||||||
|
|
||||||
|
# 添加RSS页面视图
|
||||||
|
def rss_page(request):
|
||||||
|
categories = Category.objects.all()
|
||||||
|
try:
|
||||||
|
site_settings = SiteSettings.objects.first()
|
||||||
|
except SiteSettings.DoesNotExist:
|
||||||
|
site_settings = None
|
||||||
|
return render(request, 'blog/rss.html', {
|
||||||
|
'categories': categories,
|
||||||
|
'site_settings': site_settings
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# 添加联系我页面视图
|
||||||
|
def contact_page(request):
|
||||||
|
try:
|
||||||
|
site_settings = SiteSettings.objects.first()
|
||||||
|
except SiteSettings.DoesNotExist:
|
||||||
|
site_settings = None
|
||||||
|
return render(request, 'blog/contact.html', {
|
||||||
|
'site_settings': site_settings
|
||||||
|
})
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@ DEBUG = True
|
|||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
@@ -37,6 +36,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'blog',
|
||||||
|
'mdeditor',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -68,7 +69,6 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = 'myblog.wsgi.application'
|
WSGI_APPLICATION = 'myblog.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||||
|
|
||||||
@@ -79,7 +79,6 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
@@ -98,25 +97,69 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'zh-Hans'
|
||||||
|
TIME_ZONE = 'Asia/Shanghai'
|
||||||
TIME_ZONE = 'UTC'
|
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
|
||||||
|
# 添加媒体文件配置
|
||||||
|
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
|
"https://www.yuangyaa.com",
|
||||||
|
"http://www.yuangyaa.com",
|
||||||
|
"http://yuangyaa.com",
|
||||||
|
"https://yuangyaa.com",
|
||||||
|
]
|
||||||
|
|
||||||
|
# 添加 MDEditor 配置
|
||||||
|
MDEDITOR_CONFIGS = {
|
||||||
|
'default': {
|
||||||
|
'width': '100%',
|
||||||
|
'height': 700,
|
||||||
|
'toolbar': ["undo", "redo", "|",
|
||||||
|
"bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
|
||||||
|
"h1", "h2", "h3", "h5", "h6", "|",
|
||||||
|
"list-ul", "list-ol", "hr", "|",
|
||||||
|
"link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime",
|
||||||
|
"emoji", "html-entities", "pagebreak", "goto-line", "|", "help", "info",
|
||||||
|
"||", "preview", "watch", "fullscreen"],
|
||||||
|
'upload_image_formats': ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
|
||||||
|
'image_folder': 'editor',
|
||||||
|
'theme': 'default',
|
||||||
|
'preview_theme': 'default',
|
||||||
|
'editor_theme': 'default',
|
||||||
|
'toolbar_autofixed': True,
|
||||||
|
'search_replace': True,
|
||||||
|
'emoji': True,
|
||||||
|
'tex': False,
|
||||||
|
'language': 'zh',
|
||||||
|
'focus': False,
|
||||||
|
'auto_height': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
X_FRAME_OPTIONS = 'SAMEORIGIN'
|
||||||
|
|
||||||
|
# settings.py 末尾加上这段
|
||||||
|
try:
|
||||||
|
from .local_settings import *
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -15,8 +15,17 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
from django.conf import settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('mdeditor/', include('mdeditor.urls')),
|
||||||
|
# 包含blog应用的URL
|
||||||
|
path('', include('blog.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 添加媒体文件URL配置 - 确保在DEBUG和生产环境都能正确处理媒体文件
|
||||||
|
if settings.DEBUG:
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
asgiref==3.9.1
|
asgiref==3.9.1
|
||||||
asttokens==3.0.0
|
asttokens==3.0.0
|
||||||
|
bleach==6.2.0
|
||||||
|
certifi==2025.7.14
|
||||||
|
charset-normalizer==3.4.2
|
||||||
click==8.2.1
|
click==8.2.1
|
||||||
decorator==5.2.1
|
decorator==5.2.1
|
||||||
Django==5.2.4
|
Django==5.1
|
||||||
|
django-mdeditor==0.1.20
|
||||||
|
emoji==2.14.1
|
||||||
executing==2.2.0
|
executing==2.2.0
|
||||||
gunicorn==23.0.0
|
gunicorn==23.0.0
|
||||||
h11==0.16.0
|
h11==0.16.0
|
||||||
|
idna==3.10
|
||||||
ipython==9.4.0
|
ipython==9.4.0
|
||||||
ipython_pygments_lexers==1.1.1
|
ipython_pygments_lexers==1.1.1
|
||||||
jedi==0.19.2
|
jedi==0.19.2
|
||||||
Markdown==3.8.2
|
Markdown==3.5.2
|
||||||
|
martor==1.6.45
|
||||||
matplotlib-inline==0.1.7
|
matplotlib-inline==0.1.7
|
||||||
numpy==2.3.2
|
numpy==2.3.2
|
||||||
packaging==25.0
|
packaging==25.0
|
||||||
pandas==2.3.1
|
pandas==2.3.1
|
||||||
parso==0.8.4
|
parso==0.8.4
|
||||||
pexpect==4.9.0
|
pexpect==4.9.0
|
||||||
|
pillow==11.3.0
|
||||||
prompt_toolkit==3.0.51
|
prompt_toolkit==3.0.51
|
||||||
psycopg2-binary==2.9.10
|
psycopg2-binary==2.9.10
|
||||||
ptyprocess==0.7.0
|
ptyprocess==0.7.0
|
||||||
@@ -23,11 +31,14 @@ pure_eval==0.2.3
|
|||||||
Pygments==2.19.2
|
Pygments==2.19.2
|
||||||
python-dateutil==2.9.0.post0
|
python-dateutil==2.9.0.post0
|
||||||
pytz==2025.2
|
pytz==2025.2
|
||||||
|
requests==2.32.4
|
||||||
six==1.17.0
|
six==1.17.0
|
||||||
sqlparse==0.5.3
|
sqlparse==0.5.3
|
||||||
stack-data==0.6.3
|
stack-data==0.6.3
|
||||||
traitlets==5.14.3
|
traitlets==5.14.3
|
||||||
tzdata==2025.2
|
tzdata==2025.2
|
||||||
|
urllib3==2.5.0
|
||||||
uv==0.8.3
|
uv==0.8.3
|
||||||
uvicorn==0.35.0
|
uvicorn==0.35.0
|
||||||
wcwidth==0.2.13
|
wcwidth==0.2.13
|
||||||
|
webencodings==0.5.1
|
||||||
|
|||||||
Reference in New Issue
Block a user