feat(forum): 帖子正文加入站点入口
在「出处」区块之后、免责声明之前加一行: **更多优惠汇总**:https://vps.lowseek.ai/ 目的是把论坛读者导回汇总页看全部活动 —— 论坛帖子是单条, 站点才是完整列表。 复用 LDR_SITE_URL(与站点 canonical / sitemap 同源),不新增配置; 未配置时整行不输出,避免出现半截链接。 验证:205 测试通过(新增 2 个,含「未配置时不输出」)。
This commit is contained in:
1 parent
e2749d4b3e
commit
1c1ac96a3f
2 files changed
+34
No files matched your search
@@ -349,6 +349,12 @@ def build_post(rec: dict) -> tuple[str, str]:
|
||||
if age is not None:
|
||||
lines.append("**原帖发布**:%s" % ("今天" if age == 0 else "%d 天前" % age))
|
||||
|
||||
# 站点入口:让读帖的人能回到汇总页看全部活动。
|
||||
# 复用 LDR_SITE_URL(与站点 canonical/sitemap 同源),不另设配置。
|
||||
if config.SITE_URL:
|
||||
lines.append("")
|
||||
lines.append("**更多优惠汇总**:%s/" % config.SITE_URL)
|
||||
|
||||
lines.append("")
|
||||
lines.append("> 本帖由机器人自动搬运并整理,便于中文用户阅读;"
|
||||
"**价格与库存以商家页面为准**,下单前请自行核实。")
|
||||
|
||||
@@ -428,6 +428,34 @@ def test_number_formatting_drops_trailing_zero():
|
||||
"cycle": "year"}) == "€129/年"
|
||||
|
||||
|
||||
def test_build_post_includes_site_link():
|
||||
"""帖子要带站点入口,把论坛读者导回汇总页。"""
|
||||
import pytest as _pytest
|
||||
mp = _pytest.MonkeyPatch()
|
||||
mp.setattr(config, "SITE_URL", "https://vps.example.com")
|
||||
try:
|
||||
_, body = forum.build_post(_rec())
|
||||
finally:
|
||||
mp.undo()
|
||||
assert "更多优惠汇总" in body
|
||||
assert "https://vps.example.com/" in body
|
||||
# 位置应在出处之后、免责声明之前
|
||||
assert body.index("更多优惠汇总") > body.index("原帖地址")
|
||||
assert body.index("更多优惠汇总") < body.index("机器人自动搬运")
|
||||
|
||||
|
||||
def test_build_post_omits_site_link_when_unset():
|
||||
"""未配置站点地址时不输出半截链接。"""
|
||||
import pytest as _pytest
|
||||
mp = _pytest.MonkeyPatch()
|
||||
mp.setattr(config, "SITE_URL", "")
|
||||
try:
|
||||
_, body = forum.build_post(_rec())
|
||||
finally:
|
||||
mp.undo()
|
||||
assert "更多优惠汇总" not in body
|
||||
|
||||
|
||||
def test_build_post_includes_plan_table():
|
||||
rec = _rec(plans=[{"name": "Starter", "vcpu": 2, "ram_gb": 4.0,
|
||||
"storage_gb": 40.0, "bandwidth_tb": 2.0,
|
||||
|
||||
Reference in new issue
Block a user