Skip to content

Commit cacb6e4

Browse files
committed
feat(route/joneslanglasalle): add hk support
1 parent 0ef804c commit cacb6e4

File tree

1 file changed

+66
-34
lines changed

1 file changed

+66
-34
lines changed

lib/routes/joneslanglasalle/index.ts

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,47 @@ import { parseDate } from '@/utils/parse-date';
77

88
const searchApiUrl = 'https://www.jll.com/api/search/template';
99
const subscriptionKey = '8f6a4de5b0144673acaa89b03aac035e';
10-
const rootUrl = 'https://www.joneslanglasalle.com.cn';
1110

12-
// Reason: map old route language params to the API language code
13-
const langMap: Record<string, string> = {
14-
zh: 'zh-cn',
15-
en: 'en-GB',
11+
interface LocaleConfig {
12+
apiLang: string;
13+
countries: string[];
14+
insightsUrl: string;
15+
title: string;
16+
}
17+
18+
// Reason: each locale maps to a different country filter, API language code, and site URL
19+
const localeMap: Record<string, LocaleConfig> = {
20+
zh: {
21+
apiLang: 'zh-CN',
22+
countries: ['China Mainland'],
23+
insightsUrl: 'https://www.joneslanglasalle.com.cn/zh-cn/insights',
24+
title: '洞察 - 仲量联行JLL',
25+
},
26+
en: {
27+
apiLang: 'en-GB',
28+
countries: ['China Mainland'],
29+
insightsUrl: 'https://www.joneslanglasalle.com.cn/en-cn/insights',
30+
title: 'Insights - JLL China',
31+
},
32+
'zh-hk': {
33+
apiLang: 'zh-HK',
34+
countries: ['Hong Kong'],
35+
insightsUrl: 'https://www.jll.com/zh-hk/insights',
36+
title: '洞察 - 仲量聯行JLL 香港',
37+
},
38+
'en-hk': {
39+
apiLang: 'en-GB',
40+
countries: ['Hong Kong'],
41+
insightsUrl: 'https://www.jll.com/en-hk/insights',
42+
title: 'Insights - JLL Hong Kong',
43+
},
1644
};
1745

1846
export const handler = async (ctx: Context): Promise<Data> => {
1947
const { language: lang = 'zh' } = ctx.req.param();
2048
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '12', 10);
2149

22-
const apiLang = langMap[lang] || lang;
50+
const locale = localeMap[lang] || localeMap.zh;
2351

2452
// Reason: site rebuilt with search API; old HTML scraping no longer works.
2553
// Using the public search API (Elasticsearch-backed) with subscription key from page JS.
@@ -34,8 +62,8 @@ export const handler = async (ctx: Context): Promise<Data> => {
3462
params: {
3563
size: limit,
3664
from: 0,
37-
countries: ['China Mainland'],
38-
language: apiLang,
65+
countries: locale.countries,
66+
language: locale.apiLang,
3967
sort_by_relevance: false,
4068
includeGlobalPeople: false,
4169
boostCountry: '',
@@ -57,14 +85,12 @@ export const handler = async (ctx: Context): Promise<Data> => {
5785
};
5886
});
5987

60-
const targetUrl = lang === 'en' ? `${rootUrl}/en-cn/insights` : `${rootUrl}/zh-cn/insights`;
61-
6288
return {
63-
title: lang === 'en' ? 'Insights - JLL' : '洞察 - 仲量联行JLL',
64-
link: targetUrl,
89+
title: locale.title,
90+
link: locale.insightsUrl,
6591
item: items,
6692
allowEmpty: true,
67-
language: apiLang,
93+
language: locale.apiLang,
6894
};
6995
};
7096

@@ -76,20 +102,19 @@ export const route: Route = {
76102
handler,
77103
example: '/joneslanglasalle/en/trends-and-insights',
78104
parameters: {
79-
language: 'Language, `zh` by default',
105+
language: 'Language, `zh` for China Mainland Chinese, `en` for China Mainland English, `zh-hk` for Hong Kong Chinese, `en-hk` for Hong Kong English, `zh` by default',
80106
category: 'Category, `trends-and-insights` by default',
81107
},
82108
description: `::: tip
83-
If you subscribe to [Trends & Insights](https://www.joneslanglasalle.com.cn/en-cn/insights),where the URL is \`https://www.joneslanglasalle.com.cn/en-cn/insights\`, extract the part \`https://joneslanglasalle.com.cn/\` to the end. Use \`en\` and \`trends-and-insights\` as the parameters to fill in. Therefore, the route will be [\`/joneslanglasalle/en/trends-and-insights\`](https://rsshub.app/joneslanglasalle/en/trends-and-insights).
109+
If you subscribe to [Trends & Insights (China)](https://www.joneslanglasalle.com.cn/en-cn/insights), use \`en\` as the language. For [Hong Kong Insights](https://www.jll.com/zh-hk/insights), use \`zh-hk\` as the language.
84110
:::
85111
86-
| Category | ID |
87-
| --------- | ----------------------------- |
88-
| Latest | trends-and-insights |
89-
| Workplace | trends-and-insights/workplace |
90-
| Investor | trends-and-insights/investor |
91-
| Cities | trends-and-insights/cities |
92-
| Research | trends-and-insights/research |
112+
| Region | Language | Parameter |
113+
| -------------- | -------- | --------- |
114+
| China Mainland | 中文 | zh |
115+
| China Mainland | English | en |
116+
| Hong Kong | 中文 | zh-hk |
117+
| Hong Kong | English | en-hk |
93118
`,
94119
categories: ['new-media'],
95120
features: {
@@ -113,14 +138,22 @@ If you subscribe to [Trends & Insights](https://www.joneslanglasalle.com.cn/en-c
113138
},
114139
{
115140
title: 'Latest',
116-
source: ['joneslanglasalle.com.cn/en/trends-and-insights', 'joneslanglasalle.com.cn/en-cn/insights'],
141+
source: ['joneslanglasalle.com.cn/en-cn/insights'],
117142
target: '/en/trends-and-insights',
118143
},
119144
{
120145
title: '房地产趋势与洞察',
121-
source: ['joneslanglasalle.com.cn/zh/trends-and-insights', 'joneslanglasalle.com.cn/zh-cn/insights'],
146+
source: ['joneslanglasalle.com.cn/zh-cn/insights'],
122147
target: '/zh/trends-and-insights',
123148
},
149+
{
150+
source: ['jll.com/zh-hk/insights'],
151+
target: '/zh-hk/trends-and-insights',
152+
},
153+
{
154+
source: ['jll.com/en-hk/insights'],
155+
target: '/en-hk/trends-and-insights',
156+
},
124157
],
125158
view: ViewType.Articles,
126159

@@ -132,20 +165,19 @@ If you subscribe to [Trends & Insights](https://www.joneslanglasalle.com.cn/en-c
132165
handler,
133166
example: '/joneslanglasalle/zh/trends-and-insights',
134167
parameters: {
135-
language: '语言,默认为 `zh`,可在对应分类页 URL 中找到',
136-
category: '分类,默认为 `trends-and-insights`,可在对应分类页 URL 中找到',
168+
language: '语言,`zh` 为中国大陆中文,`en` 为中国大陆英文,`zh-hk` 为香港中文,`en-hk` 为香港英文,默认为 `zh`',
169+
category: '分类,默认为 `trends-and-insights`',
137170
},
138171
description: `::: tip
139-
若订阅 [房地产趋势与洞察](https://www.joneslanglasalle.com.cn/zh-cn/insights),网址为 \`https://www.joneslanglasalle.com.cn/zh-cn/insights\`,请截取 \`https://joneslanglasalle.com.cn/\` 到末尾的部分 \`zh\` 和 \`trends-and-insights\` 作为 \`language\` 和 \`category\` 参数填入,此时目标路由为 [\`/joneslanglasalle/zh/trends-and-insights\`](https://rsshub.app/joneslanglasalle/zh/trends-and-insights)
172+
若订阅 [中国大陆洞察](https://www.joneslanglasalle.com.cn/zh-cn/insights),语言参数为 \`zh\`。若订阅 [香港洞察](https://www.jll.com/zh-hk/insights),语言参数为 \`zh-hk\`
140173
:::
141174
142-
| 分类名称 | 分类 ID |
143-
| ---------- | ----------------------------- |
144-
| 趋势及洞察 | trends-and-insights |
145-
| 办公空间 | trends-and-insights/workplace |
146-
| 投资者 | trends-and-insights/investor |
147-
| 城市 | trends-and-insights/cities |
148-
| 研究报告 | trends-and-insights/research |
175+
| 地区 | 语言 | 参数 |
176+
| ------ | ------- | ----- |
177+
| 中国大陆 | 中文 | zh |
178+
| 中国大陆 | English | en |
179+
| 香港 | 中文 | zh-hk |
180+
| 香港 | English | en-hk |
149181
`,
150182
},
151183
};

0 commit comments

Comments
 (0)