Skip to content

Commit

Permalink
feat: 规范化文档中心跳转链接 (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlmac authored Sep 23, 2024
1 parent f27a03f commit 13c36d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dashboard-front/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
var BK_DASHBOARD_URL = '<%= process.env.BK_DASHBOARD_URL %>'
var BK_DASHBOARD_CSRF_COOKIE_NAME = '<%= process.env.BK_DASHBOARD_CSRF_COOKIE_NAME %>'
var BK_LIST_USERS_API_URL = `${BK_COMPONENT_API_URL}/api/c/compapi/v2/usermanage/fs_list_users/` // 人员选择器接口地址,可选填
var BK_DOCS_URL_PREFIX_MARKDOWN = `${BK_DOCS_URL_PREFIX}/markdown/APIGateway`
var BK_DOCS_URL_PREFIX_MARKDOWN = '';
var BK_APP_HOST = '<%= process.env.BK_APP_HOST %>'
</script>
</script>
Expand Down
24 changes: 22 additions & 2 deletions src/dashboard-front/src/constant/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18n, { isChinese } from '@/language/i18n';
import cookie from 'cookie';

const { t } = i18n.global;
// 当前年份
Expand All @@ -8,9 +9,28 @@ const {
BK_LIST_USERS_API_URL,
BK_API_RESOURCE_URL_TMPL,
BK_DASHBOARD_FE_URL,
BK_DOCS_URL_PREFIX_MARKDOWN,
BK_APIGATEWAY_VERSION,
BK_DOCS_URL_PREFIX,
} = window;
let { BK_DOCS_URL_PREFIX_MARKDOWN } = window;

// 根据文档前缀、语言和版本拼接 BK_DOCS_URL_PREFIX_MARKDOWN 的值
// 执行一个立即执行函数获取,避免了声明会暴露到全局的变量
(function () {
const langMap: Record<string, string> = {
'zh-cn': 'ZH',
en: 'EN',
};
// 当前 cookie 中使用的语言 zh-cn | en
const currentLang = cookie.parse(document.cookie).blueking_language || 'zh-cn';
// 获取文档语言 ZH | EN
const lang = langMap[currentLang];
// 获取当前版本的 major 和 minor 版本,如:1.13.1 -> 1.13
const docVersion = BK_APIGATEWAY_VERSION.split('.')
.slice(0, 2)
.join('.');
BK_DOCS_URL_PREFIX_MARKDOWN = `${BK_DOCS_URL_PREFIX}/markdown/${lang}/APIGateway/${docVersion}`;
}());

export default {
// 登录
Expand Down Expand Up @@ -70,7 +90,7 @@ export default {

DOC: {
// 使用指南
GUIDE: `${BK_DOCS_URL_PREFIX_MARKDOWN}`,
GUIDE: `${BK_DOCS_URL_PREFIX_MARKDOWN}/UserGuide/README.md`,

// “请求流水查询规则”
QUERY_USE: `${BK_DOCS_URL_PREFIX_MARKDOWN}/apigateway/reference/log-search-specification.md`,
Expand Down
1 change: 1 addition & 0 deletions src/dashboard-front/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare interface Window {
BK_LIST_USERS_API_URL: string
BK_API_RESOURCE_URL_TMPL: string
BK_DASHBOARD_FE_URL: string
BK_DOCS_URL_PREFIX: string
BK_DOCS_URL_PREFIX_MARKDOWN: string
BK_APIGATEWAY_VERSION: string
GLOBAL_CONFIG: any
Expand Down

0 comments on commit 13c36d4

Please sign in to comment.