迁移基本完成,还有一些页面需要核对

This commit is contained in:
2025-12-22 16:55:31 +08:00
parent 7e44fe8a2a
commit 49fe419232
16 changed files with 327 additions and 24 deletions

1
.gitignore vendored Normal file → Executable file
View File

@@ -3,3 +3,4 @@
**/*.sql **/*.sql
**/*.db.back **/*.db.back
databases/* databases/*
mirrors/*

View File

@@ -1,20 +1,51 @@
from flask import Blueprint, render_template from flask import Blueprint, render_template, request, url_for, flash, redirect
from database import get_owp_db from database import get_owp_db
import os import os
import sqlite3
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__) blog_bp = Blueprint('blog', __name__)
@blog_bp.route('/') @blog_bp.route('/')
def home(): def home():
db = get_owp_db() db = get_owp_db()
return render_template('home.html') conn = get_owp_db_conn()
sql_logs = "SELECT * from logs;"
sql_posts = "SELECT * from posts;"
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])
@blog_bp.route('/about/') @blog_bp.route('/about/')
def about(): def about():
return render_template('about.html') return render_template('about.html')
pass pass
@blog_bp.route('/posts/')
def posts_list():
conn = get_owp_db_conn()
sql_posts = "SELECT * from posts;"
posts = conn.execute(sql_posts).fetchall()
conn.close()
return render_template('list.html', posts=posts[::-1])
@blog_bp.route('/posts/<int:posts_id>/')
def show_posts_id(posts_id):
conn = get_owp_db_conn()
sql_posts = "SELECT * FROM posts WHERE id = ?"
posts = conn.execute(sql_posts, (posts_id,)).fetchone()
conn.close()
return render_template('posts.html', posts=posts)
# 数据库测试
@blog_bp.route('/db_test/') @blog_bp.route('/db_test/')
def test_db(): def test_db():
db = get_owp_db() db = get_owp_db()

View File

@@ -1,7 +1,7 @@
import sqlite3 import sqlite3
from flask import g from flask import g
DATABASE_owp = '/var/databases/sqlite/owp.db' DATABASE_owp = '/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db'
def get_owp_db(): def get_owp_db():
db = getattr(g, '_database', None) db = getattr(g, '_database', None)

38
main.py
View File

@@ -1,11 +1,21 @@
from flask import Flask, render_template, redirect, url_for, g from flask import Flask, render_template, redirect, url_for, send_from_directory, make_response, g
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 blueprint.admin_views import admin_bp # from blueprint.admin_views import admin_bp
import os import os
import sqlite3
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
app = Flask(__name__, static_url_path='/static/') 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 # session
#app.secret_key = "508948973a8651f160baf3b26f18c47d" #app.secret_key = "508948973a8651f160baf3b26f18c47d"
app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅都凍芝西鄂' app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅都凍芝西鄂'
@@ -21,7 +31,7 @@ app.register_blueprint(study_bp, url_prefix='/study')
@app.route('/') @app.route('/')
def repage(): def repage():
# return '<meta http-equiv="refresh" content="0.1;url=/blog/">' # return '<meta http-equiv="refresh" content="0.1;url=/blog/">'
return redirect(url_for('study.home')) return redirect(url_for('blog.home'))
@app.route('/greet/<name>/') @app.route('/greet/<name>/')
@@ -35,5 +45,29 @@ def close_connection(exception):
if db is not None: if db is not None:
db.close() db.close()
@app.route('/mirrors/')
@app.route('/mirrors/<path:path>')
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('/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
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)

5
static/js/alpine.js Normal file

File diff suppressed because one or more lines are too long

7
static/robots.txt Normal file
View File

@@ -0,0 +1,7 @@
User-agent: *
Allow: /
Disallow: /admin/
Sitemap: https://open-ww3-project.ww3.tw/blog/sitemap.xml

23
static/sitemap.xml Normal file
View File

@@ -0,0 +1,23 @@
<?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>

View File

@@ -1,5 +1,6 @@
<html> <html>
<head> <head>
<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>

View File

@@ -17,15 +17,16 @@
<table border="0" style="background-color: rgba(147, 185, 255, 0.644);"> <table border="0" style="background-color: rgba(147, 185, 255, 0.644);">
<tbody> <tbody>
<tr> <tr>
<td id="td_navbar_40px"><b><a href="https://ww3.tw/" id="url_">首页</a></b></td> <td id="td_navbar_40px"><b><a href="{{ url_for('blog.home') }}" id="url_">首页</a></b></td>
<td id="td_navbar_40px"><b><a href="https://ww3.tw/blog/about/" id="url_">关于</a></b></td> <td id="td_navbar_40px"><b><a href="{{ url_for('blog.about') }}" id="url_">关于</a></b></td>
<td id="td_navbar_40px"><b><a href="https://ww3.tw/blog/post/" id="url_">文章</a></b></td> <td id="td_navbar_40px"><b><a href="{{ url_for('blog.posts_list') }}" id="url_">文章</a></b></td>
<td id="td_navbar_75px"><b><a href="https://ww3.tw/jumping-message/" id="url_">弹幕留言</a></b></td> <td id="td_navbar_75px"><b><a href="#" id="url_">弹幕留言</a></b></td>
<td id="td_navbar_78px"><b><a href="https://ww3.tw/short-url/" id="url_">短链生成</a></b></td> <td id="td_navbar_78px"><b><a href="#" id="url_">短链生成</a></b></td>
<td id="td_navbar_52px"><b><a href="https://gitea.ww3.tw/skimrme/" id="url_">gitea</a></b></td> <td id="td_navbar_52px"><b><a href="https://gitea.ww3.tw/skimrme/" id="url_">gitea</a></b></td>
<td id="td_navbar_160px"><b><a href="https://ww3.tw/docker-registry/" id="url_">docker-registry</a></b></td> <td id="td_navbar_140px"><b><a href="https://ww3.tw/docker-registry/" id="url_">docker-registry</a></b></td>
<td id="td_navbar_40px"><b><a href="https://api.ww3.tw/" id="url_">api</a></b></td> <td id="td_navbar_40px"><b><a href="https://api.ww3.tw/" id="url_">api</a></b></td>
<td id="td_navbar_40px"><b><a href="https://wiki.ww3.tw/" id="url_">wiki</a></b></td> <td id="td_navbar_40px"><b><a href="https://wiki.ww3.tw/" id="url_">wiki</a></b></td>
<td id="td_navbar_52px"><b><a href="/mirrors" id="url_">mirrors</a></b></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -47,10 +48,20 @@
<font size="3.2"> <font size="3.2">
<table border="0"> <table border="0">
<tbody> <tbody>
<?php {# 调用数据库 #}
// 引入数据库 sqlite {% for logs in logs %}
include "./logs.php.text"; <tr>
?> <td id="td_logs">
<a style='font-size: 18px;'>
{{ logs['date'] }}
</a>
<br>
</td>
<td id="td_logs_content">
{{ logs['content'].replace('&&', '<br>') | safe }}
</td>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
</font> </font>
@@ -58,6 +69,7 @@
<!-- 屑站日志 --> <!-- 屑站日志 -->
<div id="post_content"> <div id="post_content">
{#
<?php <?php
//include "post/index.php"; //include "post/index.php";
// 设定数据库路径 // 设定数据库路径
@@ -105,6 +117,22 @@
$db->close(); $db->close();
} }
?> ?>
#}
<center><b><h2>全部文章</h2></b></center>
<br>
文章如下↓
<br>
<br>
{% for posts in posts %}
文章id:{{ posts['id'] }}
<br>
{{ posts['date'] }}
{{ posts['title'] }}
<br>
<a href="{{ url_for('blog.posts_list') }}{{ posts['id'] }}">页面跳转</a>
<br>
<br>
{% endfor %}
</div> </div>
</div> </div>
<!-- 私の娘 --> <!-- 私の娘 -->
@@ -118,6 +146,10 @@
<!-- css 部分 --> <!-- css 部分 -->
<style> <style>
a {
text-decoration: none;
}
#navbar1 { #navbar1 {
margin: -160px 0 100px -30px; margin: -160px 0 100px -30px;
} }
@@ -142,9 +174,9 @@
width: 78px; width: 78px;
} }
#td_navbar_160px #td_navbar_140px
{ {
width: 160px; width: 140px;
} }
/* 日志 */ /* 日志 */
@@ -233,7 +265,9 @@
size: 200, size: 200,
autoFit: true, autoFit: true,
controls: true controls: true
}).mount('#my_girl'); })
.setState({ y: 0, t: 0, w: 0, r: 0 })
.mount('#my_girl');
} }
</script> </script>

100
templates/list.html Normal file
View File

@@ -0,0 +1,100 @@
<!DOCTYPE id="html" html>
<html>
<head>
<link rel="icon" type="image/x-icon" href="https://ww3.tw/blog/icon/original.ico">
<title>文章列表</title> <!-- 标题 -->
</head>
<body id="wallpaper" >
<!-- 背景 -->
<div id="div_1">
<a href='{{ url_for("blog.home") }}' style='background-color: rgba(147, 185, 255, 0)'>返回首页</a>
<center id="center_2"><b><h2>全部文章</h2></b></center>
<br>
<div id="posts_list">文章如下↓</div>
<br>
<br>
<br>
<div id='content'>
{% for posts in posts %}
<div id="posts_bian_kuang">
<br>
<br>
文章id:{{ posts['id'] }}
<br>
文章标题:{{ posts['title'] }}
<br>
<a href="{{ url_for('blog.posts_list') }}{{ posts['id'] }}">页面跳转</a>__{{ posts['date'] }}
</div>
<br>
<br>
{% endfor %}
</div>
</div>
</body>
{# 随机变换图床api #}
{% 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 %}
</html>
<style>
#center_2 {
width: 100%;
height: 40px;
background-color: rgba(255, 255, 255, 0.415);
text-align: center;
margin: -55px 0 0 0;
}
#posts_list {
width: 90px;
height: 30px;
background-color: rgba(255, 255, 255, 0.415);
}
#posts_bian_kuang {
width: 600px;
height: 200px;
background-color: rgba(255, 255, 255, 0.415);
}
a {
text-decoration: none;
}
html {
margin: 0 0 0 0;
}
#wallpaper {
background-image: url('{{ wallpaper }}');
background-size: cover;
background-repeat: no-repeat; /*禁止平铺*/
background-size: 100% 100%; /*图片占满100%*/
margin: 0; /* 外边框为0 */
/*padding: 0;*/
}
#div_1 {
height: 100%;
color: rgb(0, 0, 0);
font-size: 19px;
background-color: rgba(169, 169, 169, 0.212);
overflow-y: auto;
}
#content {
/* up、right、down、left */
margin: 0px 0px 0px 100px;
}
#wallpaper_url {
color: rgba(255, 0, 0, 0.354);
/* up、right、down、left */
margin: 20% 0px 0px 75%;
}
</style>

28
templates/mirrors.html Normal file
View File

@@ -0,0 +1,28 @@
{% extends '__autoindex__/autoindex.html' %}
{% block header %}
<h1 style="width: 80%; background-color: #fbecec7d; margin-left: auto; margin-right: auto;">index of .</h1>
<br>
<br>
<br>
<style>
body {
background-image: url('https://moe.jitsu.top/img/?sort=pc');
background-size: cover;
background-repeat: no-repeat; /*禁止平铺*/
margin: 0; /* 外边框为0 */
}
table {
width: 80%;
margin-left: auto;
margin-right: auto;
}
</style>
{% endblock %}
{% block footer %}
<hr>
<div style="text-align: right; color: #fb8888; background-color: rgba(229, 229, 255, 0); width: 300px; margin: -13.82% 0 0 70.45%;">
© 2025 open-ww3-project
</div>
{% endblock %}

14
templates/posts.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ posts['title'] }}</title>
</head>
<body>
<a href="../">返回上级</a>
<br>
{{ posts['title'] }}
<br>
<br>
{{ posts['content'] | safe}}
</body>
</html>

16
templates/sitemap.xml Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="www.sitemaps.org">
<url>
<loc>{{ base_url }}</loc>
<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>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
{% endfor %}
</urlset>

View File

@@ -24,9 +24,14 @@
</div> </div>
</td> </td>
<td> <td>
<div class="url"> <div style="margin: -5px 0 0 10px;" class="url" x-data="{ open: false }">
<div class="url" @click="open = true">子功能</div>
<div x-show="open" @click.away="open = false">
<div>
<a href="/study/posts/new" class="url">新建文章</a> <a href="/study/posts/new" class="url">新建文章</a>
</div> </div>
</div>
</div>
</td> </td>
</tr> </tr>
</table> </table>
@@ -52,3 +57,5 @@
text-decoration: none; text-decoration: none;
} }
</style> </style>
<script src="{{ url_for('static', filename='js/alpine.js') }}">vue_global</script>

View File

@@ -5,7 +5,9 @@
{% block title %} 新建文章 {% endblock %} {% block title %} 新建文章 {% endblock %}
{% block content %} {% block content %}
<br>
<br>
<br>
<form method="post"> <form method="post">
<div class="form-group"> <div class="form-group">
<label for="title">标题</label> <label for="title">标题</label>