合并部分代码

This commit is contained in:
黄心宇 2024-04-28 11:13:35 +08:00
parent 6381ff7dcf
commit 7bd45d9088
10 changed files with 66 additions and 30 deletions

View File

@ -17,6 +17,13 @@ const paths = require("./paths");
const publicPath = "/";
const env = getClientEnvironment("/","development");
const process = require('process');
process.on('uncaughtException', function (err) {
// 开发时websocket proxy 会因服务重新部署而报错中断本地 server这里拦截一下
console.log('拦截未处理异常:', err);
});
module.exports = {
optimization: {
splitChunks: {
@ -273,12 +280,11 @@ module.exports = {
reactPath:'react.production.min.js',
}),
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
// Add module names to factory functions so they appear in browser profiler.
new webpack.NamedModulesPlugin(),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env.stringified),
new webpack.DefinePlugin({ ...env.stringified, __SERVER__: 'false',__CLIENT__: 'true' }),
// This is necessary to emit hot updates (currently CSS only):
new webpack.HotModuleReplacementPlugin(),
// Watcher doesn't work well if you mistype casing in a path so we use

View File

@ -294,6 +294,7 @@ module.exports = {
minifyURLs: true,
},
}),
new webpack.DefinePlugin({ ...env.stringified, __SERVER__: 'false',__CLIENT__: 'true' }),
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.

View File

@ -2,10 +2,14 @@ import React from "react";
import md5 from 'md5';
import {Input} from "antd";
const { Search } = Input;
import { url as ssrOrigin, host as ssrHost } from '../ssrUrl'
const $ = window.$;
const isDev = window.location.port == 3007;
const isdev2= window.location.hostname ==='www.educoder.net'
if (!__SERVER__) {
const $ = window.$;
}
const isDev = __SERVER__ ? false : window.location.port == 3007;
const isdev2= __SERVER__ ? false : window.location.hostname ==='www.educoder.net'
export const TEST_HOST = "https://testforgeplus.trustie.net"
export function getImageUrl(path) {
// https://www.educoder.net
@ -40,7 +44,7 @@ export function getImageUrlAbsolute(path) {
// const local = 'http://localhost:3000'
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
const local = 'https://testforgeplus.trustie.net';
const prod = window.location.origin;
const prod = __SERVER__ ? local : window.location.origin;
if (isDev) {
return `${local}${path}`
}else{
@ -198,7 +202,7 @@ function railsgettimess(proxy) {
}
}})
window.setTimeout(function () {
setTimeout(function () {
checkSubmitFlgs=false;
}, 2500);
}
@ -295,13 +299,13 @@ export function turnbar(str){
let s = str;
if(s && s.length>0){
if(s.indexOf("%")>-1){
s = s.replaceAll('%','_25');
s = s.split('%').join('_25');
}
if(s.indexOf("#")>-1){
s = s.replaceAll('#','%23');
s = s.split('#').join('%23');
}
if(s.indexOf("/")>-1){
s = s.replaceAll('/','%2F');
s = s.split('/').join('%2F');
}
}
return s;
@ -310,13 +314,13 @@ export function returnbar(str){
let s = str;
if(s && s.length>0){
if(str.indexOf("_25")>-1){
s = s.replaceAll('_25','%');
s = s.split('_25').join('%');
}
if(s.indexOf("%23")>-1){
s = s.replaceAll('%23','#');
s = s.split('%23').join('#');
}
if(s.indexOf("%2F")>-1){
s = s.replaceAll('%2F','/');
s = s.split('%2F').join('/');
}
}
return s;
@ -324,6 +328,9 @@ export function returnbar(str){
// 手动添加/修改mate标签
export function addMeta(name, content){
if (__SERVER__) {
document = domObj.window.document
}
if(document.querySelector(`meta[name='${name}']`)){
document.querySelector(`meta[name='${name}']`).content=content;
}else{
@ -344,16 +351,19 @@ export function addMeta(name, content){
* projectId 项目唯一标识
*/
export function setSeoMeta(keyWords, title, description, url, owner, projectId) {
if (__SERVER__) {
document = domObj.window.document
}
// 服务端没有location
const host = window.location.host
const origin = window.location.origin
document.querySelector(`meta[property='og:title']`).content = title + ' | GitLink';
document.querySelector(`title`).textContent = title + ' | GitLink';
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;
document.querySelector(`title`).textContent = title;
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[property='og:description']`).content = description;
document.querySelector(`meta[property='og:image:alt']`).content = description;
document.querySelector('meta[name="Keywords"]').content= `${ keyWords }${ keyWords ? '' : 'GitLink, git, 开源, 代码托管, 项目管理, 版本控制, 代码分享, 项目协作, 协同开发平台' }` ;
document.querySelector(`meta[name='description']`).content = description;
document.querySelector(`meta[name='go-import']`).content = host + url + ' git ' + origin + url;
document.querySelector(`meta[name='octolytics-dimension-user_login']`).content = owner;
if (projectId) {

View File

@ -29,7 +29,7 @@ function Badge(props) {
} else {
setProjectDetail(result.data);
// seo
let keyWords = `${owner},${projectsId},${result.data.author.name},`;
let keyWords = `${owner},${projectsId},${result.data.author.name}`;
let title = `${owner}/${projectsId}${result.data.description ? '' + result.data.description : ''}`;
setSeoMeta(keyWords, title, result.data.description, `/${owner}/${projectsId}`, owner, projectsId);
}

View File

@ -1,5 +1,5 @@
import React , { useEffect } from 'react';
import Slider from 'react-slick';
// import Slider from 'react-slick';
import { httpUrl } from '../fetch';
import axios from 'axios';
import { useState } from 'react';

View File

@ -116,7 +116,7 @@ function HeaderPageCCF(props) {
{
//
data && data.cmsShow === 1 && newsList && newsList.length >= 0 &&
<div className="zone_news">
<div className="zone_news zone_news_ccf">
<p className="in_title mb50">{data.homepageCmsTitle}</p>
<div className="boxmain mb100" style={{ display: "flex" }}>
<div className="zone_new_first">

View File

@ -25,9 +25,9 @@ function NewsDetail(props){
let initialContent = undefined;
//
if(detail){
const { name, cmsDir, summary} = detail;
const { name, cmsDir} = detail;
document.title = `${ name }/${ cmsDir.name }`;
addMeta('Keywords', `${ name },${ cmsDir.name },${ summary }`);
setMeta()
setTimeout(() => {
configShareForCustom(detail.name, detail.summary, detail.headImg)
}, 1000);
@ -46,8 +46,7 @@ function NewsDetail(props){
document.querySelector('meta[name="viewport"]').setAttribute('content', initialContent);
}
if (zonedetail) {
document.title= zonedetail.mainTitle;
setSeoMeta(`${zonedetail.name},`, zonedetail.name, zonedetail.subTitle, `/zone/${deptId}`)
setMeta(true)
}
}
},[zonedetail,detail])
@ -59,6 +58,19 @@ function NewsDetail(props){
}
},[id])
function setMeta(unmount = false) {
if (unmount) {
document.title= zonedetail.name;
setSeoMeta(`${zonedetail.name}`, zonedetail.name, zonedetail.subTitle, `/zone/${deptId}`)
} else {
const { name, cmsDir, summary, id} = detail;
const title = `${ name }/${ cmsDir.name }`;
const keywords = `${ name },${ cmsDir.name },${ zonedetail.name }`;
document.title = title;
setSeoMeta(keywords, title, summary, `/zone/${deptId}/newdetail/${ id }`)
}
}
function getDetails(){
setIsSpin(true)
getNewsDetail(id).then(result=>{

View File

@ -1,6 +1,6 @@
@import './theme.scss';
.zone_news {
.zone_news_ccf {
margin-top: -10px !important;
.zone_new_first {

View File

@ -161,7 +161,7 @@ class Infos extends Component {
const { pathname } = this.props.location;
this.renderPath(pathname,result.data);
document.title = result.data.username ? result.data.username : username;
let keyWords=`${result.data.username},${username},`;
let keyWords=`${result.data.username},${username}`;
let title= result.data.username+'('+ username +')';
setSeoMeta(keyWords,title,title,`/${username}`,username);
})

7
src/ssrUrl.js Normal file
View File

@ -0,0 +1,7 @@
export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'https://testforgeplus.trustie.net'
export const zoneUrl = process.env.NODE_ENV === 'production' ? 'https://gateway.gitlink.org.cn' : 'https://testgetway.trustie.net'
export const host = process.env.NODE_ENV === 'production' ? 'www.gitlink.org.cn' : 'testforgeplus.trustie.net'
// export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : ''
// export const zoneUrl = process.env.NODE_ENV === 'production' ? 'https://gateway.gitlink.org.cn' : ''
// export const host = process.env.NODE_ENV === 'production' ? 'www.gitlink.org.cn' : ''