fix some bugs
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -176,4 +176,5 @@ cython_debug/
|
|||||||
|
|
||||||
# 忽略媒体上传目录
|
# 忽略媒体上传目录
|
||||||
*/media/*
|
*/media/*
|
||||||
|
staticfiles/
|
||||||
|
|
||||||
|
|||||||
66
AGENTS.md
Normal file
66
AGENTS.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# AGENTS.md — blog (六桂流芳的com)
|
||||||
|
|
||||||
|
## Tech stack
|
||||||
|
|
||||||
|
- Python 3.12.7, Django 5.1, SQLite (dev) / PostgreSQL (prod via `psycopg2-binary`)
|
||||||
|
- `zh-Hans` locale, `Asia/Shanghai` timezone
|
||||||
|
|
||||||
|
## Key commands
|
||||||
|
|
||||||
|
Run from `myblog/`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python manage.py runserver # dev server
|
||||||
|
python manage.py makemigrations # after model changes
|
||||||
|
python manage.py migrate # apply migrations
|
||||||
|
python manage.py createsuperuser # admin login
|
||||||
|
python manage.py collectstatic # prod: gather static files to staticfiles/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Package management
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt # sync deps (no lockfile)
|
||||||
|
```
|
||||||
|
|
||||||
|
`uv` (v0.8.3) is in requirements.txt but not the primary workflow.
|
||||||
|
|
||||||
|
## Project layout
|
||||||
|
|
||||||
|
```
|
||||||
|
myblog/
|
||||||
|
├── blog/ # main app (models, views, templates, admin)
|
||||||
|
│ └── static/blog/ # shared CSS (single style.css)
|
||||||
|
├── myblog/ # Django project settings/settings.py
|
||||||
|
├── manage.py
|
||||||
|
├── db.sqlite3 # dev DB (gitignored)
|
||||||
|
└── media/ # user uploads (gitignored)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key models
|
||||||
|
|
||||||
|
- `Post` — `title`, `content` (MDEditor), `category` (FK), `status` (draft/published), `publish_date`
|
||||||
|
- `Category` — `name`, `description`
|
||||||
|
- `SiteSettings` — singleton: `summary_length`, contact fields
|
||||||
|
|
||||||
|
Admin at `/admin/` with MDEditor on Post content field.
|
||||||
|
|
||||||
|
## Local overrides
|
||||||
|
|
||||||
|
Create `myblog/myblog/local_settings.py` to override any setting. Imported at the bottom of `settings.py`.
|
||||||
|
|
||||||
|
## Git workflow
|
||||||
|
|
||||||
|
```
|
||||||
|
feature/* or bugfix/* → develop → main
|
||||||
|
```
|
||||||
|
|
||||||
|
Remote: `ssh://git@git.yuangyaa.com:222/yuangyaa/blog.git`
|
||||||
|
|
||||||
|
## What's NOT configured
|
||||||
|
|
||||||
|
- **No tests** (tests.py is blank)
|
||||||
|
- **No linting, formatting, or type checking**
|
||||||
|
- **No CI/CD**
|
||||||
|
- **No pre-commit hooks**
|
||||||
|
- **No Docker**
|
||||||
@@ -12,7 +12,7 @@ class LatestPostsFeed(Feed):
|
|||||||
content_type = 'application/xml; charset=utf-8'
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return Post.objects.order_by('-publish_date')[:10]
|
return Post.objects.filter(status=Post.PUBLISHED).order_by('-publish_date')[:10]
|
||||||
|
|
||||||
def item_title(self, item):
|
def item_title(self, item):
|
||||||
return item.title
|
return item.title
|
||||||
@@ -42,7 +42,7 @@ class CategoryPostsFeed(Feed):
|
|||||||
return f"{obj.name}分类的最新博客文章"
|
return f"{obj.name}分类的最新博客文章"
|
||||||
|
|
||||||
def items(self, obj):
|
def items(self, obj):
|
||||||
return Post.objects.filter(category=obj).order_by('-publish_date')[:10]
|
return Post.objects.filter(category=obj, status=Post.PUBLISHED).order_by('-publish_date')[:10]
|
||||||
|
|
||||||
def item_title(self, item):
|
def item_title(self, item):
|
||||||
return item.title
|
return item.title
|
||||||
@@ -63,7 +63,7 @@ class RecentPostsFeed(Feed):
|
|||||||
content_type = 'application/xml; charset=utf-8'
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return Post.objects.order_by('-publish_date')[:20]
|
return Post.objects.filter(status=Post.PUBLISHED).order_by('-publish_date')[:20]
|
||||||
|
|
||||||
def item_title(self, item):
|
def item_title(self, item):
|
||||||
return item.title
|
return item.title
|
||||||
@@ -84,7 +84,7 @@ class AllPostsFeed(Feed):
|
|||||||
content_type = 'application/xml; charset=utf-8'
|
content_type = 'application/xml; charset=utf-8'
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return Post.objects.order_by('-publish_date')
|
return Post.objects.filter(status=Post.PUBLISHED).order_by('-publish_date')
|
||||||
|
|
||||||
def item_title(self, item):
|
def item_title(self, item):
|
||||||
return item.title
|
return item.title
|
||||||
|
|||||||
340
myblog/blog/static/blog/style.css
Normal file
340
myblog/blog/static/blog/style.css
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
margin-top: 20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination a {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
margin: 0 4px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #007cba;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination a:hover {
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination .current {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
margin: 0 4px;
|
||||||
|
background-color: #007cba;
|
||||||
|
color: white;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-main,
|
||||||
|
.rss-main {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-main h2,
|
||||||
|
.rss-main h2 {
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2px solid #007cba;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rss-main h2 {
|
||||||
|
border-bottom-color: #ff6600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-description,
|
||||||
|
.rss-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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
72
myblog/blog/templates/blog/base.html
Normal file
72
myblog/blog/templates/blog/base.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{% block title %}六桂流芳的com{% endblock %}</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'blog/style.css' %}">
|
||||||
|
</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"
|
||||||
|
{% 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="{% url 'index' %}?category={{ category.id }}"
|
||||||
|
{% if selected_category == category.id|stringformat:"s" %}class="active"{% endif %}>
|
||||||
|
{{ category.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,288 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "blog/base.html" %}
|
||||||
<html lang="zh">
|
{% block title %}联系我 - 六桂流芳的com{% endblock %}
|
||||||
<head>
|
{% block content %}
|
||||||
<meta charset="UTF-8">
|
<div class="contact-main">
|
||||||
<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>
|
<h2>联系我</h2>
|
||||||
<div class="contact-description">
|
<div class="contact-description">
|
||||||
如果您有任何问题或想与我交流,可以通过以下方式联系我:
|
如果您有任何问题或想与我交流,可以通过以下方式联系我:
|
||||||
@@ -314,12 +33,5 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock %}
|
||||||
<footer>
|
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
@@ -1,270 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "blog/base.html" %}
|
||||||
<html lang="zh">
|
{% block title %}{{ post.title }} - 六桂流芳的com{% endblock %}
|
||||||
<head>
|
{% block content %}
|
||||||
<meta charset="UTF-8">
|
<h1 style="text-align: center;">{{ post.title }}</h1>
|
||||||
<title>{{ post.title }}</title>
|
<div class="post-meta">
|
||||||
<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;">
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
<span>发布时间:{{ post.publish_date|date:"Y年n月j日 H:i" }}</span>
|
<span>发布时间:{{ post.publish_date|date:"Y年n月j日 H:i" }}</span>
|
||||||
<a href="{% url 'index' %}" style="white-space: nowrap;">返回首页</a>
|
<a href="{% url 'index' %}" style="white-space: nowrap;">返回首页</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="post-content">{{ post.get_markdown_content }}</div>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="post-content">{{ post.get_markdown_content }}</div>
|
||||||
<footer>
|
<br>
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
{% endblock %}
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
@@ -1,262 +1,8 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "blog/base.html" %}
|
||||||
<html lang="zh">
|
{% block title %}六桂流芳的com{% endblock %}
|
||||||
<head>
|
{% block content %}
|
||||||
<meta charset="UTF-8">
|
<ul class="posts-list">
|
||||||
<title>六桂流芳的com</title>
|
{% for post in page_obj %}
|
||||||
<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>
|
<li>
|
||||||
<div class="post-title">
|
<div class="post-title">
|
||||||
<a href="{% url 'detail' post.id %}">{{ post.title }}</a>
|
<a href="{% url 'detail' post.id %}">{{ post.title }}</a>
|
||||||
@@ -274,12 +20,27 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</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;">
|
{% if page_obj.paginator.num_pages > 1 %}
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
<div class="pagination">
|
||||||
</footer>
|
{% if page_obj.has_previous %}
|
||||||
</body>
|
<a href="?page=1{% if query %}&q={{ query }}{% endif %}{% if search_type %}&search_type={{ search_type }}{% endif %}{% if selected_category %}&category={{ selected_category }}{% endif %}">«</a>
|
||||||
</html>
|
<a href="?page={{ page_obj.previous_page_number }}{% if query %}&q={{ query }}{% endif %}{% if search_type %}&search_type={{ search_type }}{% endif %}{% if selected_category %}&category={{ selected_category }}{% endif %}">‹</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for num in page_obj.paginator.page_range %}
|
||||||
|
{% if page_obj.number == num %}
|
||||||
|
<span class="current">{{ num }}</span>
|
||||||
|
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
|
||||||
|
<a href="?page={{ num }}{% if query %}&q={{ query }}{% endif %}{% if search_type %}&search_type={{ search_type }}{% endif %}{% if selected_category %}&category={{ selected_category }}{% endif %}">{{ num }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<a href="?page={{ page_obj.next_page_number }}{% if query %}&q={{ query }}{% endif %}{% if search_type %}&search_type={{ search_type }}{% endif %}{% if selected_category %}&category={{ selected_category }}{% endif %}">›</a>
|
||||||
|
<a href="?page={{ page_obj.paginator.num_pages }}{% if query %}&q={{ query }}{% endif %}{% if search_type %}&search_type={{ search_type }}{% endif %}{% if selected_category %}&category={{ selected_category }}{% endif %}">»</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,270 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "blog/base.html" %}
|
||||||
<html lang="zh">
|
{% block title %}RSS订阅 - 六桂流芳的com{% endblock %}
|
||||||
<head>
|
{% block content %}
|
||||||
<meta charset="UTF-8">
|
<div class="rss-main">
|
||||||
<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>
|
<h2>RSS订阅</h2>
|
||||||
<div class="rss-description">
|
<div class="rss-description">
|
||||||
RSS是一种用于发布经常更新的内容的网页格式。通过RSS阅读器,您可以订阅我们的内容,及时获取最新文章更新。
|
RSS是一种用于发布经常更新的内容的网页格式。通过RSS阅读器,您可以订阅我们的内容,及时获取最新文章更新。
|
||||||
@@ -292,12 +29,5 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock %}
|
||||||
<footer>
|
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank">闽ICP备2023010767号-2</a>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
@@ -1,81 +1,25 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from .models import Post, Category, SiteSettings
|
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.
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
# 获取所有分类
|
|
||||||
categories = Category.objects.all()
|
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()
|
site_settings = SiteSettings.objects.first()
|
||||||
summary_length = site_settings.summary_length if site_settings else 50
|
summary_length = site_settings.summary_length if site_settings else 50
|
||||||
except SiteSettings.DoesNotExist:
|
|
||||||
site_settings = None
|
|
||||||
summary_length = 50
|
|
||||||
|
|
||||||
# 根据分类和搜索关键词筛选文章
|
category_id = request.GET.get('category')
|
||||||
|
query = request.GET.get('q')
|
||||||
|
search_type = request.GET.get('search_type', 'all')
|
||||||
|
|
||||||
if query:
|
if query:
|
||||||
# 根据搜索类型执行不同的搜索
|
|
||||||
if search_type == 'title':
|
if search_type == 'title':
|
||||||
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED)
|
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED)
|
||||||
elif search_type == 'content':
|
elif search_type == 'content':
|
||||||
posts = Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
posts = Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
||||||
else:
|
else:
|
||||||
# 默认按标题和内容搜索
|
|
||||||
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED) | Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
posts = Post.objects.filter(title__icontains=query, status=Post.PUBLISHED) | Post.objects.filter(content__icontains=query, status=Post.PUBLISHED)
|
||||||
elif category_id:
|
elif category_id:
|
||||||
posts = Post.objects.filter(category_id=category_id, status=Post.PUBLISHED)
|
posts = Post.objects.filter(category_id=category_id, status=Post.PUBLISHED)
|
||||||
@@ -84,54 +28,46 @@ def index(request):
|
|||||||
|
|
||||||
posts = posts.order_by('-publish_date').distinct()
|
posts = posts.order_by('-publish_date').distinct()
|
||||||
|
|
||||||
# 为每篇文章添加摘要(根据设置的字符长度)
|
paginator = Paginator(posts, 10)
|
||||||
for post in posts:
|
page_number = request.GET.get('page')
|
||||||
import re
|
page_obj = paginator.get_page(page_number)
|
||||||
|
|
||||||
|
for post in page_obj:
|
||||||
clean_content = re.sub(r'<[^>]+>', '', post.get_markdown_content())
|
clean_content = re.sub(r'<[^>]+>', '', post.get_markdown_content())
|
||||||
post.summary = clean_content[:summary_length] + '...' if len(clean_content) > summary_length else clean_content
|
post.summary = clean_content[:summary_length] + '...' if len(clean_content) > summary_length else clean_content
|
||||||
|
|
||||||
return render(request, 'blog/index.html', {
|
return render(request, 'blog/index.html', {
|
||||||
'posts': posts,
|
'page_obj': page_obj,
|
||||||
'categories': categories,
|
'categories': categories,
|
||||||
'selected_category': category_id,
|
'selected_category': category_id,
|
||||||
'query': query,
|
'query': query,
|
||||||
'search_type': search_type,
|
'search_type': search_type,
|
||||||
'site_settings': site_settings
|
'site_settings': site_settings,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def detail(request, post_id):
|
def detail(request, post_id):
|
||||||
post = get_object_or_404(Post, pk=post_id, status=Post.PUBLISHED)
|
post = get_object_or_404(Post, pk=post_id, status=Post.PUBLISHED)
|
||||||
categories = Category.objects.all() # 获取所有分类用于侧边栏
|
categories = Category.objects.all()
|
||||||
try:
|
|
||||||
site_settings = SiteSettings.objects.first()
|
site_settings = SiteSettings.objects.first()
|
||||||
except SiteSettings.DoesNotExist:
|
|
||||||
site_settings = None
|
|
||||||
return render(request, 'blog/detail.html', {
|
return render(request, 'blog/detail.html', {
|
||||||
'post': post,
|
'post': post,
|
||||||
'categories': categories,
|
'categories': categories,
|
||||||
'site_settings': site_settings})
|
'site_settings': site_settings,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# 添加RSS页面视图
|
|
||||||
def rss_page(request):
|
def rss_page(request):
|
||||||
categories = Category.objects.all()
|
categories = Category.objects.all()
|
||||||
try:
|
|
||||||
site_settings = SiteSettings.objects.first()
|
site_settings = SiteSettings.objects.first()
|
||||||
except SiteSettings.DoesNotExist:
|
|
||||||
site_settings = None
|
|
||||||
return render(request, 'blog/rss.html', {
|
return render(request, 'blog/rss.html', {
|
||||||
'categories': categories,
|
'categories': categories,
|
||||||
'site_settings': site_settings
|
'site_settings': site_settings,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# 添加联系我页面视图
|
|
||||||
def contact_page(request):
|
def contact_page(request):
|
||||||
try:
|
|
||||||
site_settings = SiteSettings.objects.first()
|
site_settings = SiteSettings.objects.first()
|
||||||
except SiteSettings.DoesNotExist:
|
|
||||||
site_settings = None
|
|
||||||
return render(request, 'blog/contact.html', {
|
return render(request, 'blog/contact.html', {
|
||||||
'site_settings': site_settings
|
'site_settings': site_settings,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ USE_TZ = True
|
|||||||
# 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/'
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
|
|
||||||
# 添加媒体文件配置
|
# 添加媒体文件配置
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user