feat: 官网补充 Open Graph 分享元信息,生产域名 ideship.com
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
da8376e31d
commit
04929ee2da
@ -4,6 +4,13 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>9610跨境电商出口方案选择指南 | IDE国际物流</title>
|
||||
<meta name="description" content="IDE 9610跨境电商出口指南:报关、退税与专线物流怎么选,一看就懂。">
|
||||
<meta property="og:title" content="9610跨境电商出口方案选择指南 | IDE国际物流">
|
||||
<meta property="og:description" content="IDE 9610跨境电商出口指南:报关、退税与专线物流怎么选,一看就懂。">
|
||||
<meta property="og:image" content="https://ideship.com/site/assets/img/og-cover.png">
|
||||
<meta property="og:url" content="https://ideship.com/9610.html">
|
||||
<meta property="og:type" content="website">
|
||||
<script src="assets/js/og-meta.js"></script>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
|
||||
BIN
IDE官网/assets/img/og-cover.png
Normal file
BIN
IDE官网/assets/img/og-cover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@ -712,6 +712,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (window.IDEAdvisor) {
|
||||
window.IDEAdvisor.setLanguage(isChinese ? 'zh' : 'en');
|
||||
}
|
||||
|
||||
if (window.IDEOpenGraph && typeof window.IDEOpenGraph.refresh === 'function') {
|
||||
window.IDEOpenGraph.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSavedLanguage() {
|
||||
|
||||
78
IDE官网/assets/js/og-meta.js
Normal file
78
IDE官网/assets/js/og-meta.js
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Open Graph:复用 <title> / meta[name=description],补齐绝对 og:url / og:image。
|
||||
* 爬虫可读 head 内静态 meta;本脚本在浏览器中按当前域名校正。
|
||||
*/
|
||||
(function () {
|
||||
var PROD_ORIGIN = 'https://ideship.com';
|
||||
var OG_IMAGE_PATH = '/site/assets/img/og-cover.png';
|
||||
var OG_IMAGE_REL = 'assets/img/og-cover.png';
|
||||
|
||||
function truncate(text, max) {
|
||||
var value = String(text || '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
if (value.length <= max) return value;
|
||||
return value.slice(0, max);
|
||||
}
|
||||
|
||||
function ensureMeta(property, content) {
|
||||
if (!content) return;
|
||||
var node = document.querySelector('meta[property="' + property + '"]');
|
||||
if (!node) {
|
||||
node = document.createElement('meta');
|
||||
node.setAttribute('property', property);
|
||||
document.head.appendChild(node);
|
||||
}
|
||||
node.setAttribute('content', content);
|
||||
}
|
||||
|
||||
function resolveOrigin() {
|
||||
if (location.protocol === 'http:' || location.protocol === 'https:') {
|
||||
return location.origin;
|
||||
}
|
||||
return PROD_ORIGIN;
|
||||
}
|
||||
|
||||
function resolvePageUrl(origin) {
|
||||
if (location.protocol === 'file:') {
|
||||
return /9610\.html$/i.test(location.pathname || '')
|
||||
? PROD_ORIGIN + '/9610.html'
|
||||
: PROD_ORIGIN + '/';
|
||||
}
|
||||
var path = location.pathname || '/';
|
||||
if (/\/index\.html$/i.test(path)) {
|
||||
path = path.replace(/\/index\.html$/i, '/') || '/';
|
||||
}
|
||||
if (path === '/site' || path === '/site/' || path === '/site/index.html') {
|
||||
path = '/';
|
||||
}
|
||||
return origin + path + (location.search || '');
|
||||
}
|
||||
|
||||
function resolveImageUrl(origin) {
|
||||
if (origin === PROD_ORIGIN || /(^|\.)ideship\.com$/i.test(location.hostname || '')) {
|
||||
return origin + OG_IMAGE_PATH;
|
||||
}
|
||||
try {
|
||||
return new URL(OG_IMAGE_REL, location.href).href;
|
||||
} catch (e) {
|
||||
return origin + '/assets/img/og-cover.png';
|
||||
}
|
||||
}
|
||||
|
||||
function applyOpenGraph() {
|
||||
var title = truncate(document.title, 30);
|
||||
var descNode = document.querySelector('meta[name="description"]');
|
||||
var description = truncate(descNode && descNode.getAttribute('content'), 60);
|
||||
var origin = resolveOrigin();
|
||||
|
||||
ensureMeta('og:title', title);
|
||||
if (description) ensureMeta('og:description', description);
|
||||
ensureMeta('og:image', resolveImageUrl(origin));
|
||||
ensureMeta('og:url', resolvePageUrl(origin));
|
||||
ensureMeta('og:type', 'website');
|
||||
}
|
||||
|
||||
applyOpenGraph();
|
||||
window.IDEOpenGraph = { refresh: applyOpenGraph };
|
||||
})();
|
||||
@ -9,6 +9,14 @@
|
||||
<meta content="IDE 面向中小卖家的跨境物流。全球数字化一站式跨境物流服务商。注册登记后即可询价,一口价不砍,专属顾问跟到签收。" name="description">
|
||||
<meta content="IDE, 跨境物流, 中小卖家, 9610, 疑难单, 出口退税, 欧美专线, 东南亚专线" name="keywords">
|
||||
|
||||
<!-- Open Graph(标题/描述复用上方 title、description;图片为 478×478) -->
|
||||
<meta property="og:title" content="IDE - 跨境物流,全球即递">
|
||||
<meta property="og:description" content="IDE 面向中小卖家的跨境物流。全球数字化一站式服务,一口价不砍。">
|
||||
<meta property="og:image" content="https://ideship.com/site/assets/img/og-cover.png">
|
||||
<meta property="og:url" content="https://ideship.com/">
|
||||
<meta property="og:type" content="website">
|
||||
<script src="assets/js/og-meta.js"></script>
|
||||
|
||||
<!-- Favicons(logo1 已入库;favicon.png 由 postbuild 同步) -->
|
||||
<link href="assets/img/logo1.png" rel="icon" type="image/png">
|
||||
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user