Bläddra i källkod

seo地址处理

ccf 4 år sedan
förälder
incheckning
7982410080

+ 8 - 8
components/consult/dealSeoList.js

@@ -18,7 +18,7 @@ export default class DealSeoData {
         this.cateNameOne = ''
         this.cateNameTwo = ''
     }
-  
+
     async dealData() {
         const self = this
         let {
@@ -33,7 +33,8 @@ export default class DealSeoData {
         // 目前仅将二级 id 拼接到 url 上
         let match = params.pathMatch || ''
         let matchList = match.split('/').map(item => item.toLocaleLowerCase())
-        let lastMatch = matchList.pop()
+        matchList.pop();
+        let lastMatch = matchList.pop();
         // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
 
         // 重定向
@@ -51,19 +52,19 @@ export default class DealSeoData {
             }
         })
 
-        if (Number(lastMatch) > 0) {
+        if (lastMatch) {
             // 遍历分类数组
             let selectedCateIdOne = ''
             consultCate.forEach(cateOne => {
                 cateOne.children.forEach(cateTwo => {
-                    if (Number(cateTwo.value) === Number(lastMatch)) {
+                    if (cateTwo.value ===lastMatch) {
                         selectedCateIdOne = cateOne.value
                         self.cateNameOne = cateOne.label
                         self.cateNameTwo = cateTwo.label
                     }
                 })
             })
-            if (Number(selectedCateIdOne) > 0) {
+            if (selectedCateIdOne) {
                 this.pagination.selectedCateIdOne = selectedCateIdOne
                 this.pagination.selectedCateIdTwo = lastMatch
             }
@@ -92,7 +93,7 @@ export default class DealSeoData {
             consultCate = consultCate.map(item => {
                 let children = item.child_list.map(child => {
                     return {
-                        value: child.category_id,
+                        value: child.f_name,
                         label: child.name
                     }
                 })
@@ -178,7 +179,7 @@ export default class DealSeoData {
 
         return consultList
     }
-  
+
     dealThisMeta() {
         let head = {
             title: "",
@@ -215,4 +216,3 @@ export default class DealSeoData {
         return head
     }
 }
-  

+ 9 - 8
components/skill/dealSeoList.js

@@ -17,7 +17,7 @@ export default class DealSeoData {
         this.cateNameOne = ''
         this.cateNameTwo = ''
     }
-  
+
     async dealData() {
         const self = this
         let {
@@ -32,6 +32,7 @@ export default class DealSeoData {
         // 目前仅将二级 id 拼接到 url 上
         let match = params.pathMatch || ''
         let matchList = match.split('/').map(item => item.toLocaleLowerCase())
+        matchList.pop()
         let lastMatch = matchList.pop()
         // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
 
@@ -50,19 +51,19 @@ export default class DealSeoData {
             }
         })
 
-        if (Number(lastMatch) > 0) {
+        if (lastMatch) {
             // 遍历分类数组
             let selectedCateIdOne = ''
             skillCate.forEach(cateOne => {
                 cateOne.children.forEach(cateTwo => {
-                    if (Number(cateTwo.value) === Number(lastMatch)) {
+                    if (cateTwo.value === lastMatch) {
                         selectedCateIdOne = cateOne.value
                         self.cateNameOne = cateOne.label
                         self.cateNameTwo = cateTwo.label
                     }
                 })
             })
-            if (Number(selectedCateIdOne) > 0) {
+            if (selectedCateIdOne) {
                 this.pagination.selectedCateIdOne = selectedCateIdOne
                 this.pagination.selectedCateIdTwo = lastMatch
             }
@@ -91,7 +92,7 @@ export default class DealSeoData {
             skillCate = skillCate.map(item => {
                 let children = item.child_list.map(child => {
                     return {
-                        value: child.category_id,
+                        value: child.f_name,
                         label: child.name
                     }
                 })
@@ -141,7 +142,7 @@ export default class DealSeoData {
 
         return skillList
     }
-  
+
     dealThisMeta() {
         let head = {
             title: "",
@@ -154,7 +155,7 @@ export default class DealSeoData {
 
         if (this.req) {
             const { headers: { host }, url } = this.req
-      
+
             //拼接canonical
             if (host.indexOf('local') !== -1) {
               head.canonical = 'http://' + host + url
@@ -174,7 +175,7 @@ export default class DealSeoData {
             head.keyword = "IT技术学习、IT培训、编程开发学习、自学编程";
             head.description = "程序员客栈技术培训是一个提供了编程的基础技术教程, 介绍了HTML、CSS、Javascript、Python,Java,Ruby,C,PHP , MySQL等各种编程语言的培训课程。 同时也提供了大量的高端程序员,通过一对一教学,帮助您更好的学习编程。";
         }
-        
+
         return head
     }
 }

+ 10 - 8
components/work_down/dealSeoList.js

@@ -18,7 +18,7 @@ export default class DealSeoData {
         this.cateNameOne = ''
         this.cateNameTwo = ''
     }
-  
+
     async dealData() {
         const self = this
         let {
@@ -33,6 +33,7 @@ export default class DealSeoData {
         // 目前仅将二级 id 拼接到 url 上
         let match = params.pathMatch || ''
         let matchList = match.split('/').map(item => item.toLocaleLowerCase())
+        matchList.pop()
         let lastMatch = matchList.pop()
         // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
 
@@ -51,19 +52,20 @@ export default class DealSeoData {
             }
         })
 
-        if (Number(lastMatch) > 0) {
+        if (lastMatch) {
             // 遍历分类数组
             let selectedCateIdOne = ''
             categoryList.forEach(cateOne => {
                 cateOne.child.forEach(cateTwo => {
-                    if (Number(cateTwo.category_id) === Number(lastMatch)) {
-                        selectedCateIdOne = cateOne.category_id
+                    if (cateTwo.f_name===lastMatch) {
+                        selectedCateIdOne = lastMatch
                         self.cateNameOne = cateOne.name
                         self.cateNameTwo = cateTwo.name
                     }
                 })
             })
-            if (Number(selectedCateIdOne) > 0) {
+
+            if (selectedCateIdOne) {
                 this.pagination.cate_id_two.push(lastMatch)
             }
         }
@@ -118,7 +120,7 @@ export default class DealSeoData {
 
         return worksList
     }
-  
+
     dealThisMeta() {
         let head = {
             title: "",
@@ -131,7 +133,7 @@ export default class DealSeoData {
 
         if (this.req) {
             const { headers: { host }, url } = this.req
-      
+
             //拼接canonical
             if (host.indexOf('local') !== -1) {
               head.canonical = 'http://' + host + url
@@ -151,7 +153,7 @@ export default class DealSeoData {
             head.keyword = "IT开发资源下载、开发源码下载";
             head.description = "程序员客栈资源商城是一个提供学习资源、源码、在线学习视频、IT电子书、各类免费软件等下载服务的IT资源大本营,致力于为软件开发者提供知识传播、资源共享、共同学习的优质学习资源平台.";
         }
-        
+
         return head
     }
 }

+ 2 - 2
pages/frontend/consult/list.vue

@@ -20,7 +20,7 @@
                             @click="handleClickExpandCategory">{{ categoryExpanded ? '收起' : '更多' }}</div> -->
                         <!-- 全部 -->
                         <a
-                            href="/consult"
+                            href="/consult/"
                             class="category-one-item"
                             :class="pagination.selectedCateIdOne == '' ? 'active' : ''">全部</a>
                         <!-- 一级分类 -->
@@ -41,7 +41,7 @@
                             <a
                                 class="category-two-item"
                                 :class="pagination.selectedCateIdTwo == categoryTwo.value ? 'active' : ''"
-                                :href="`/consult/${categoryTwo.value}`"
+                                :href="`/consult/${categoryTwo.value}/`"
                                 v-for="categoryTwo in categoryOne.children"
                                 :key="`cate-two-${categoryTwo.value}`">{{ categoryTwo.label }}</a>
                         </div>

+ 1 - 1
pages/frontend/skill/list.vue

@@ -41,7 +41,7 @@
                             <a
                                 class="category-two-item"
                                 :class="pagination.selectedCateIdTwo == categoryTwo.value ? 'active' : ''"
-                                :href="`/learn/${categoryTwo.value}`"
+                                :href="`/learn/${categoryTwo.value}/`"
                                 v-for="categoryTwo in categoryOne.children"
                                 :key="`cate-two-${categoryTwo.value}`">{{ categoryTwo.label }}</a>
                         </div>

+ 5 - 5
pages/work_down/index.vue

@@ -35,10 +35,10 @@
                         v-show="currentCategoryIndex === 0">
                         <a
                             class="works-category-two-item"
-                            :class="pagination.cate_id_two.indexOf(category.category_id) > -1 ? 'active' : ''"
+                            :class="pagination.cate_id_two.indexOf(category.f_name) > -1 ? 'active' : ''"
                             v-for="category in categoryAll"
-                            :key="`category-all-${category.category_id}`"
-                            :href="`/works/${category.category_id}`">
+                            :key="`category-all-${category.category_id}/`"
+                            :href="`/works/${category.f_name}`">
                             {{ category.name }}
                         </a>
                     </div>
@@ -51,10 +51,10 @@
                         v-show="currentCategoryIndex === index + 1">
                         <a
                             class="works-category-two-item"
-                            :class="pagination.cate_id_two.indexOf(categoryChild.category_id) > -1 ? 'active' : ''"
+                            :class="pagination.cate_id_two.indexOf(categoryChild.f_name) > -1 ? 'active' : ''"
                             v-for="categoryChild in category.child"
                             :key="`category-two-${categoryChild.category_id}`"
-                            :href="`/works/${categoryChild.category_id}`">
+                            :href="`/works/${categoryChild.f_name}/`">
                             {{ categoryChild.name }}
                         </a>
                     </div>