PageSourceSearch

https://www.jarmoo.com/config/index.js

js jarmoo.com collected 2026-10-08 06:15:32 UTC 4,667 bytes, 133 lines download raw bytes

1import PageConfig, { getPageConfigByPath } from './page.js'
2import { getPathLang } from '../src/function.js'
3
4Object.keys(PageConfig).forEach(key => {
5  PageConfig[key].allowSiteList = []
6  if (PageConfig[key].allowSiteB2B) PageConfig[key].allowSiteList.push('b2b')
7  if (PageConfig[key].allowSiteB2B2C) PageConfig[key].allowSiteList.push('b2b2c')
8  if (PageConfig[key].allowSiteB2C) PageConfig[key].allowSiteList.push('b2c')
9  if (PageConfig[key].allowSiteLP) PageConfig[key].allowSiteList.push('lp')
10  if (PageConfig[key].allowSiteHY) PageConfig[key].allowSiteList.push('hy')
11})
12
13/** 后端的页面类型映射模板类型 */
14const siteTypeToTemplateType = { 1: 'b2b', 11: 'b2b2c', 21: 'b2c', 51: 'b2b', 61: 'b2b2c' }
15
16/** 分页规则 */
17const pagingReg = /_list([0-9]*)$/
18const detailReg = /_([0-9]*)$/
19const systemDirReg = /^(inquire|user|coupon_detail|reduction_detail)\/(.*)$/
20
21/** SystemPage */
22function checkSystemPage(pageType) {
23  return PageConfig[pageType] ? PageConfig[pageType].code < 200 : true
24}
25
26/** Animat */
27function checkAnimat(pageType) {
28  return PageConfig[pageType] && PageConfig[pageType].allowAnimat
29}
30
31/** Detail */
32function checkDetail(pageType) {
33  return PageConfig[pageType] && PageConfig[pageType].isDetail
34}
35
36/** ListContentType */
37function getListContentType(pageType) {
38  return PageConfig[pageType] && PageConfig[pageType].listContentType
39}
40
41/** 返回页面类型,需要根据路径规则和权限判断 */
42function getPageType(pagePath, siteType, pageType = '404') {
43  // 拿到渲染模板类型
44  const templateType = siteTypeToTemplateType[siteType || 1]
45  // 拿到剔除分页和详情id之后的基础页面类型
46  let tempPageType = getBasePageType(pagePath)
47  // 处理首页
48  if (!tempPageType) tempPageType = 'index'
49  // 根据页面路径匹配到页面类型,并且该页面类型与站点类型也匹配
50  if (PageConfig[tempPageType] && PageConfig[tempPageType].allowSiteList.includes(templateType)) pageType = tempPageType
51  // 根据后端返回的页面类型匹配
52  else if (!PageConfig[pageType] || !PageConfig[pageType].allowSiteList.includes(templateType)) pageType = '404'
53  // 返回对应的页面类型,或'404'
54  return `${pageType}`
55}
56/** 返回页面code, 需要根据页面类型 */
57function getPageCode(pageType) {
58  return PageConfig[pageType].code
59}
60/** 获取基本的页面配置,还没处理权限的那种 */
61function getBasePageType(pagePath) {
62  // 去掉语种前缀
63  const langReg = `^/${getPathLang(pagePath)}`
64  pagePath = pagePath.replace(new RegExp(langReg), '')
65  // 去掉/前缀
66  pagePath = pagePath.replace(/^\//, '')
67  // 去掉.html后缀
68  pagePath = pagePath.replace(/\.html$/, '')
69  // 商城政策处理
70  if (pagePath === 'doc/privacy_policy' || pagePath === 'doc/terms_and_conditions') {
71    pagePath = pagePath.replace(/\//, '_')
72  }
73  const pageCfg = getPageConfigByPath(pagePath)
74  // 如果匹配不到,尝试去掉分页后缀再匹配
75  if (!PageConfig[pagePath]) pagePath = pagePath.replace(pagingReg, '')
76  // 还是匹配不到,尝试匹配系统页
77  if (!PageConfig[pagePath]) pagePath = pagePath.replace(systemDirReg, '$1')
78  if (pageCfg && pageCfg.pageType) pagePath = pageCfg.pageType
79  // 返回结果
80  return pagePath
81}
82/** 获取url中的详情页id */
83function getPageId(pagePath) {
84  // 默认为0
85  let pageId = 0
86  // 不在配置中直接返回,在配置中才继续
87  if (!PageConfig[getBasePageType(pagePath)]) return pageId
88  // 拿到分页前的页面路径
89  pagePath = getBasePagePath(pagePath)
90  // 处理/ => _
91  pagePath = pagePath.replace(/\//g, '_')
92  // 拿到id
93  pagePath.replace(detailReg, (match, p1) => pageId = parseInt(p1))
94  // 返回id
95  return pageId
96}
97/** 获取当前页数 */
98function getPageNumber(pagePath) {
99  // 默认为1
100  let pageNumber = 1
101  // 不在配置中直接返回,在配置中才继续
102  if (!PageConfig[getBasePageType(pagePath)]) return pageNumber
103  // 去掉.html后缀
104  pagePath = pagePath.replace(/\.html$/, '')
105  // 去掉_one_page后缀
106  pagePath = pagePath.replace(/_one_page$/, '')
107  // 拿到number
108  pagePath.replace(pagingReg, (match, p1) => pageNumber = parseInt(p1))
109  // 返回number
110  return pageNumber
111}
112/** 获取分页前的页面路径 */
113function getBasePagePath(pagePath) {
114  // 去掉.html后缀
115  pagePath = pagePath.replace(/\.html$/, '')
116  // 去掉_one_page后缀
117  pagePath = pagePath.replace(/_one_page$/, '')
118  return pagePath.replace(pagingReg, '')
119}
120
121export {
122  PageConfig,
123  getPageConfigByPath,
124  checkSystemPage,
125  checkAnimat,
126  checkDetail,
127  getBasePagePath,
128  getPageType,
129  getPageCode,
130  getPageId,
131  getPageNumber,
132  getListContentType,
133}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.