diff --git a/.gitignore b/.gitignore index 3ab65af..db01f67 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ databases/* mirrors/* blueprint/kami_views.py -templates/kami/* \ No newline at end of file +templates/kami/* +static/upload/* \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blueprint/blog_views.py b/blueprint/blog_views.py index 6581767..3b941fd 100755 --- a/blueprint/blog_views.py +++ b/blueprint/blog_views.py @@ -1,46 +1,54 @@ 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 flask_autoindex import AutoIndex import os import sqlite3 +import time def get_owp_db_conn(): conn = sqlite3.connect('/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db') conn.row_factory = sqlite3.Row return conn + blog_bp = Blueprint('blog', __name__) +index_path = '/var/open-ww3-project-ww3-tw/mirrors/' +index = AutoIndex(blog_bp, browse_root=index_path, add_url_rules=False) + @blog_bp.route('/') def home(): db = get_owp_db() conn = get_owp_db_conn() sql_logs = "SELECT * from logs;" - sql_posts = "SELECT * from posts;" + sql_posts = "SELECT * from posts where status= 1;" logs = conn.execute(sql_logs).fetchall() posts = conn.execute(sql_posts).fetchall() conn.close() - return render_template('home.html', logs=logs[::-1], posts=posts[::-1]) + return render_template('blog/home.html', logs=logs[::-1], posts=posts[::-1]) @blog_bp.route('/about/') def about(): - return render_template('about.html') + return render_template('blog/about.html') pass @blog_bp.route('/posts/') def posts_list(): conn = get_owp_db_conn() - sql_posts = "SELECT * from posts;" + sql_posts = "SELECT * from posts where status= 1;" posts = conn.execute(sql_posts).fetchall() conn.close() - return render_template('list.html', posts=posts[::-1]) + return render_template('blog/list.html', posts=posts[::-1]) @blog_bp.route('/posts//') def show_posts_id(posts_id): conn = get_owp_db_conn() - sql_posts = "SELECT * FROM posts WHERE id = ?" + sql_posts = "SELECT * FROM posts WHERE status = 1 AND id = ?" posts = conn.execute(sql_posts, (posts_id,)).fetchone() conn.close() - return render_template('posts.html', posts=posts) + if posts is None: + return f'未找到该文章{posts_id}未找到该文章{posts_id}', 404 + return render_template('blog/posts.html', posts=posts) @@ -72,14 +80,32 @@ def google02f6a3f6004a32c6(): @blog_bp.route('/sitemap.xml/') def sitemap(): conn = get_owp_db_conn() - sql_posts = "SELECT * from posts;" + sql_posts = "SELECT * from posts where status = 1;" 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/") + template = render_template('blog/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 \ No newline at end of file +@blog_bp.route('/kami/') +def kami(): + return redirect(url_for('kami.home')) + +@blog_bp.route('/mirrors/') +@blog_bp.route('/mirrors/') +def autoindex(path='.'): + return index.render_autoindex(path, template='blog/mirrors.html') + + +@blog_bp.route('/upload/', methods=['POST' , 'GET']) +def upload(): + if request.method == "POST": + f = request.files.get('img') + filename = f.filename + with open(f'/var/open-ww3-project-ww3-tw/static/upload/img/{filename}', 'wb') as tf: + tf.write(f.read()) + return '上传成功' + img_files = '/var/open-ww3-project-ww3-tw/static/upload/img/' + images = [img for img in os.listdir(img_files) if img.endswith(('.png', '.jpg', '.jpeg', '.gif'))] + return render_template('blog/upload.html', images=images) \ No newline at end of file diff --git a/blueprint/index_views.py b/blueprint/index_views.py new file mode 100644 index 0000000..2ea4b18 --- /dev/null +++ b/blueprint/index_views.py @@ -0,0 +1,17 @@ +from flask import Blueprint, render_template, url_for, redirect +import sqlite3 +import os + +index_bp = Blueprint('/', __name__) + +@index_bp.route('/') +def repage(): + return redirect(url_for('blog.home')) + +@index_bp.route('/mirrors/') +def mirrors(): + return redirect(url_for('blog.autoindex')) + +@index_bp.route('/greet//') +def greet(name): + return f'Hello, {name}!' \ No newline at end of file diff --git a/main.py b/main.py index d9da5ae..40748db 100755 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from blueprint.blog_views import blog_bp from blueprint.study_views import study_bp from flask_autoindex import AutoIndex from blueprint.kami_views import kami_bp +from blueprint.index_views import index_bp import os import sqlite3 @@ -13,8 +14,6 @@ def get_owp_db_conn(): app = Flask(__name__, static_url_path='/static/') -index_path = '/var/open-ww3-project-ww3-tw/mirrors/' -index = AutoIndex(app, browse_root=index_path, add_url_rules=False) # session #app.secret_key = "508948973a8651f160baf3b26f18c47d" @@ -26,18 +25,11 @@ app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅 app.register_blueprint(blog_bp, url_prefix='/blog') app.register_blueprint(study_bp, url_prefix='/study') app.register_blueprint(kami_bp, url_prefix='/kami') +app.register_blueprint(index_bp, url_prefix='/') -@app.route('/') -def repage(): - # return '' - return redirect(url_for('blog.home')) -@app.route('/greet//') -def greet(name): - return f'Hello, {name}!' - # 全局清理关闭数据库连接 @app.teardown_appcontext def close_connection(exception): @@ -46,10 +38,6 @@ def close_connection(exception): db.close() -@app.route('/mirrors/') -@app.route('/mirrors/') -def autoindex(path='.'): - return index.render_autoindex(path, template='mirrors.html') @app.errorhandler(400) def bad_request(error): diff --git a/static/google02f6a3f6004a32c6.html b/static/google02f6a3f6004a32c6.html old mode 100644 new mode 100755 diff --git a/static/robots.txt b/static/robots.txt index a1acd26..75218a8 100755 --- a/static/robots.txt +++ b/static/robots.txt @@ -2,6 +2,6 @@ User-agent: * Allow: / -Disallow: /admin/ +Disallow: /kami/ Sitemap: https://open-ww3-project.ww3.tw/blog/sitemap.xml \ No newline at end of file diff --git a/static/tui_jian/index.html b/static/tui_jian/index.html old mode 100644 new mode 100755 diff --git a/static/video.html b/static/video.html old mode 100644 new mode 100755 diff --git a/templates/about.html b/templates/blog/about.html similarity index 100% rename from templates/about.html rename to templates/blog/about.html diff --git a/templates/blog/home.html b/templates/blog/home.html new file mode 100644 index 0000000..6dc3d50 --- /dev/null +++ b/templates/blog/home.html @@ -0,0 +1,83 @@ +{# 引入base #} +{% extends 'blog/home_base.html' %} + +{# 引入标题 #} +{% block title %}首页{% endblock %} + +{% block logs_and_page %} +

欢迎访问open-ww3-project

+ +

屑站日志:

+
+ + + + {# 调用数据库 #} + {% for logs in logs %} + + + + + {% endfor %} + +
+ + {{ logs['date'].replace('.', '-') }} + +
+
+ {{ logs['content'].replace('&&', '
') | safe }} +
+
+
+ +
+

全部文章

+ 文章如下↓ +
+
+ {% for posts in posts %} + 文章id:{{ posts['id'] }} +
+ 标题: {{ posts['title'] }} +
+ 日期: {{ posts['date'].replace('.', '-')}} + 页面跳转 +
+
+ {% endfor %} +
+ + + + +{% endblock %} \ No newline at end of file diff --git a/templates/blog/home_base.html b/templates/blog/home_base.html new file mode 100644 index 0000000..7670168 --- /dev/null +++ b/templates/blog/home_base.html @@ -0,0 +1,142 @@ +{# base模板 #} + + + + + + + {% block title %}{% endblock %} | ww3 + + + {% set navbar_list = [ + {"id":1, "name": "首页", "url": url_for('blog.home')}, + {"id":2, "name": "关于", "url": url_for('blog.about')}, + {"id":3, "name": "文章", "url": url_for('blog.posts_list')}, + {"id":4, "name": "mirrors", "url": url_for('blog.autoindex')}, + {"id":5, "name": "study", "url": url_for('study.home')}, + ]%} + + {% set wallpaper_apis =[ + 'https://www.loliapi.com/acg/pc/', + 'https://api.sretna.cn/api/pc.php', + 'https://www.api.plus/API/dongman/', + 'https://moe.jitsu.top/img/?sort=pc', + 'https://www.dmoe.cc/random.php', + 'https://api.r10086.com/樱道随机图片api接口.php?图片系列=猫娘1', + 'https://api.mtyqx.cn/tapi/random.php'] %} + {% set wallpaper = wallpaper_apis | random %} +
+

一个致力于分享个人学习到的知识的记录形式的屑站

+

在这里,我会分享我学到的计算机知识或者记录一些自己经常碰到的问题

+
+ +
+ {% block logs_and_page %} + {# 这里存放写入模板的数据 #} + {% endblock %} +
+ +
+ + + +{# css部分 #} + \ No newline at end of file diff --git a/templates/list.html b/templates/blog/list.html similarity index 100% rename from templates/list.html rename to templates/blog/list.html diff --git a/templates/mirrors.html b/templates/blog/mirrors.html similarity index 83% rename from templates/mirrors.html rename to templates/blog/mirrors.html index de6b687..2a65895 100755 --- a/templates/mirrors.html +++ b/templates/blog/mirrors.html @@ -22,7 +22,7 @@ {% block footer %}
-
+
© 2025 open-ww3-project
{% endblock %} \ No newline at end of file diff --git a/templates/blog/posts.html b/templates/blog/posts.html new file mode 100755 index 0000000..77052cb --- /dev/null +++ b/templates/blog/posts.html @@ -0,0 +1,19 @@ + + + + {{ posts['title'] }} + + +
返回上级 +
+

{{ posts['title'] }}

+
+
+ {{ posts['content'].replace('&a&a','') | safe}} + + + \ No newline at end of file diff --git a/templates/blog/sitemap.xml b/templates/blog/sitemap.xml new file mode 100755 index 0000000..274cf0e --- /dev/null +++ b/templates/blog/sitemap.xml @@ -0,0 +1,29 @@ + + + + {{ base_url }} + 2025-12-22 + daily + 1.0 + + {% for post in posts %} + + {{ base_url }}posts/{{ post['id'] }}/ + {{ post['date'].replace('.', '-') }} + monthly + 0.8 + + {% endfor %} + + {{ base_url }}posts/ + 2025-12-23 + daily + 0.8 + + + {{ base_url }}mirrors/ + 2025-12-23 + daily + 0.8 + + \ No newline at end of file diff --git a/templates/blog/upload.html b/templates/blog/upload.html new file mode 100644 index 0000000..29dc6a6 --- /dev/null +++ b/templates/blog/upload.html @@ -0,0 +1,19 @@ +上传文件 +上传文件 +
+目前只支持jpg, jpeg, png, gif +
+ + +
+
+
+已上传图片 +
+
+
+{% for image in images %} + + {{ image }} + +{% endfor %} \ No newline at end of file diff --git a/templates/home.html b/templates/home.html deleted file mode 100755 index 9a57ff6..0000000 --- a/templates/home.html +++ /dev/null @@ -1,277 +0,0 @@ - - - - 首页 | ww3 - - - - - - -
-
-

open-ww3-project

-
- - - -
- open-ww3-project-img -
- - - gitea - - - -
- -

屑站日志:

-
- - - - {# 调用数据库 #} - {% for logs in logs %} - - - - - {% endfor %} - -
- - {{ logs['date'] }} - -
-
- {{ logs['content'].replace('&&', '
') | safe }} -
-
-
- - -
- {# - "; - // 如果连接成功,但是内部状态有问题 - if ($db->lastErrorCode() !==0) { - // 依旧显示为连接失败 - die("数据库连接失败"); - } - - // 内容区 - // 执行sql命令 查询表单 - $select_id_date_title_from_posts_btos /*查询posts表单中的id date title id从大到小排列*/ = $db->query('SELECT id, date, title FROM posts ORDER BY id DESC'); // 执行查询posts表单中的id date title id从大到小排列的命令 - // 循环 写入 - - echo "

全部文章

"; - echo "
"; - echo "文章如下↓"; - echo "
"; - echo "
"; - - while ($row = $select_id_date_title_from_posts_btos->fetchArray(SQLITE3_ASSOC)) { - - echo "文章id: " . $row['id'] . "
"; - echo $row['date'] . "   " . "文章标题: " . $row['title'] . "
"; - echo "页面跳转

"; - } - - - - // 关闭数据库连接 - $db->close(); - - // 捕获php报错 - } catch (Exception $e) { - // 依旧显示为连接失败 - die("数据库连接失败"); - // 关闭数据库连接 - $db->close(); - } - ?> - #} -

全部文章

-
- 文章如下↓ -
-
- {% for posts in posts %} - 文章id:{{ posts['id'] }} -
- {{ posts['date'] }} - {{ posts['title'] }} -
- 页面跳转 -
-
- {% endfor %} -
-
- -
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/templates/posts.html b/templates/posts.html deleted file mode 100755 index 88cb33d..0000000 --- a/templates/posts.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - {{ posts['title'] }} - - - 返回上级 -
- {{ posts['title'] }} -
-
- {{ posts['content'] | safe}} - - \ No newline at end of file diff --git a/templates/sitemap.xml b/templates/sitemap.xml deleted file mode 100755 index a28d9a9..0000000 --- a/templates/sitemap.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - {{ base_url }} - 2025.12.22 - daily - 1.0 - - {% for posts in posts %} - - {{ base_url }}posts/{{ posts['id'] }}/ - {{ posts['date'] }} - monthly - 0.8 - - {% endfor %} -