From 0580fcb2c0ecccd6b833a0917dda5c524331c5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BF=83=E5=AE=87?= Date: Thu, 21 Sep 2023 14:38:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9title=E4=B8=8Ehead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 8 ++++---- src/common/UrlTool.js | 12 ++++++++++++ src/common/educoder.js | 2 +- src/forums/ForumsDetail.jsx | 6 +++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/public/index.html b/public/index.html index 2082ca5d2..ee24f5978 100755 --- a/public/index.html +++ b/public/index.html @@ -3,10 +3,10 @@ - - - - + + + + diff --git a/src/common/UrlTool.js b/src/common/UrlTool.js index 9704e713d..0689f4e81 100644 --- a/src/common/UrlTool.js +++ b/src/common/UrlTool.js @@ -219,3 +219,15 @@ export function publicSearchs(Placeholder,onSearch,onInputs,onChanges,loadings) allowClear={true} >) } + +// 手动添加/修改mate标签 +export function addMeta(name, content){ + if(document.querySelector(`meta[name='${name}']`)){ + document.querySelector(`meta[name='${name}']`).content=content; + }else{ + const meta = document.createElement('meta'); + meta.content = content; + meta.name = name; + document.getElementsByTagName('head')[0].appendChild(meta); + } +}; diff --git a/src/common/educoder.js b/src/common/educoder.js index 83d2a40c8..67e427004 100644 --- a/src/common/educoder.js +++ b/src/common/educoder.js @@ -6,7 +6,7 @@ export { getUploadLogoActionUrl as getUploadLogoActionUrl, getImageUrl as getImageUrl, getmyUrl as getmyUrl, getRandomNumber as getRandomNumber, getUrl as getUrl, publicSearchs as publicSearchs, getRandomcode as getRandomcode, getUrlmys as getUrlmys, getUrl2 as getUrl2, setImagesUrl as setImagesUrl , getUploadActionUrl as getUploadActionUrl, getUploadActionUrltwo as getUploadActionUrltwo, getUploadActionUrlthree as getUploadActionUrlthree, getUploadActionUrlOfAuth as getUploadActionUrlOfAuth - , getTaskUrlById as getTaskUrlById, TEST_HOST, htmlEncode as htmlEncode, getupload_git_file as getupload_git_file, getcdnImageUrl as getcdnImageUrl + , getTaskUrlById as getTaskUrlById, TEST_HOST, htmlEncode as htmlEncode, getupload_git_file as getupload_git_file, getcdnImageUrl as getcdnImageUrl, addMeta as addMeta } from './UrlTool'; export { setmiyah as setmiyah } from './Component'; diff --git a/src/forums/ForumsDetail.jsx b/src/forums/ForumsDetail.jsx index 6c955c26d..07c693e8a 100644 --- a/src/forums/ForumsDetail.jsx +++ b/src/forums/ForumsDetail.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import axios from "axios"; -import { getImageUrl } from "educoder"; +import { getImageUrl, addMeta } from "educoder"; import { Breadcrumb, Spin, Empty } from "antd"; import { Link } from "react-router-dom"; import { @@ -47,7 +47,9 @@ function memo_show(props) { }, [memo_id]); function componentWillUnmount() { + // 离开页面恢复原来title与head document.title = '论坛交流' + addMeta('Keywords', "trustie,trustieforge,forge,确实让创建更美好,协同开发平台") } async function init() { @@ -74,7 +76,9 @@ function memo_show(props) { setRecentmemos(result.data.recent_memos); setIsBanned(result.data.is_banned); getMemoUser(result.data.author_info); + // 帖子详情页动态修改title与head document.title = `${result.data.memo.subject}/${result.data.memo.forum_tag && result.data.memo.forum_tag.title}` + addMeta('Keywords', `${result.data.memo.subject}/${result.data.memo.forum_tag && result.data.memo.forum_tag.title}`) } setSpinType(false); })