Fix roll docs page by resolving markdown from repo root.
The /strategy/roll/docs link looked under lib/strategy/ while 顺势加仓滚仓说明.md lives at the repository root. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -129,8 +129,8 @@ def register_strategy_trading(app: Flask, cfg: dict[str, Any]) -> None:
|
|||||||
@_lr
|
@_lr
|
||||||
@app.route("/strategy/roll/docs")
|
@app.route("/strategy/roll/docs")
|
||||||
def strategy_roll_docs():
|
def strategy_roll_docs():
|
||||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "顺势加仓滚仓说明.md")
|
path = _resolve_roll_doc_path()
|
||||||
if not os.path.isfile(path):
|
if not path:
|
||||||
flash("滚仓说明文档不存在")
|
flash("滚仓说明文档不存在")
|
||||||
return redirect(url_for("strategy_trading_page"))
|
return redirect(url_for("strategy_trading_page"))
|
||||||
with open(path, encoding="utf-8") as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
@@ -142,6 +142,19 @@ def register_strategy_trading(app: Flask, cfg: dict[str, Any]) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_roll_doc_path() -> str | None:
|
||||||
|
"""滚仓说明 md:优先包内,否则仓库根目录(顺势加仓滚仓说明.md)."""
|
||||||
|
here = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
name = "顺势加仓滚仓说明.md"
|
||||||
|
for path in (
|
||||||
|
os.path.join(here, name),
|
||||||
|
os.path.normpath(os.path.join(here, "..", "..", name)),
|
||||||
|
):
|
||||||
|
if os.path.isfile(path):
|
||||||
|
return path
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _roll_doc_markdown_to_html(text: str) -> str:
|
def _roll_doc_markdown_to_html(text: str) -> str:
|
||||||
"""轻量 Markdown → HTML(仅供滚仓说明页)."""
|
"""轻量 Markdown → HTML(仅供滚仓说明页)."""
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
|
|||||||
Reference in New Issue
Block a user