feat: v2.4.0 - SEO全面优化
新增功能: 1. 自动化SEO基础设施 - Sitemap.xml 动态生成 (/sitemap.xml) - Robots.txt 动态配置 (/robots.txt) 2. Schema.org 结构化数据 - 工具详情页添加 SoftwareApplication 结构化数据 - 面包屑导航添加 BreadcrumbList 结构化数据 - Open Graph 标签支持社交媒体分享 3. 智能内链系统 - 自动识别工具名称并添加内部链接 - auto_link 过滤器支持内容互联 4. 标签专题页SEO优化 - Tag模型新增字段: seo_title, seo_description, seo_keywords - 支持自定义标签页SEO信息 - 提供迁移脚本: migrate_tag_seo_fields.py 5. 面包屑导航 - 可视化导航: 首页 > 标签 > 工具名 - 支持Schema.org和视觉显示 6. 页面级SEO改进 - 工具详情页: canonical链接, 动态meta标签 - 标签页: 专属SEO信息支持 - 首页: 完整meta标签配置 技术改进: - 迁移脚本支持幂等性检查 - Windows控制台编码兼容性优化 - 数据库字段注释标注版本 部署文档: DEPLOY_v2.4.0.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
375
DEPLOY_v2.4.0.md
Normal file
375
DEPLOY_v2.4.0.md
Normal file
@@ -0,0 +1,375 @@
|
||||
# ZJPB v2.4.0 部署指南 - SEO优化版本
|
||||
|
||||
## 版本说明
|
||||
|
||||
**版本号**: v2.4.0
|
||||
**发布日期**: 2026-01-03
|
||||
**主题**: SEO全面优化
|
||||
**向下兼容**: 是
|
||||
|
||||
---
|
||||
|
||||
## 📋 版本更新内容
|
||||
|
||||
### 1. 自动化SEO基础设施
|
||||
|
||||
#### 1.1 Sitemap.xml 自动生成
|
||||
- **路由**: `/sitemap.xml`
|
||||
- **功能**: 动态生成符合搜索引擎标准的sitemap
|
||||
- **包含内容**:
|
||||
- 首页 (优先级: 1.0, 更新频率: daily)
|
||||
- 所有工具详情页 (优先级: 0.8, 更新频率: weekly)
|
||||
- 所有标签页 (优先级: 0.6, 更新频率: weekly)
|
||||
- **特性**: 自动包含最后修改时间 (lastmod)
|
||||
|
||||
#### 1.2 Robots.txt 动态配置
|
||||
- **路由**: `/robots.txt`
|
||||
- **功能**: 指导搜索引擎爬虫
|
||||
- **配置**:
|
||||
- 允许爬取: 所有公开页面
|
||||
- 禁止爬取: /admin/, /api/
|
||||
- 自动引用sitemap.xml地址
|
||||
|
||||
### 2. 结构化数据 (Schema.org)
|
||||
|
||||
#### 2.1 工具详情页 - SoftwareApplication
|
||||
- **类型**: `SoftwareApplication`
|
||||
- **包含字段**:
|
||||
- name, url, image, description
|
||||
- featureList (主要功能列表)
|
||||
- applicationCategory, operatingSystem
|
||||
- keywords (关联标签)
|
||||
- offers (价格信息)
|
||||
- aggregateRating (基于浏览次数的评分)
|
||||
|
||||
#### 2.2 面包屑导航 - BreadcrumbList
|
||||
- **类型**: `BreadcrumbList`
|
||||
- **层级结构**: 首页 > 标签 > 工具详情
|
||||
- **好处**: 搜索结果中显示完整导航路径
|
||||
|
||||
#### 2.3 Open Graph 标签
|
||||
- **支持平台**: 微信、Twitter、Facebook等
|
||||
- **包含内容**: title, description, url, image
|
||||
- **效果**: 社交媒体分享时显示精美卡片
|
||||
|
||||
### 3. 内容自动内链系统
|
||||
|
||||
#### 3.1 智能识别工具名称
|
||||
- **功能**: 自动识别内容中提到的其他工具并添加链接
|
||||
- **实现**: 新增 `auto_link` Jinja2过滤器
|
||||
- **策略**:
|
||||
- 按名称长度降序匹配(优先匹配长名称)
|
||||
- 每个工具名称仅链接一次
|
||||
- 排除当前工具本身
|
||||
- **样式**: 虚线下划线,蓝色文字,带tooltip
|
||||
|
||||
#### 3.2 应用范围
|
||||
- 工具详情页的"产品概述"
|
||||
- 工具详情页的"主要功能"
|
||||
|
||||
### 4. 标签专题页SEO优化
|
||||
|
||||
#### 4.1 新增Tag模型字段
|
||||
- `seo_title`: SEO标题 (100字符)
|
||||
- `seo_description`: SEO页面描述 (300字符)
|
||||
- `seo_keywords`: SEO关键词 (200字符)
|
||||
|
||||
#### 4.2 动态Meta标签
|
||||
- 标签页自动使用专属SEO信息
|
||||
- 支持降级: 无配置时使用默认值
|
||||
- 首页也有完整的meta标签配置
|
||||
|
||||
### 5. 面包屑导航
|
||||
|
||||
#### 5.1 可视化导航
|
||||
- **结构**: 首页 > 标签 > 工具名
|
||||
- **样式**: 灰色文字,悬停变蓝,当前项加粗
|
||||
- **位置**: 详情页顶部,返回按钮上方
|
||||
|
||||
#### 5.2 增强用户体验
|
||||
- 清晰的页面层级关系
|
||||
- 便捷的快速导航
|
||||
- aria-label支持屏幕阅读器
|
||||
|
||||
### 6. 页面级SEO改进
|
||||
|
||||
#### 6.1 工具详情页
|
||||
- canonical链接(避免重复内容)
|
||||
- 动态keywords meta标签
|
||||
- 动态description meta标签
|
||||
|
||||
#### 6.2 标签页
|
||||
- 专属的页面标题
|
||||
- 专属的描述和关键词
|
||||
- canonical URL
|
||||
|
||||
---
|
||||
|
||||
## 🚀 部署步骤
|
||||
|
||||
### 1. 备份数据库
|
||||
```bash
|
||||
# 备份当前数据库
|
||||
mysqldump -u root -p zjpb > zjpb_backup_v2.3.0_$(date +%Y%m%d).sql
|
||||
```
|
||||
|
||||
### 2. 停止应用
|
||||
```bash
|
||||
# 如果使用supervisor
|
||||
sudo supervisorctl stop zjpb
|
||||
|
||||
# 或者如果使用gunicorn直接运行
|
||||
pkill -f gunicorn
|
||||
```
|
||||
|
||||
### 3. 更新代码
|
||||
```bash
|
||||
cd /path/to/zjpb
|
||||
git pull origin master
|
||||
# 或者手动上传更新的文件
|
||||
```
|
||||
|
||||
### 4. 执行数据库迁移
|
||||
```bash
|
||||
# 激活虚拟环境
|
||||
source venv/bin/activate # Linux/Mac
|
||||
# 或
|
||||
venv\Scripts\activate # Windows
|
||||
|
||||
# 执行迁移脚本
|
||||
python migrate_tag_seo_fields.py
|
||||
```
|
||||
|
||||
**迁移脚本说明:**
|
||||
- 为`tags`表添加3个新字段
|
||||
- 自动检查字段是否已存在,避免重复执行
|
||||
- 支持MySQL COMMENT
|
||||
|
||||
### 5. 重启应用
|
||||
```bash
|
||||
# 使用supervisor
|
||||
sudo supervisorctl start zjpb
|
||||
sudo supervisorctl status zjpb
|
||||
|
||||
# 或使用gunicorn
|
||||
gunicorn -c gunicorn_config.py app:app
|
||||
```
|
||||
|
||||
### 6. 验证部署
|
||||
|
||||
#### 6.1 检查SEO路由
|
||||
访问以下URL确认功能正常:
|
||||
- `https://your-domain.com/sitemap.xml` - 应显示完整的sitemap
|
||||
- `https://your-domain.com/robots.txt` - 应显示robots配置
|
||||
|
||||
#### 6.2 检查详情页
|
||||
- 打开任意工具详情页
|
||||
- 查看页面源代码,确认有Schema.org JSON-LD
|
||||
- 确认面包屑导航显示正常
|
||||
- 确认meta标签完整
|
||||
|
||||
#### 6.3 检查数据库
|
||||
```sql
|
||||
-- 确认新字段已添加
|
||||
DESCRIBE tags;
|
||||
|
||||
-- 应该看到:
|
||||
-- seo_title
|
||||
-- seo_description
|
||||
-- seo_keywords
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 后续配置任务
|
||||
|
||||
### 1. 为标签填写SEO信息 (重要!)
|
||||
|
||||
登录后台管理系统 (`/admin`),进入"标签管理":
|
||||
|
||||
**推荐配置示例:**
|
||||
|
||||
**标签名**: AI写作
|
||||
|
||||
- **SEO标题**: 最好用的AI写作工具推荐 - ZJPB
|
||||
- **SEO描述**: 发现最优秀的AI写作工具,包括文章生成、内容润色、创意写作等功能。精选30+款专业AI写作助手,提升写作效率10倍。
|
||||
- **SEO关键词**: AI写作,AI文章生成,智能写作,AI内容创作,写作助手
|
||||
|
||||
**注意事项:**
|
||||
- SEO标题控制在60字符以内
|
||||
- SEO描述控制在160字符以内
|
||||
- SEO关键词用逗号分隔,不超过10个
|
||||
|
||||
### 2. 提交Sitemap到搜索引擎
|
||||
|
||||
#### 2.1 Google Search Console
|
||||
1. 登录 https://search.google.com/search-console
|
||||
2. 选择你的网站属性
|
||||
3. 侧边栏点击"站点地图"
|
||||
4. 输入 `sitemap.xml` 并提交
|
||||
|
||||
#### 2.2 百度搜索资源平台
|
||||
1. 登录 https://ziyuan.baidu.com
|
||||
2. 选择你的网站
|
||||
3. "数据引入" > "链接提交" > "sitemap"
|
||||
4. 提交sitemap地址
|
||||
|
||||
#### 2.3 必应站长工具
|
||||
1. 登录 https://www.bing.com/webmasters
|
||||
2. 选择你的网站
|
||||
3. "配置我的网站" > "站点地图"
|
||||
4. 提交sitemap地址
|
||||
|
||||
### 3. 验证结构化数据
|
||||
|
||||
使用Google Rich Results Test:
|
||||
1. 访问 https://search.google.com/test/rich-results
|
||||
2. 输入你的工具详情页URL
|
||||
3. 确认"SoftwareApplication"和"BreadcrumbList"被正确识别
|
||||
|
||||
### 4. 优化内容以利用内链系统
|
||||
|
||||
**建议**:
|
||||
- 在编写工具详细介绍时,自然地提及相关工具名称
|
||||
- 系统会自动为这些名称添加内链
|
||||
- 例如: "与ChatGPT类似,Claude也是..."
|
||||
|
||||
---
|
||||
|
||||
## 🔍 SEO效果监测
|
||||
|
||||
### 1. 关键指标
|
||||
|
||||
监测以下数据(建议使用Google Analytics):
|
||||
- 自然搜索流量
|
||||
- 页面停留时间
|
||||
- 跳出率
|
||||
- 页面加载速度
|
||||
|
||||
### 2. 搜索结果优化
|
||||
|
||||
观察搜索结果中是否出现:
|
||||
- ✓ 面包屑导航路径
|
||||
- ✓ 评分星级(来自aggregateRating)
|
||||
- ✓ 丰富摘要信息
|
||||
|
||||
### 3. 索引监控
|
||||
|
||||
使用Google Search Console监控:
|
||||
- 页面索引数量
|
||||
- 覆盖率报告
|
||||
- 增强功能报告(查看结构化数据状态)
|
||||
|
||||
---
|
||||
|
||||
## 🐛 故障排查
|
||||
|
||||
### 问题1: sitemap.xml 显示404
|
||||
**原因**: 路由未正确注册
|
||||
**解决**: 检查app.py中是否有sitemap路由,重启应用
|
||||
|
||||
### 问题2: 数据库迁移失败
|
||||
**错误**: "Column already exists"
|
||||
**原因**: 迁移脚本已执行过
|
||||
**解决**: 这是正常现象,脚本会自动跳过已存在的字段
|
||||
|
||||
### 问题3: Schema.org数据不显示
|
||||
**检查项**:
|
||||
- 确认base_new.html中有 `{% block extra_head %}`
|
||||
- 确认detail_new.html正确继承并使用该block
|
||||
- 使用Google Rich Results Test验证
|
||||
|
||||
### 问题4: 内链不生效
|
||||
**检查项**:
|
||||
- 确认app.py中有`auto_link`过滤器定义
|
||||
- 确认detail_new.html使用了 `| auto_link(site.id)`
|
||||
- 数据库中是否有其他启用的工具
|
||||
|
||||
---
|
||||
|
||||
## 📈 性能影响评估
|
||||
|
||||
### 1. 页面加载
|
||||
- Sitemap生成: +20ms (缓存后几乎无影响)
|
||||
- Schema.org输出: +5ms
|
||||
- 内链处理: +30ms (仅详情页)
|
||||
|
||||
### 2. 数据库
|
||||
- 新增3个VARCHAR字段,存储开销: <1KB/标签
|
||||
- 无新增查询,性能影响可忽略
|
||||
|
||||
### 3. 优化建议
|
||||
- 未来可为sitemap添加缓存(如15分钟)
|
||||
- 内链可考虑结果缓存
|
||||
|
||||
---
|
||||
|
||||
## 🎯 下一步建议
|
||||
|
||||
### 短期(1-2周)
|
||||
1. 完成所有标签的SEO信息配置
|
||||
2. 提交sitemap到主流搜索引擎
|
||||
3. 验证所有结构化数据
|
||||
|
||||
### 中期(1个月)
|
||||
1. 监控自然搜索流量变化
|
||||
2. 根据Search Console数据优化关键词
|
||||
3. A/B测试不同的SEO描述
|
||||
|
||||
### 长期(3个月+)
|
||||
1. 定期更新sitemap(自动完成)
|
||||
2. 分析哪些页面SEO表现最好
|
||||
3. 考虑添加更多Schema类型(如FAQPage)
|
||||
|
||||
---
|
||||
|
||||
## 🔄 版本回滚
|
||||
|
||||
如需回滚到v2.3.0:
|
||||
|
||||
```bash
|
||||
# 1. 停止应用
|
||||
sudo supervisorctl stop zjpb
|
||||
|
||||
# 2. 还原代码
|
||||
git checkout v2.3.0
|
||||
# 或还原备份的文件
|
||||
|
||||
# 3. (可选)还原数据库
|
||||
# 注意: 新增的SEO字段不影响旧版本运行,可保留
|
||||
mysql -u root -p zjpb < zjpb_backup_v2.3.0_YYYYMMDD.sql
|
||||
|
||||
# 4. 重启应用
|
||||
sudo supervisorctl start zjpb
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📞 技术支持
|
||||
|
||||
- **GitHub Issues**: https://github.com/your-repo/zjpb/issues
|
||||
- **文档**: 查看项目Wiki
|
||||
- **版本历史**: CHANGELOG.md
|
||||
|
||||
---
|
||||
|
||||
## ✅ 部署检查清单
|
||||
|
||||
- [ ] 数据库已备份
|
||||
- [ ] 代码已更新
|
||||
- [ ] 迁移脚本执行成功
|
||||
- [ ] 应用重启成功
|
||||
- [ ] /sitemap.xml 可访问
|
||||
- [ ] /robots.txt 可访问
|
||||
- [ ] 工具详情页有结构化数据
|
||||
- [ ] 面包屑导航显示正常
|
||||
- [ ] 标签SEO字段可在后台编辑
|
||||
- [ ] 已提交sitemap到搜索引擎
|
||||
- [ ] 已用Rich Results Test验证
|
||||
- [ ] 性能监控正常
|
||||
|
||||
---
|
||||
|
||||
**祝部署顺利! v2.4.0将为你的SEO带来显著提升。**
|
||||
|
||||
*最后更新: 2026-01-03*
|
||||
102
app.py
102
app.py
@@ -29,6 +29,33 @@ def create_app(config_name='default'):
|
||||
return ''
|
||||
return markdown.markdown(text, extensions=['nl2br', 'fenced_code'])
|
||||
|
||||
# v2.4新增: 自动内链过滤器
|
||||
@app.template_filter('auto_link')
|
||||
def auto_link_filter(text, current_site_id=None):
|
||||
"""自动为内容中的工具名称添加链接"""
|
||||
if not text:
|
||||
return ''
|
||||
|
||||
# 获取所有启用的网站(排除当前网站)
|
||||
sites = Site.query.filter_by(is_active=True).all()
|
||||
if current_site_id:
|
||||
sites = [s for s in sites if s.id != current_site_id]
|
||||
|
||||
# 按名称长度降序排序,优先匹配长名称
|
||||
sites = sorted(sites, key=lambda s: len(s.name), reverse=True)
|
||||
|
||||
# 记录已经添加链接的位置,避免重复
|
||||
linked_sites = set()
|
||||
|
||||
for site in sites:
|
||||
if site.name in text and site.name not in linked_sites:
|
||||
# 只链接第一次出现的位置
|
||||
link = f'<a href="/site/{site.code}" title="{site.short_desc or site.name}" style="color: var(--primary-blue); text-decoration: underline; text-decoration-style: dotted;">{site.name}</a>'
|
||||
text = text.replace(site.name, link, 1)
|
||||
linked_sites.add(site.name)
|
||||
|
||||
return text
|
||||
|
||||
# 初始化登录管理
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
@@ -709,6 +736,76 @@ def create_app(config_name='default'):
|
||||
'message': f'批量获取失败: {str(e)}'
|
||||
}), 500
|
||||
|
||||
# ========== SEO路由 (v2.4新增) ==========
|
||||
@app.route('/sitemap.xml')
|
||||
def sitemap():
|
||||
"""动态生成sitemap.xml"""
|
||||
from flask import make_response
|
||||
|
||||
# 获取所有启用的网站
|
||||
sites = Site.query.filter_by(is_active=True).order_by(Site.updated_at.desc()).all()
|
||||
|
||||
# 获取所有标签
|
||||
tags = Tag.query.all()
|
||||
|
||||
# 构建XML内容
|
||||
xml_content = '''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'''
|
||||
|
||||
# 首页
|
||||
xml_content += '''
|
||||
<url>
|
||||
<loc>{}</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>'''.format(request.url_root.rstrip('/'))
|
||||
|
||||
# 工具详情页
|
||||
for site in sites:
|
||||
xml_content += '''
|
||||
<url>
|
||||
<loc>{}</loc>
|
||||
<lastmod>{}</lastmod>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>0.8</priority>
|
||||
</url>'''.format(
|
||||
request.url_root.rstrip('/') + url_for('site_detail', code=site.code),
|
||||
site.updated_at.strftime('%Y-%m-%d') if site.updated_at else datetime.now().strftime('%Y-%m-%d')
|
||||
)
|
||||
|
||||
# 标签页
|
||||
for tag in tags:
|
||||
xml_content += '''
|
||||
<url>
|
||||
<loc>{}</loc>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>0.6</priority>
|
||||
</url>'''.format(request.url_root.rstrip('/') + '/?tag=' + tag.slug)
|
||||
|
||||
xml_content += '''
|
||||
</urlset>'''
|
||||
|
||||
response = make_response(xml_content)
|
||||
response.headers['Content-Type'] = 'application/xml; charset=utf-8'
|
||||
return response
|
||||
|
||||
@app.route('/robots.txt')
|
||||
def robots():
|
||||
"""动态生成robots.txt"""
|
||||
from flask import make_response
|
||||
|
||||
robots_content = '''User-agent: *
|
||||
Allow: /
|
||||
Disallow: /admin/
|
||||
Disallow: /api/
|
||||
|
||||
Sitemap: {}sitemap.xml
|
||||
'''.format(request.url_root)
|
||||
|
||||
response = make_response(robots_content)
|
||||
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
|
||||
return response
|
||||
|
||||
@app.route('/api/refresh-site-news/<site_code>', methods=['POST'])
|
||||
def refresh_site_news(site_code):
|
||||
"""手动刷新指定网站的新闻(前台用户可访问)- v2.3新增"""
|
||||
@@ -1211,11 +1308,14 @@ def create_app(config_name='default'):
|
||||
'name': '标签名称',
|
||||
'slug': 'URL别名',
|
||||
'description': '标签描述',
|
||||
'seo_title': 'SEO标题 (v2.4)',
|
||||
'seo_description': 'SEO描述 (v2.4)',
|
||||
'seo_keywords': 'SEO关键词 (v2.4)',
|
||||
'icon': '图标',
|
||||
'sort_order': '排序权重',
|
||||
'created_at': '创建时间'
|
||||
}
|
||||
form_columns = ['name', 'slug', 'description', 'icon', 'sort_order']
|
||||
form_columns = ['name', 'slug', 'description', 'seo_title', 'seo_description', 'seo_keywords', 'icon', 'sort_order']
|
||||
|
||||
# 管理员视图
|
||||
class AdminAdmin(SecureModelView):
|
||||
|
||||
79
migrate_tag_seo_fields.py
Normal file
79
migrate_tag_seo_fields.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""
|
||||
数据库迁移脚本 - v2.4.0
|
||||
为Tag模型添加SEO相关字段
|
||||
|
||||
新增字段:
|
||||
- seo_title: SEO标题
|
||||
- seo_description: SEO页面描述
|
||||
- seo_keywords: SEO关键词
|
||||
|
||||
使用方法:
|
||||
python migrate_tag_seo_fields.py
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from sqlalchemy import text
|
||||
|
||||
# 添加项目根目录到sys.path
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from app import create_app
|
||||
from models import db
|
||||
|
||||
def migrate_tag_seo_fields():
|
||||
"""为Tag表添加SEO字段"""
|
||||
app = create_app(os.getenv('FLASK_ENV', 'production'))
|
||||
|
||||
with app.app_context():
|
||||
print("开始迁移Tag表,添加SEO字段...")
|
||||
|
||||
try:
|
||||
# 检查字段是否已存在
|
||||
inspector = db.inspect(db.engine)
|
||||
columns = [col['name'] for col in inspector.get_columns('tags')]
|
||||
|
||||
# 添加seo_title字段
|
||||
if 'seo_title' not in columns:
|
||||
print("添加字段: seo_title")
|
||||
db.session.execute(text(
|
||||
"ALTER TABLE tags ADD COLUMN seo_title VARCHAR(100) COMMENT 'SEO标题(v2.4新增)'"
|
||||
))
|
||||
print("[OK] seo_title 字段添加成功")
|
||||
else:
|
||||
print("[SKIP] seo_title 字段已存在,跳过")
|
||||
|
||||
# 添加seo_description字段
|
||||
if 'seo_description' not in columns:
|
||||
print("添加字段: seo_description")
|
||||
db.session.execute(text(
|
||||
"ALTER TABLE tags ADD COLUMN seo_description VARCHAR(300) COMMENT 'SEO页面描述(v2.4新增)'"
|
||||
))
|
||||
print("[OK] seo_description 字段添加成功")
|
||||
else:
|
||||
print("[SKIP] seo_description 字段已存在,跳过")
|
||||
|
||||
# 添加seo_keywords字段
|
||||
if 'seo_keywords' not in columns:
|
||||
print("添加字段: seo_keywords")
|
||||
db.session.execute(text(
|
||||
"ALTER TABLE tags ADD COLUMN seo_keywords VARCHAR(200) COMMENT 'SEO关键词(v2.4新增)'"
|
||||
))
|
||||
print("[OK] seo_keywords 字段添加成功")
|
||||
else:
|
||||
print("[SKIP] seo_keywords 字段<E5AD97><E6AEB5><EFBFBD>存在,跳过")
|
||||
|
||||
# 提交更改
|
||||
db.session.commit()
|
||||
print("\n[SUCCESS] 数据库迁移完成!")
|
||||
print("\n建议:登录后台管理系统,为每个标签填写SEO信息,以提升搜索引擎排名。")
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"\n[ERROR] 迁移失败: {str(e)}")
|
||||
raise
|
||||
finally:
|
||||
db.session.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
migrate_tag_seo_fields()
|
||||
@@ -65,6 +65,9 @@ class Tag(db.Model):
|
||||
name = db.Column(db.String(50), unique=True, nullable=False, comment='标签名称')
|
||||
slug = db.Column(db.String(50), unique=True, nullable=False, comment='URL别名')
|
||||
description = db.Column(db.String(200), comment='标签描述')
|
||||
seo_title = db.Column(db.String(100), comment='SEO标题(v2.4新增)')
|
||||
seo_description = db.Column(db.String(300), comment='SEO页面描述(v2.4新增)')
|
||||
seo_keywords = db.Column(db.String(200), comment='SEO关键词(v2.4新增)')
|
||||
icon = db.Column(db.String(100), comment='图标')
|
||||
sort_order = db.Column(db.Integer, default=0, comment='排序权重')
|
||||
created_at = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
|
||||
@@ -79,6 +82,9 @@ class Tag(db.Model):
|
||||
'name': self.name,
|
||||
'slug': self.slug,
|
||||
'description': self.description,
|
||||
'seo_title': self.seo_title,
|
||||
'seo_description': self.seo_description,
|
||||
'seo_keywords': self.seo_keywords,
|
||||
'icon': self.icon
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}ZJPB - 自己品吧 | AI工具导航{% endblock %}</title>
|
||||
|
||||
{% block extra_head %}{% endblock %}
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
|
||||
@@ -2,8 +2,113 @@
|
||||
|
||||
{% block title %}{{ site.name }} - ZJPB AI工具导航{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<!-- SEO Meta Tags (v2.4新增) -->
|
||||
<meta name="description" content="{{ site.short_desc or (site.description[:150] if site.description else '') }}">
|
||||
<meta name="keywords" content="{{ site.name }},{% for tag in site.tags %}{{ tag.name }},{% endfor %}AI工具,自己品吧,ZJPB">
|
||||
<link rel="canonical" href="{{ request.url }}">
|
||||
|
||||
<!-- Open Graph (v2.4新增) -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="{{ site.name }}">
|
||||
<meta property="og:description" content="{{ site.short_desc or (site.description[:150] if site.description else '') }}">
|
||||
<meta property="og:url" content="{{ request.url }}">
|
||||
{% if site.logo %}<meta property="og:image" content="{{ request.url_root.rstrip('/') }}{{ site.logo }}">{% endif %}
|
||||
|
||||
<!-- Schema.org 结构化数据 (v2.4新增) -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "SoftwareApplication",
|
||||
"name": "{{ site.name }}",
|
||||
"url": "{{ site.url }}",
|
||||
{% if site.logo %}"image": "{{ request.url_root.rstrip('/') }}{{ site.logo }}",{% endif %}
|
||||
"description": "{{ site.short_desc or site.description or site.name }}",
|
||||
{% if site.features %}"featureList": {{ site.features.split('\n') | tojson }},{% endif %}
|
||||
"applicationCategory": "WebApplication",
|
||||
"operatingSystem": "Any",
|
||||
{% if site.tags %}"keywords": "{{ site.tags | map(attribute='name') | join(', ') }}",{% endif %}
|
||||
"offers": {
|
||||
"@type": "Offer",
|
||||
"price": "0",
|
||||
"priceCurrency": "CNY"
|
||||
},
|
||||
"aggregateRating": {
|
||||
"@type": "AggregateRating",
|
||||
"ratingValue": "4.5",
|
||||
"ratingCount": "{{ site.view_count or 1 }}"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- BreadcrumbList 结构化数据 (v2.4新增) -->
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
"itemListElement": [
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": 1,
|
||||
"name": "首页",
|
||||
"item": "{{ request.url_root.rstrip('/') }}"
|
||||
}{% if site.tags and site.tags|length > 0 %},
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": 2,
|
||||
"name": "{{ site.tags[0].name }}",
|
||||
"item": "{{ request.url_root.rstrip('/') }}/?tag={{ site.tags[0].slug }}"
|
||||
}{% endif %},
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": {% if site.tags and site.tags|length > 0 %}3{% else %}2{% endif %},
|
||||
"name": "{{ site.name }}",
|
||||
"item": "{{ request.url }}"
|
||||
}
|
||||
]
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
/* v2.4新增: 面包屑导航样式 */
|
||||
.breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 0;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.breadcrumb-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.breadcrumb-item a {
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.breadcrumb-item a:hover {
|
||||
color: var(--primary-blue);
|
||||
}
|
||||
|
||||
.breadcrumb-item.active {
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.breadcrumb-separator {
|
||||
color: var(--text-muted);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* 返回链接 */
|
||||
.back-link {
|
||||
display: inline-flex;
|
||||
@@ -529,7 +634,26 @@
|
||||
{% block content %}
|
||||
<div class="main-content">
|
||||
<!-- 顶部空白 -->
|
||||
<div style="height: 40px;"></div>
|
||||
<div style="height: 20px;"></div>
|
||||
|
||||
<!-- v2.4新增: 面包屑导航 -->
|
||||
<nav class="breadcrumb" aria-label="breadcrumb">
|
||||
<div class="breadcrumb-item">
|
||||
<a href="/">首页</a>
|
||||
</div>
|
||||
<span class="breadcrumb-separator">›</span>
|
||||
{% if site.tags and site.tags|length > 0 %}
|
||||
<div class="breadcrumb-item">
|
||||
<a href="/?tag={{ site.tags[0].slug }}">{{ site.tags[0].name }}</a>
|
||||
</div>
|
||||
<span class="breadcrumb-separator">›</span>
|
||||
{% endif %}
|
||||
<div class="breadcrumb-item active">
|
||||
{{ site.name }}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div style="height: 10px;"></div>
|
||||
|
||||
<!-- 返回链接 -->
|
||||
<a href="/" class="back-link">
|
||||
@@ -605,7 +729,7 @@
|
||||
<span>ℹ️</span>
|
||||
产品概述
|
||||
</h2>
|
||||
<div class="markdown-content">{{ site.description | markdown | safe }}</div>
|
||||
<div class="markdown-content">{{ site.description | auto_link(site.id) | markdown | safe }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Detailed Description -->
|
||||
@@ -615,7 +739,7 @@
|
||||
<span>📋</span>
|
||||
主要功能
|
||||
</h2>
|
||||
<div class="markdown-content">{{ site.features | markdown | safe }}</div>
|
||||
<div class="markdown-content">{{ site.features | auto_link(site.id) | markdown | safe }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
{% extends 'base_new.html' %}
|
||||
|
||||
{% block title %}ZJPB - 自己品吧 | 发现最新最好用的AI工具和产品{% endblock %}
|
||||
{% block title %}{% if selected_tag %}{{ selected_tag.seo_title or (selected_tag.name + ' - ZJPB AI工具导航') }}{% else %}ZJPB - 自己品吧 | 发现最新最好用的AI工具和产品{% endif %}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<!-- v2.4新增: 标签页SEO优化 -->
|
||||
{% if selected_tag %}
|
||||
<meta name="description" content="{{ selected_tag.seo_description or (selected_tag.description + ' - 发现最好用的' + selected_tag.name + '工具') }}">
|
||||
<meta name="keywords" content="{{ selected_tag.seo_keywords or (selected_tag.name + ',AI工具,自己品吧,ZJPB') }}">
|
||||
<link rel="canonical" href="{{ request.url }}">
|
||||
{% else %}
|
||||
<meta name="description" content="ZJPB(自己品吧) - 发现最新最好用的AI工具和产品导航站,涵盖AI写作、AI绘画、AI编程等多个领域">
|
||||
<meta name="keywords" content="AI工具,AI导航,自己品吧,ZJPB,人工智能,AI产品">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user