迁移完毕.....舒服
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@
|
||||
**/*.db.back
|
||||
databases/*
|
||||
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
|
||||
import os
|
||||
import sqlite3
|
||||
@@ -57,4 +57,29 @@ def test_db():
|
||||
except Exception as 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.study_views import study_bp
|
||||
from flask_autoindex import AutoIndex
|
||||
# from blueprint.admin_views import admin_bp
|
||||
from blueprint.kami_views import kami_bp
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
@@ -25,7 +25,7 @@ app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅
|
||||
# 注册蓝图
|
||||
app.register_blueprint(blog_bp, url_prefix='/blog')
|
||||
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('/')
|
||||
@@ -51,27 +51,64 @@ def close_connection(exception):
|
||||
def autoindex(path='.'):
|
||||
return index.render_autoindex(path, template='mirrors.html')
|
||||
|
||||
@app.route('/robots.txt/')
|
||||
def robots():
|
||||
return send_from_directory(app.static_folder, 'robots.txt')
|
||||
|
||||
@app.route('/google02f6a3f6004a32c6.html')
|
||||
def google02f6a3f6004a32c6():
|
||||
return send_from_directory(app.static_folder, 'google02f6a3f6004a32c6.html')
|
||||
@app.errorhandler(400)
|
||||
def bad_request(error):
|
||||
return (
|
||||
'400 Bad Request<br>'
|
||||
'请求有误,请检查参数是否正确'
|
||||
'<title>400 Bad Request</title>',
|
||||
400
|
||||
)
|
||||
|
||||
|
||||
@app.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
|
||||
@app.errorhandler(401)
|
||||
def unauthorized(error):
|
||||
return (
|
||||
'401 Unauthorized<br>'
|
||||
'请先登录或提供有效凭证'
|
||||
'<title>401 Unauthorized</title>',
|
||||
401
|
||||
)
|
||||
|
||||
|
||||
@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__':
|
||||
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,10 +1,21 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="2.0;url={{ url_for('blog.home') }}">
|
||||
<title>不想写了</title>
|
||||
<!--meta http-equiv="refresh" content="2.0;url={{ url_for('blog.home') }}"-->
|
||||
<title>关于</title>
|
||||
<meta charset="utf-8" lang="zh-CN">
|
||||
</head>
|
||||
<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>
|
||||
所以暂时就不写了
|
||||
@@ -12,3 +23,9 @@
|
||||
<p>over</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
@@ -250,7 +250,7 @@
|
||||
|
||||
<script>
|
||||
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 myCharacter = {
|
||||
image: customImageUrl,
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
<urlset xmlns="www.sitemaps.org">
|
||||
<url>
|
||||
<loc>{{ base_url }}</loc>
|
||||
<lastmod>2025.12.22</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
{% for posts in posts %}
|
||||
<url>
|
||||
<loc>{{ base_url }}posts/{{ posts['id'] }}</loc>
|
||||
<lastmod>{{ posts.updated_at }}</lastmod>
|
||||
<loc>{{ base_url }}posts/{{ posts['id'] }}/</loc>
|
||||
<lastmod>{{ posts['date'] }}</lastmod>
|
||||
<changefreq>monthly</changefreq>
|
||||
<priority>0.8</priority>
|
||||
</url>
|
||||
|
||||
Reference in New Issue
Block a user