This commit is contained in:
ddrwode
2026-02-10 11:49:01 +08:00
parent 742b1286c9
commit d29515598d
11 changed files with 165 additions and 46 deletions

82
app.py
View File

@@ -638,14 +638,96 @@ def _forum_redirect_with_msg(post_id, text_msg):
return redirect(url_for("forum_post_detail", post_id=post_id, msg=text_msg)) return redirect(url_for("forum_post_detail", post_id=post_id, msg=text_msg))
# 首页多语言文案(中文 / English
I18N = {
"zh": {
"tagline": "云服务器价格一目了然",
"filter_provider": "厂商",
"filter_region": "区域",
"filter_memory": "内存 ≥",
"filter_price": "价格区间",
"filter_currency": "货币",
"search_placeholder": "搜索厂商、配置...",
"all": "全部",
"unlimited": "不限",
"btn_reset": "重置筛选",
"th_provider": "厂商",
"th_country": "国家",
"th_config": "配置",
"th_vcpu": "vCPU",
"th_memory": "内存",
"th_storage": "存储",
"th_bandwidth": "带宽",
"th_traffic": "流量",
"th_price": "月付价格",
"th_action": "操作",
"disclaimer": "* 价格仅供参考,以各厂商官网为准。部分为按量/包年折算月价。",
"footer_note": "数据仅供参考 · 请以云厂商官网实时报价为准",
"contact_label": "联系我们",
"empty_state": "未找到匹配的方案",
"load_error": "数据加载失败,请刷新页面重试",
"search_label": "搜索",
"price_under50": "< ¥50",
"price_50_100": "¥50-100",
"price_100_300": "¥100-300",
"price_300_500": "¥300-500",
"price_over500": "> ¥500",
"cny": "人民币 (¥)",
"usd": "美元 ($)",
},
"en": {
"tagline": "VPS & cloud server prices at a glance",
"filter_provider": "Provider",
"filter_region": "Region",
"filter_memory": "Memory ≥",
"filter_price": "Price range",
"filter_currency": "Currency",
"search_placeholder": "Search provider, config...",
"all": "All",
"unlimited": "Any",
"btn_reset": "Reset",
"th_provider": "Provider",
"th_country": "Country",
"th_config": "Config",
"th_vcpu": "vCPU",
"th_memory": "Memory",
"th_storage": "Storage",
"th_bandwidth": "Bandwidth",
"th_traffic": "Traffic",
"th_price": "Monthly",
"th_action": "Action",
"disclaimer": "* Prices are indicative. See provider sites for current rates.",
"footer_note": "Data for reference only. Check provider sites for latest pricing.",
"contact_label": "Contact",
"empty_state": "No matching plans found",
"load_error": "Failed to load data. Please refresh.",
"search_label": "Search",
"price_under50": "< 50",
"price_50_100": "50-100",
"price_100_300": "100-300",
"price_300_500": "300-500",
"price_over500": "> 500",
"cny": "CNY (¥)",
"usd": "USD ($)",
},
}
@app.route("/") @app.route("/")
def index(): def index():
lang = request.args.get("lang") or session.get("lang", "zh")
if lang not in ("zh", "en"):
lang = "zh"
session["lang"] = lang
t = I18N[lang]
plans = VPSPlan.query.order_by(VPSPlan.provider, VPSPlan.price_cny).all() plans = VPSPlan.query.order_by(VPSPlan.provider, VPSPlan.price_cny).all()
return render_template( return render_template(
"index.html", "index.html",
site_url=SITE_URL, site_url=SITE_URL,
site_name=SITE_NAME, site_name=SITE_NAME,
plans_json_ld=[p.to_dict() for p in plans], plans_json_ld=[p.to_dict() for p in plans],
lang=lang,
t=t,
) )

View File

@@ -25,7 +25,7 @@ class Config:
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or _mysql_uri() SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or _mysql_uri()
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SITE_URL = os.environ.get("SITE_URL") or "https://vps.ddrwode.cn" SITE_URL = os.environ.get("SITE_URL") or "https://vps.ddrwode.cn"
SITE_NAME = "服务器价格对比" SITE_NAME = "价眼"
# 兼容直接 from config import XXX # 兼容直接 from config import XXX

View File

@@ -112,6 +112,31 @@ body {
background: var(--accent-glow); background: var(--accent-glow);
} }
.lang-switch {
display: inline-flex;
align-items: center;
gap: 0.25rem;
margin-right: 0.5rem;
font-size: 0.9rem;
}
.lang-switch a {
color: var(--accent);
text-decoration: none;
padding: 0.2rem 0.4rem;
border-radius: 4px;
}
.lang-switch a:hover {
background: var(--accent-glow);
}
.lang-switch a.active {
font-weight: 600;
color: var(--text);
}
.lang-sep {
color: var(--text-muted);
user-select: none;
}
.nav-link-with-badge { .nav-link-with-badge {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;

View File

@@ -80,7 +80,7 @@
}) })
.catch(function(error) { .catch(function(error) {
console.error('Error fetching data:', error); console.error('Error fetching data:', error);
showError('数据加载失败,请刷新页面重试'); showError((window.I18N_JS && window.I18N_JS.load_error) || '数据加载失败,请刷新页面重试');
}); });
} }
@@ -216,7 +216,7 @@
tbody.innerHTML = ''; tbody.innerHTML = '';
if (sorted.length === 0) { if (sorted.length === 0) {
tbody.innerHTML = '<tr><td colspan="10" style="text-align: center; padding: 2rem; color: var(--text-muted);">未找到匹配的方案</td></tr>'; tbody.innerHTML = '<tr><td colspan="10" style="text-align: center; padding: 2rem; color: var(--text-muted);">' + ((window.I18N_JS && window.I18N_JS.empty_state) || '未找到匹配的方案') + '</td></tr>';
return; return;
} }

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后台管理 - 云服务器价格对比</title> <title>后台管理 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/admin.css"> <link rel="stylesheet" href="/static/css/admin.css">
</head> </head>

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后台登录 - 云服务器价格对比</title> <title>后台登录 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/admin.css"> <link rel="stylesheet" href="/static/css/admin.css">
</head> </head>

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户登录 - 云服务器价格对比</title> <title>用户登录 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/forum.css"> <link rel="stylesheet" href="/static/css/forum.css">
</head> </head>

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户注册 - 云服务器价格对比</title> <title>用户注册 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/forum.css"> <link rel="stylesheet" href="/static/css/forum.css">
</head> </head>

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>论坛 - 云服务器价格对比</title> <title>论坛 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/forum.css"> <link rel="stylesheet" href="/static/css/forum.css">
</head> </head>

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>发布帖子 - 云服务器价格对比</title> <title>发布帖子 - 云价眼</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/forum.css"> <link rel="stylesheet" href="/static/css/forum.css">
</head> </head>

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="{{ 'zh-CN' if lang == 'zh' else 'en' }}">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -10,7 +10,7 @@
<!-- Open Graph / 社交分享 --> <!-- Open Graph / 社交分享 -->
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:url" content="{{ site_url }}/"> <meta property="og:url" content="{{ site_url }}/">
<meta property="og:title" content="{{ site_name }} - VPS 价格对比"> <meta property="og:title" content="{{ site_name }} - 云服务器价格对比">
<meta property="og:description" content="云服务器 VPS 月付价格对比阿里云、腾讯云、DigitalOcean、Vultr 等,支持筛选与官网跳转。"> <meta property="og:description" content="云服务器 VPS 月付价格对比阿里云、腾讯云、DigitalOcean、Vultr 等,支持筛选与官网跳转。">
<meta property="og:locale" content="zh_CN"> <meta property="og:locale" content="zh_CN">
<!-- JSON-LD 结构化数据,便于搜索引擎理解 --> <!-- JSON-LD 结构化数据,便于搜索引擎理解 -->
@@ -28,7 +28,7 @@
{ {
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "Table", "@type": "Table",
"about": "云服务器 VPS 价格对比", "about": "云价眼 - 云服务器 VPS 价格对比",
"name": "VPS 价格对比表", "name": "VPS 价格对比表",
"description": "各云厂商 VPS 方案配置与月付价格" "description": "各云厂商 VPS 方案配置与月付价格"
} }
@@ -38,14 +38,19 @@
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="/static/css/style.css">
</head> </head>
<body> <body data-lang="{{ lang }}">
<header class="header"> <header class="header">
<div class="header-inner"> <div class="header-inner">
<div class="header-brand"> <div class="header-brand">
<h1 class="logo">VPS Price</h1> <h1 class="logo">云价眼</h1>
<p class="tagline">云服务器价格对比</p> <p class="tagline">{{ t.tagline }}</p>
</div> </div>
<nav class="header-nav"> <nav class="header-nav">
<span class="lang-switch">
<a href="{{ url_for('index', lang='zh') }}" class="{{ 'active' if lang == 'zh' else '' }}">中文</a>
<span class="lang-sep">|</span>
<a href="{{ url_for('index', lang='en') }}" class="{{ 'active' if lang == 'en' else '' }}">English</a>
</span>
<a href="{{ url_for('forum_index') }}">论坛</a> <a href="{{ url_for('forum_index') }}">论坛</a>
{% if current_user %} {% if current_user %}
<span class="header-user">你好,{{ current_user.username }}</span> <span class="header-user">你好,{{ current_user.username }}</span>
@@ -71,21 +76,21 @@
<main class="main"> <main class="main">
<section class="filters"> <section class="filters">
<div class="filter-group"> <div class="filter-group">
<label for="filter-provider">厂商</label> <label for="filter-provider">{{ t.filter_provider }}</label>
<select id="filter-provider"> <select id="filter-provider">
<option value="">全部</option> <option value="">{{ t.all }}</option>
</select> </select>
</div> </div>
<div class="filter-group"> <div class="filter-group">
<label for="filter-region">区域</label> <label for="filter-region">{{ t.filter_region }}</label>
<select id="filter-region"> <select id="filter-region">
<option value="">全部</option> <option value="">{{ t.all }}</option>
</select> </select>
</div> </div>
<div class="filter-group"> <div class="filter-group">
<label for="filter-memory">内存 ≥</label> <label for="filter-memory">{{ t.filter_memory }}</label>
<select id="filter-memory"> <select id="filter-memory">
<option value="0">不限</option> <option value="0">{{ t.unlimited }}</option>
<option value="1">1 GB</option> <option value="1">1 GB</option>
<option value="2">2 GB</option> <option value="2">2 GB</option>
<option value="4">4 GB</option> <option value="4">4 GB</option>
@@ -93,28 +98,28 @@
</select> </select>
</div> </div>
<div class="filter-group"> <div class="filter-group">
<label for="filter-price">价格区间</label> <label for="filter-price">{{ t.filter_price }}</label>
<select id="filter-price"> <select id="filter-price">
<option value="0">不限</option> <option value="0">{{ t.unlimited }}</option>
<option value="0-50">< ¥50</option> <option value="0-50">{{ t.price_under50 }}</option>
<option value="50-100">¥50-100</option> <option value="50-100">{{ t.price_50_100 }}</option>
<option value="100-300">¥100-300</option> <option value="100-300">{{ t.price_100_300 }}</option>
<option value="300-500">¥300-500</option> <option value="300-500">{{ t.price_300_500 }}</option>
<option value="500-99999">> ¥500</option> <option value="500-99999">{{ t.price_over500 }}</option>
</select> </select>
</div> </div>
<div class="filter-group"> <div class="filter-group">
<label for="filter-currency">货币</label> <label for="filter-currency">{{ t.filter_currency }}</label>
<select id="filter-currency"> <select id="filter-currency">
<option value="CNY">人民币 (¥)</option> <option value="CNY">{{ t.cny }}</option>
<option value="USD">美元 ($)</option> <option value="USD">{{ t.usd }}</option>
</select> </select>
</div> </div>
<div class="filter-group filter-group-search"> <div class="filter-group filter-group-search">
<label for="search-input">搜索</label> <label for="search-input">{{ t.search_label }}</label>
<input type="text" id="search-input" placeholder="搜索厂商、配置..." /> <input type="text" id="search-input" placeholder="{{ t.search_placeholder }}" />
</div> </div>
<button type="button" class="btn-reset" id="btn-reset">重置筛选</button> <button type="button" class="btn-reset" id="btn-reset">{{ t.btn_reset }}</button>
</section> </section>
<!-- 广告位 2表格上方。可放置矩形或横条广告 --> <!-- 广告位 2表格上方。可放置矩形或横条广告 -->
@@ -127,16 +132,16 @@
<table class="price-table"> <table class="price-table">
<thead> <thead>
<tr> <tr>
<th>厂商</th> <th>{{ t.th_provider }}</th>
<th>国家</th> <th>{{ t.th_country }}</th>
<th>配置</th> <th>{{ t.th_config }}</th>
<th data-sort="vcpu" class="sortable">vCPU <span class="sort-icon"></span></th> <th data-sort="vcpu" class="sortable">vCPU <span class="sort-icon"></span></th>
<th data-sort="memory_gb" class="sortable">内存 <span class="sort-icon"></span></th> <th data-sort="memory_gb" class="sortable">{{ t.th_memory }} <span class="sort-icon"></span></th>
<th data-sort="storage_gb" class="sortable">存储 <span class="sort-icon"></span></th> <th data-sort="storage_gb" class="sortable">{{ t.th_storage }} <span class="sort-icon"></span></th>
<th>带宽</th> <th>{{ t.th_bandwidth }}</th>
<th>流量</th> <th>{{ t.th_traffic }}</th>
<th data-sort="price" class="col-price sortable">月付价格 <span class="sort-icon"></span></th> <th data-sort="price" class="col-price sortable">{{ t.th_price }} <span class="sort-icon"></span></th>
<th class="col-link">操作</th> <th class="col-link">{{ t.th_action }}</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-body"> <tbody id="table-body">
@@ -145,7 +150,7 @@
</table> </table>
</section> </section>
<p class="disclaimer">* 价格仅供参考,以各厂商官网为准。部分为按量/包年折算月价。</p> <p class="disclaimer">{{ t.disclaimer }}</p>
</main> </main>
<footer class="footer"> <footer class="footer">
@@ -153,9 +158,9 @@
<div class="ad-slot ad-slot-footer" id="ad-slot-3"> <div class="ad-slot ad-slot-footer" id="ad-slot-3">
<!-- 在此处粘贴 Google AdSense 代码 --> <!-- 在此处粘贴 Google AdSense 代码 -->
</div> </div>
<p>数据仅供参考 · 请以云厂商官网实时报价为准</p> <p>{{ t.footer_note }}</p>
<div class="contact-section"> <div class="contact-section">
<p class="contact-label">联系我们</p> <p class="contact-label">{{ t.contact_label }}</p>
<a href="https://t.me/dockerse" target="_blank" rel="noopener" class="contact-link"> <a href="https://t.me/dockerse" target="_blank" rel="noopener" class="contact-link">
<svg class="contact-icon" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"> <svg class="contact-icon" width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm5.562 8.161c-.18 1.897-.962 6.502-1.359 8.627-.168.9-.5 1.201-.82 1.23-.697.064-1.226-.461-1.901-.903-1.056-.692-1.653-1.123-2.678-1.799-1.185-.781-.417-1.21.258-1.911.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.139-5.062 3.345-.479.329-.913.489-1.302.481-.428-.009-1.252-.242-1.865-.442-.752-.244-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.831-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635.099-.002.321.023.465.141.121.099.155.232.171.326.016.094.036.308.02.475z"/> <path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm5.562 8.161c-.18 1.897-.962 6.502-1.359 8.627-.168.9-.5 1.201-.82 1.23-.697.064-1.226-.461-1.901-.903-1.056-.692-1.653-1.123-2.678-1.799-1.185-.781-.417-1.21.258-1.911.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.139-5.062 3.345-.479.329-.913.489-1.302.481-.428-.009-1.252-.242-1.865-.442-.752-.244-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.831-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635.099-.002.321.023.465.141.121.099.155.232.171.326.016.094.036.308.02.475z"/>
@@ -172,6 +177,13 @@
</svg> </svg>
</a> </a>
<script>
window.LANG = {{ lang|tojson }};
window.I18N_JS = {
empty_state: {{ t.empty_state|tojson }},
load_error: {{ t.load_error|tojson }}
};
</script>
<script src="/static/js/main-simple.js"></script> <script src="/static/js/main-simple.js"></script>
</body> </body>
</html> </html>