迁移完毕.....舒服
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,4 +3,6 @@
|
|||||||
**/*.sql
|
**/*.sql
|
||||||
**/*.db.back
|
**/*.db.back
|
||||||
databases/*
|
databases/*
|
||||||
mirrors/*
|
mirrors/*
|
||||||
|
blueprint/kami_views.py
|
||||||
|
templates/kami/*
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, render_template, request, url_for, flash, redirect
|
from flask import Blueprint, render_template, request, url_for, flash, redirect, send_from_directory, make_response, current_app
|
||||||
from database import get_owp_db
|
from database import get_owp_db
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -57,4 +57,29 @@ def test_db():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"连接失败: {str(e)}"
|
return f"连接失败: {str(e)}"
|
||||||
|
|
||||||
|
######
|
||||||
|
## 网站地图 及其 robots 配置
|
||||||
|
|
||||||
|
@blog_bp.route('/robots.txt/')
|
||||||
|
def robots():
|
||||||
|
return send_from_directory(current_app.static_folder, 'robots.txt')
|
||||||
|
|
||||||
|
@blog_bp.route('/google02f6a3f6004a32c6.html')
|
||||||
|
def google02f6a3f6004a32c6():
|
||||||
|
return send_from_directory(blog_bp.static_folder, 'google02f6a3f6004a32c6.html')
|
||||||
|
|
||||||
|
|
||||||
|
@blog_bp.route('/sitemap.xml/')
|
||||||
|
def sitemap():
|
||||||
|
conn = get_owp_db_conn()
|
||||||
|
sql_posts = "SELECT * from posts;"
|
||||||
|
posts = conn.execute(sql_posts).fetchall()
|
||||||
|
conn.close()
|
||||||
|
template = render_template('sitemap.xml', posts=posts[::-1], base_url="https://open-ww3-project.ww3.tw/blog/")
|
||||||
|
response = make_response(template)
|
||||||
|
response.headers['Content-Type'] = 'application/xml'
|
||||||
|
return response
|
||||||
|
|
||||||
|
@blog_bp.errorhandler(404)
|
||||||
|
def not_found_error(error):
|
||||||
|
return '404 not found', 404
|
||||||
75
main.py
75
main.py
@@ -2,7 +2,7 @@ from flask import Flask, render_template, redirect, url_for, send_from_directory
|
|||||||
from blueprint.blog_views import blog_bp
|
from blueprint.blog_views import blog_bp
|
||||||
from blueprint.study_views import study_bp
|
from blueprint.study_views import study_bp
|
||||||
from flask_autoindex import AutoIndex
|
from flask_autoindex import AutoIndex
|
||||||
# from blueprint.admin_views import admin_bp
|
from blueprint.kami_views import kami_bp
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅
|
|||||||
# 注册蓝图
|
# 注册蓝图
|
||||||
app.register_blueprint(blog_bp, url_prefix='/blog')
|
app.register_blueprint(blog_bp, url_prefix='/blog')
|
||||||
app.register_blueprint(study_bp, url_prefix='/study')
|
app.register_blueprint(study_bp, url_prefix='/study')
|
||||||
# app.register_blueprint(admin_bp, url_prefix='/admin')
|
app.register_blueprint(kami_bp, url_prefix='/kami')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@@ -51,27 +51,64 @@ def close_connection(exception):
|
|||||||
def autoindex(path='.'):
|
def autoindex(path='.'):
|
||||||
return index.render_autoindex(path, template='mirrors.html')
|
return index.render_autoindex(path, template='mirrors.html')
|
||||||
|
|
||||||
@app.route('/robots.txt/')
|
@app.errorhandler(400)
|
||||||
def robots():
|
def bad_request(error):
|
||||||
return send_from_directory(app.static_folder, 'robots.txt')
|
return (
|
||||||
|
'400 Bad Request<br>'
|
||||||
@app.route('/google02f6a3f6004a32c6.html')
|
'请求有误,请检查参数是否正确'
|
||||||
def google02f6a3f6004a32c6():
|
'<title>400 Bad Request</title>',
|
||||||
return send_from_directory(app.static_folder, 'google02f6a3f6004a32c6.html')
|
400
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/sitemap.xml/')
|
@app.errorhandler(401)
|
||||||
def sitemap():
|
def unauthorized(error):
|
||||||
conn = get_owp_db_conn()
|
return (
|
||||||
sql_posts = "SELECT * from posts;"
|
'401 Unauthorized<br>'
|
||||||
posts = conn.execute(sql_posts).fetchall()
|
'请先登录或提供有效凭证'
|
||||||
conn.close()
|
'<title>401 Unauthorized</title>',
|
||||||
template = render_template('sitemap.xml', posts=posts[::-1], base_url="https://open-ww3-project.ww3.tw/blog/")
|
401
|
||||||
response = make_response(template)
|
)
|
||||||
response.headers['Content-Type'] = 'application/xml'
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(403)
|
||||||
|
def forbidden(error):
|
||||||
|
return (
|
||||||
|
'403 Forbidden<br>'
|
||||||
|
'你没有权限访问此资源'
|
||||||
|
'<title>403 Forbidden</title>',
|
||||||
|
403
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def not_found(error):
|
||||||
|
return (
|
||||||
|
'404 Not Found<br>'
|
||||||
|
'这里什么都没有'
|
||||||
|
'<title>404 Not Found</title>',
|
||||||
|
404
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(405)
|
||||||
|
def method_not_allowed(error):
|
||||||
|
return (
|
||||||
|
'405 Method Not Allowed<br>'
|
||||||
|
'请求方法不被允许'
|
||||||
|
'<title>405 Method Not Allowed</title>',
|
||||||
|
405
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
def internal_server_error(error):
|
||||||
|
return (
|
||||||
|
'500 Internal Server Error<br>'
|
||||||
|
'服务器开小差了,请稍后再试'
|
||||||
|
'<title>500 Internal Server Error</title>',
|
||||||
|
500
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host="0.0.0.0", port=8085, debug=True)
|
app.run(host="0.0.0.0", port=8085, debug=True)
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<url>
|
|
||||||
<loc>https://open-ww3-project.ww3.tw/blog/</loc>
|
|
||||||
<lastmod>2025-12-12</lastmod>
|
|
||||||
<priority>1.0</priority>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>https://open-ww3-project.ww3.tw/blog/about/</loc>
|
|
||||||
<lastmod>2025-12-12</lastmod>
|
|
||||||
<priority>0.8</priority>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>https://open-ww3-project.ww3.tw/blog/post/</loc>
|
|
||||||
<lastmod>2025-12-12</lastmod>
|
|
||||||
<priority>0.8</priority>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>https://open-ww3-project.ww3.tw/blog/test.html</loc>
|
|
||||||
<lastmod>2025-12-13</lastmod>
|
|
||||||
<priority>0.1</priority>
|
|
||||||
</url>
|
|
||||||
</urlset>
|
|
||||||
@@ -1,14 +1,31 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="refresh" content="2.0;url={{ url_for('blog.home') }}">
|
<!--meta http-equiv="refresh" content="2.0;url={{ url_for('blog.home') }}"-->
|
||||||
<title>不想写了</title>
|
<title>关于</title>
|
||||||
<meta charset="utf-8" lang="zh-CN">
|
<meta charset="utf-8" lang="zh-CN">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<a href="{{ url_for('blog.home') }}">返回首页</a>__<a href="{{ url_for('blog.sitemap') }}">网页地图</a>
|
||||||
|
<hr>
|
||||||
|
本站建立于大概2025年8月前后<br>
|
||||||
|
差不多是个人博客多次重建后的成果<br>
|
||||||
|
如今我已经成长很多<br>
|
||||||
|
<br>
|
||||||
|
<a href="https://wiki.ww3.tw/doku.php?id=zh_cn:skimrme">站长介绍<a>
|
||||||
|
<p>2025.12.22</p>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<hr>
|
||||||
忘记写了
|
忘记写了
|
||||||
<br>
|
<br>
|
||||||
所以暂时就不写了
|
所以暂时就不写了
|
||||||
<p>2025.08.05</p>
|
<p>2025.08.05</p>
|
||||||
<p>over</p>
|
<p>over</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -250,7 +250,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function initSakanaWidget(){
|
function initSakanaWidget(){
|
||||||
const customImageUrl = 'https://open-ww3-project.ww3.tw/blog/src/img/my_girl.png';
|
const customImageUrl = "{{ url_for('static', filename='img/my_girl.png') }}";
|
||||||
const baseCharacter = SakanaWidget.getCharacter('chisato');
|
const baseCharacter = SakanaWidget.getCharacter('chisato');
|
||||||
const myCharacter = {
|
const myCharacter = {
|
||||||
image: customImageUrl,
|
image: customImageUrl,
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
<urlset xmlns="www.sitemaps.org">
|
<urlset xmlns="www.sitemaps.org">
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ base_url }}</loc>
|
<loc>{{ base_url }}</loc>
|
||||||
|
<lastmod>2025.12.22</lastmod>
|
||||||
<changefreq>daily</changefreq>
|
<changefreq>daily</changefreq>
|
||||||
<priority>1.0</priority>
|
<priority>1.0</priority>
|
||||||
</url>
|
</url>
|
||||||
{% for posts in posts %}
|
{% for posts in posts %}
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ base_url }}posts/{{ posts['id'] }}</loc>
|
<loc>{{ base_url }}posts/{{ posts['id'] }}/</loc>
|
||||||
<lastmod>{{ posts.updated_at }}</lastmod>
|
<lastmod>{{ posts['date'] }}</lastmod>
|
||||||
<changefreq>monthly</changefreq>
|
<changefreq>monthly</changefreq>
|
||||||
<priority>0.8</priority>
|
<priority>0.8</priority>
|
||||||
</url>
|
</url>
|
||||||
|
|||||||
Reference in New Issue
Block a user