diff --git a/public/index.html b/public/index.html index 20db22926..971fa3245 100755 --- a/public/index.html +++ b/public/index.html @@ -2,32 +2,24 @@ + GitLink | 新一代开源创新服务平台 - - + + - + - + - - - - - - - - - - - + + diff --git a/src/common/UrlTool.js b/src/common/UrlTool.js index 5a9fa372e..65c354f3f 100644 --- a/src/common/UrlTool.js +++ b/src/common/UrlTool.js @@ -344,25 +344,21 @@ export function addMeta(name, content){ * projectId 项目唯一标识 */ export function setSeoMeta(keyWords, title, description, url, owner, projectId) { - let keyStatement = ' '; - if(owner)keyStatement += owner; - if(projectId)keyStatement += `/${projectId}`; - - document.querySelector(`meta[property='og:title']`).content = title + keyStatement + ' for gitlink' + keyStatement + ' for git'; - document.querySelector(`meta[property='og:url']`).content = window.location.origin + url; - document.querySelector(`meta[property='og:description']`).content = description + ' - ' + title + ' for gitlink' + keyStatement + ' for git'; - document.querySelector(`meta[property='og:image:alt']`).content = description + ' - ' + title + ' for gitlink' + keyStatement + ' for git'; - document.querySelector('meta[name="Keywords"]').content= `${ keyWords } ${ keyWords ? '' : 'gitLink,GitLink,gitlink,trustie,trustieforge,forge,开源,确实开源,代码托管,Git,开源,内源,项目管理,版本控制,开源代码,代码分享,项目协作,开源项目托管,免费代码托管,Git代码托管,Git托管服务,确实让创建更美好,协同开发平台' }` ; - document.querySelector(`meta[name='description']`).content = description + keyStatement + ' for gitlink' + keyStatement + ' for git'; - document.querySelector(`meta[name='go-import']`).content = window.location.host + url + ' git ' + window.location.origin + url; + // 服务端没有location + const host = window.location.host === 'null' || !window.location.host ? ssrHost : window.location.host + const origin = window.location.origin === 'null' || !window.location.origin ? ssrOrigin : window.location.origin + document.querySelector(`meta[property='og:title']`).content = title + ' | GitLink'; + document.querySelector(`title`).textContent = title + ' | GitLink'; + document.querySelector(`meta[property='og:url']`).content = origin + url; + document.querySelector(`meta[property='og:description']`).content = description + ' | GitLink'; + document.querySelector(`meta[property='og:image:alt']`).content = description + ' | GitLink'; + document.querySelector('meta[name="Keywords"]').content= `${ keyWords },${ keyWords ? '' : 'GitLink, git, 开源, 代码托管, 项目管理, 版本控制, 代码分享, 项目协作, 协同开发平台' }` ; + document.querySelector(`meta[name='description']`).content = description + ' | GitLink'; + document.querySelector(`meta[name='go-import']`).content = host + url + ' git ' + origin + url; document.querySelector(`meta[name='octolytics-dimension-user_login']`).content = owner; if (projectId) { document.querySelector(`meta[name='octolytics-dimension-repository_nwo']`).content = owner + '/' + projectId; document.querySelector(`meta[name='octolytics-dimension-repository_network_root_nwo']`).content = owner + '/' + projectId; } - document.querySelector(`meta[name='twitter:title']`).content = title + keyStatement + ' for gitlink' + keyStatement + ' for git'; - document.querySelector(`meta[name='twitter:description']`).content = description + ' - ' + title + keyStatement + ' for gitlink' + keyStatement + ' for git'; - - document.querySelector(`link[rel='canonical']`).href = window.location.origin + url; - + document.querySelector(`link[rel='canonical']`).href = origin + url; } \ No newline at end of file