增添了首页加载README.md

This commit is contained in:
mxr612 2025-03-05 03:09:51 +00:00
parent f65e26e093
commit f0440a21a2
4 changed files with 34 additions and 2 deletions

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# 心尺 PsychoScales (Org)
## 什么是PsychoScales
PsychoScales网站是一个专业的心理学资源平台旨在为用户提供全面的心理学测量工具和评估资源。我们汇集了各种心理测量工具涵盖了情绪、人格、认知能力、心理健康等多个领域帮助用户更好地了解自己的心理特点和状况。
作为PsychoScales网站的用户您可以通过简单的在线测试快速获取关于自己心理特征的详细报告和分析。这些测量工具基于权威的心理学理论和研究确保了测试结果的准确性和可靠性。
[心尺主站](https://psygscales.com/)
## 什么是PsychoScales Org
这个一个开源的量表框架基于Python搭建。
本项目的量表加载完全基于json不使用任何数据库。同时也可以通过易于编辑的txt文件制作可以加载的json。
[开源地址](https://git.mxr612.io/PsychoScales/PsychoScales)

14
app.py
View File

@ -1,5 +1,6 @@
from fastapi import FastAPI, Request, HTTPException from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
import markdown
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
import json import json
@ -25,7 +26,18 @@ def load_all_scales():
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
async def index(request: Request): async def index(request: Request):
scales = load_all_scales() scales = load_all_scales()
return templates.TemplateResponse("index.html", {"request": request, "scales": scales}) # 新增读取README.md的逻辑
readme_content = ""
try:
with open("README.md", "r", encoding="utf-8") as f:
readme_content = markdown.markdown(f.read())
except FileNotFoundError:
pass # 如果README不存在则静默失败
return templates.TemplateResponse("index.html", {
"request": request,
"scales": scales,
"readme_content": readme_content # 新增模板变量
})
@app.get("/scales/{scale_id}", response_class=HTMLResponse) @app.get("/scales/{scale_id}", response_class=HTMLResponse)
async def scale(request: Request, scale_id: str): async def scale(request: Request, scale_id: str):

Binary file not shown.

View File

@ -6,7 +6,11 @@
<title>心尺 PsychoScales</title> <title>心尺 PsychoScales</title>
</head> </head>
<body> <body>
<h1>心尺 PsychoScales</h1> {% if readme_content %}
<div class="readme-section">
{{ readme_content|safe }}
</div>
{% endif %}
<ul> <ul>
{% for scale_id, scale in scales.items() %} {% for scale_id, scale in scales.items() %}
<li><a href="{{ url_for('scale', scale_id=scale_id) }}">{{ scale.get('title', '未命名问卷') }}</a></li> <li><a href="{{ url_for('scale', scale_id=scale_id) }}">{{ scale.get('title', '未命名问卷') }}</a></li>