bep40 commited on
Commit
c18dfd1
·
verified ·
1 Parent(s): d91e337

Khôi phục 100% về commit 818a5ed6

Browse files
Files changed (1) hide show
  1. 404.html +160 -0
404.html ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="vi">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>V.AI STUDIO</title>
7
+ <meta property="og:type" content="website">
8
+ <meta property="og:site_name" content="V.AI STUDIO">
9
+ <meta property="og:image" content="https://huggingface.co/spaces/bep40/V.AISTUDIO/resolve/main/logo/logo_main.png">
10
+ <meta name="twitter:card" content="summary_large_image">
11
+ <script>
12
+ /**
13
+ * V.AI STUDIO — 404 Fix v2
14
+ * ========================
15
+ * FIX:
16
+ * - Bot/crawler visits /san-pham/SLUG/index.html → render full OG tags INSTANTLY
17
+ * - Real user → immediate redirect to SPA
18
+ * - Uses lightweight product_seo_min.json (3.8MB) for rich OG data if available
19
+ */
20
+ (function(){
21
+ 'use strict';
22
+ var path = location.pathname;
23
+ var slug = '';
24
+ var m = path.match(/\/san-pham\/([^\/]+)/i);
25
+ if (m) slug = decodeURIComponent(m[1]);
26
+
27
+ var ua = (navigator.userAgent||'').toLowerCase();
28
+ var isBot = /bot|crawl|spider|facebook|twitter|zalo|whatsapp|telegram|slack|discord|pinterest|linkedin|embedly|iframely|google|bing|yandex|duckduck|baidu|semrush|ahrefs|majestic|facebookexternalhit|adsbot/i.test(ua);
29
+
30
+ var SITE = 'https://bep40-v-aistudio.static.hf.space';
31
+ var IMG_DEFAULT = 'https://huggingface.co/spaces/bep40/V.AISTUDIO/resolve/main/logo/logo_main.png';
32
+
33
+ function setMeta(attr, name, content) {
34
+ var sel = attr === 'property' ? 'meta[property="' + name + '"]' : 'meta[name="' + name + '"]';
35
+ var el = document.querySelector(sel);
36
+ if (!el) {
37
+ el = document.createElement('meta');
38
+ el.setAttribute(attr, name);
39
+ document.head.appendChild(el);
40
+ }
41
+ el.setAttribute('content', content || '');
42
+ }
43
+
44
+ function setCanonical(url) {
45
+ var el = document.querySelector('link[rel="canonical"]');
46
+ if (!el) {
47
+ el = document.createElement('link');
48
+ el.setAttribute('rel', 'canonical');
49
+ document.head.appendChild(el);
50
+ }
51
+ el.setAttribute('href', url || SITE + '/');
52
+ }
53
+
54
+ // ── Render full static page for bot ──
55
+ function renderBotPage(name, price, image, desc, sku, brand) {
56
+ name = name || slug || 'Sản phẩm';
57
+ price = price || 0;
58
+ image = image || IMG_DEFAULT;
59
+ desc = desc || name + ' tại V.AI STUDIO';
60
+ sku = sku || '';
61
+ brand = brand || '';
62
+
63
+ var title = name;
64
+ if (brand) title = name + ' | ' + brand + ' | V.AI STUDIO';
65
+ else title = name + ' | V.AI STUDIO';
66
+
67
+ var priceStr = price ? Number(price).toLocaleString('vi-VN') + 'đ' : '';
68
+ var ogDesc = priceStr ? 'Giá: ' + priceStr + ' - ' + desc : desc;
69
+ var ogUrl = SITE + '/san-pham/' + encodeURIComponent(slug) + '/index.html';
70
+
71
+ setMeta('property', 'og:title', title);
72
+ setMeta('property', 'og:description', ogDesc);
73
+ setMeta('property', 'og:image', image);
74
+ setMeta('property', 'og:url', ogUrl);
75
+ if (price > 0) {
76
+ setMeta('property', 'product:price:amount', String(price));
77
+ setMeta('property', 'product:price:currency', 'VND');
78
+ }
79
+ setMeta('name', 'twitter:title', title);
80
+ setMeta('name', 'twitter:description', ogDesc);
81
+ setMeta('name', 'twitter:image', image);
82
+ setCanonical(ogUrl);
83
+ document.title = title;
84
+
85
+ if (isBot) {
86
+ var html = '<!DOCTYPE html><html lang="vi"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
87
+ + '<title>' + title.replace(/"/g,'&quot;') + '</title>'
88
+ + '<meta property="og:title" content="' + title.replace(/"/g,'&quot;') + '">'
89
+ + '<meta property="og:description" content="' + ogDesc.replace(/"/g,'&quot;') + '">'
90
+ + '<meta property="og:image" content="' + image.replace(/"/g,'&quot;') + '">'
91
+ + '<meta property="og:url" content="' + ogUrl.replace(/"/g,'&quot;') + '">'
92
+ + (price > 0 ? '<meta property="product:price:amount" content="' + price + '"><meta property="product:price:currency" content="VND">' : '')
93
+ + '<meta name="twitter:card" content="summary_large_image">'
94
+ + '<meta name="twitter:title" content="' + title.replace(/"/g,'&quot;') + '">'
95
+ + '<meta name="twitter:description" content="' + ogDesc.replace(/"/g,'&quot;') + '">'
96
+ + '<meta name="twitter:image" content="' + image.replace(/"/g,'&quot;') + '">'
97
+ + '<link rel="canonical" href="' + ogUrl.replace(/"/g,'&quot;') + '">'
98
+ + '<style>body{font-family:sans-serif;max-width:700px;margin:40px auto;padding:20px;color:#333}h1{font-size:1.5em;color:#003f62}.price{font-size:1.3em;color:#003f62;font-weight:bold}img{max-width:100%;max-height:400px;margin:16px 0}.btn{display:inline-block;background:#003f62;color:#fff;padding:12px 24px;border-radius:8px;text-decoration:none;font-weight:bold;margin-top:8px}.meta{color:#666;font-size:.85em}</style>'
99
+ + '</head><body>'
100
+ + '<h1>' + name.replace(/"/g,'&quot;') + '</h1>'
101
+ + (sku ? '<p class="meta">Mã: ' + sku.replace(/"/g,'&quot;') + '</p>' : '')
102
+ + (priceStr ? '<p class="price">' + priceStr + '</p>' : '')
103
+ + '<img src="' + image.replace(/"/g,'&quot;') + '" alt="' + name.replace(/"/g,'&quot;') + '">'
104
+ + '<p>' + desc.replace(/"/g,'&quot;') + '</p>'
105
+ + '<a class="btn" href="' + SITE + '/?product=' + encodeURIComponent(slug) + '">Xem chi tiết tại V.AI STUDIO</a>'
106
+ + '</body></html>';
107
+ document.open();
108
+ document.write(html);
109
+ document.close();
110
+ }
111
+ }
112
+
113
+ function tryLoadSEOIndex() {
114
+ var xhr = new XMLHttpRequest();
115
+ xhr.open('GET', '/product_seo_min.json', true);
116
+ xhr.timeout = 5000;
117
+ xhr.onload = function() {
118
+ if (xhr.status >= 200 && xhr.status < 300) {
119
+ try {
120
+ var data = JSON.parse(xhr.responseText);
121
+ var target = slug ? slug.toLowerCase() : '';
122
+ for (var i = 0; i < data.length; i++) {
123
+ var p = data[i];
124
+ if (p[0] && p[0].toLowerCase() === target) {
125
+ renderBotPage(p[1], p[2], p[3], p[4], p[5], p[6]);
126
+ return;
127
+ }
128
+ }
129
+ } catch(e) {}
130
+ }
131
+ };
132
+ xhr.send();
133
+ }
134
+
135
+ // ══════════ MAIN ══════════
136
+ if (!slug) {
137
+ if (!isBot) location.replace('/');
138
+ return;
139
+ }
140
+
141
+ // Step 1: Always render minimal OG instantly from slug
142
+ var guessName = slug.replace(/-/g, ' ').replace(/\b\w/g, function(c){ return c.toUpperCase(); });
143
+ renderBotPage(guessName, 0, IMG_DEFAULT, 'Sản phẩm tại V.AI STUDIO', '', '');
144
+
145
+ // Step 2: Try async loading of SEO index for accurate data
146
+ tryLoadSEOIndex();
147
+
148
+ // Step 3: Real users redirect
149
+ if (!isBot) {
150
+ setTimeout(function() {
151
+ location.replace('/?product=' + encodeURIComponent(slug));
152
+ }, 100);
153
+ }
154
+ })();
155
+ </script>
156
+ </head>
157
+ <body>
158
+ <p style="font-family:sans-serif;text-align:center;padding:40px;color:#666">Vui lòng chờ trong giây lát...</p>
159
+ </body>
160
+ </html>