소스 검색

feat:三级页seo

wangchuanjin 2 년 전
부모
커밋
51e28181c0
1개의 변경된 파일20개의 추가작업 그리고 9개의 파일을 삭제
  1. 20 9
      src/jfw/front/shorturl.go

+ 20 - 9
src/jfw/front/shorturl.go

@@ -55,7 +55,18 @@ var Map_stype = map[string]bool{
 	"advancedProject": true,
 	"advancedProject": true,
 }
 }
 
 
+var seoAgentReg = regexp.MustCompile("Baiduspider|360Spider|bingbot|Googlebot")
+
 func (s *Short) Article(stype, id string) error {
 func (s *Short) Article(stype, id string) error {
+	userId, _ := s.GetSession("userId").(string)
+	if stype == "article" && userId == "" && seoAgentReg.MatchString(s.UserAgent()) {
+		sids := encrypt.CommonDecodeArticle(stype, id)
+		return s.NologinCommon("", "nologin", encrypt.CommonEncodeArticle("nologin", sids[0]), sids[0])
+	}
+	return s.LoginCommon(userId, stype, id)
+}
+
+func (s *Short) LoginCommon(userId, stype, id string) error {
 	client := s.Header("User-Agent")
 	client := s.Header("User-Agent")
 	bm := mobileReg.MatchString(client)
 	bm := mobileReg.MatchString(client)
 	//电脑端 剑鱼快照页面访问
 	//电脑端 剑鱼快照页面访问
@@ -96,12 +107,11 @@ func (s *Short) Article(stype, id string) error {
 		}
 		}
 		aboutUrl += "&from=" + from_userid
 		aboutUrl += "&from=" + from_userid
 	}
 	}
-	userId, _ := s.GetSession("userId").(string)
 	if !Map_stype[stype] {
 	if !Map_stype[stype] {
 		s.Redirect("/not/nottype", 302)
 		s.Redirect("/not/nottype", 302)
 		return nil
 		return nil
 	} else if stype == "content" || stype == "bdcontent" || stype == "advancedProject" {
 	} else if stype == "content" || stype == "bdcontent" || stype == "advancedProject" {
-		if s.Session().Get("userId") == nil {
+		if userId == "" {
 			if s.GetString("state") == "wx" {
 			if s.GetString("state") == "wx" {
 				//微信跳回来的
 				//微信跳回来的
 				if code := s.GetString("code"); code != "" {
 				if code := s.GetString("code"); code != "" {
@@ -119,7 +129,7 @@ func (s *Short) Article(stype, id string) error {
 		if disWord != "" {
 		if disWord != "" {
 			from_userid = disWordNil(disWord, userId)
 			from_userid = disWordNil(disWord, userId)
 		}
 		}
-		if s.Session().Get("userId") == nil { //} && !regclient.MatchString(client) { //没有用户session //搜索引擎让过
+		if userId == "" { //} && !regclient.MatchString(client) { //没有用户session //搜索引擎让过
 			s.Session().Set("referer", s.Request.RequestURI)
 			s.Session().Set("referer", s.Request.RequestURI)
 			if bm { //是否是移动端访问
 			if bm { //是否是移动端访问
 				s.Redirect(aboutUrl, 302)
 				s.Redirect(aboutUrl, 302)
@@ -283,7 +293,7 @@ func (s *Short) Article(stype, id string) error {
 				return s.Redirect(aboutUrl, 302)
 				return s.Redirect(aboutUrl, 302)
 			}
 			}
 			//之前sessionkeep.go中没有放userId,造成关注有问题
 			//之前sessionkeep.go中没有放userId,造成关注有问题
-			if s.GetSession("userId") == nil {
+			if userId == "" {
 				FindUserAndCreateSess(ssOpenid.(string), s.Session(), "wx", false, true)
 				FindUserAndCreateSess(ssOpenid.(string), s.Session(), "wx", false, true)
 			}
 			}
 		}
 		}
@@ -977,13 +987,14 @@ func (s *Short) NologinArticle(stype, id string) error {
 		s.Redirect("/notin/page", 302)
 		s.Redirect("/notin/page", 302)
 		return nil
 		return nil
 	}
 	}
-	sid := sids[0]
-
-	tg := &Tags{}
-
 	if userId != "" { //已登录用户直接跳转至正常三级页
 	if userId != "" { //已登录用户直接跳转至正常三级页
-		return s.Redirect(fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", sid)))
+		return s.LoginCommon(userId, "article", encrypt.CommonEncodeArticle("content", sids[0]))
 	}
 	}
+	return s.NologinCommon(userId, stype, id, sids[0])
+}
+
+func (s *Short) NologinCommon(userId, stype, id, sid string) error {
+	tg := &Tags{}
 	catchKey := fmt.Sprintf("jypcdetail_nologin_%s_%s", stype, sid)
 	catchKey := fmt.Sprintf("jypcdetail_nologin_%s_%s", stype, sid)
 	if res := redis.Get("newother", catchKey); res == nil || res == "" {
 	if res := redis.Get("newother", catchKey); res == nil || res == "" {
 		industry := s.GetString("industry")
 		industry := s.GetString("industry")