Skip to content

Commit

Permalink
Merge pull request #1431 from benero/feat_docs
Browse files Browse the repository at this point in the history
minor: 统一文档地址 --story=119997066
  • Loading branch information
benero authored Oct 10, 2024
2 parents 2964118 + d78448b commit bfeac35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def my_before_proxy_func(request, json_data, request_headers):
os.getenv("BK_DOCS_URL_PREFIX", "{}o/bk_docs_center".format(BK_PAAS_HOST)),
)
BK_DOC_URL = "{}{}".format(
BK_DOC_CENTER_HOST, "/markdown/ITSM/UserGuide/Introduce/README.md"
BK_DOC_CENTER_HOST, "/markdown/{lang}/ITSM/{version}/UserGuide/Introduce/README.md"
)

BK_IEOD_LOGIN_URL = os.environ.get("BK_IEOD_LOGIN_URL", "")
Expand Down
23 changes: 20 additions & 3 deletions itsm/sites/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from django.conf import settings
from django.http import JsonResponse, HttpResponseRedirect
from django.shortcuts import render
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext as _, get_language
from django.views.decorators.http import require_GET
from mako.template import Template

Expand Down Expand Up @@ -116,6 +116,15 @@ def index(request):
).value
except SystemSettings.DoesNotExist:
notice_center_switch_value = "off"

# 文档地址转换
doc_lang = "EN"
lang = get_language()
if lang in ["zh-cn", "zh-hans"]:
doc_lang = "ZH"

version = get_version()
doc_url = settings.BK_DOC_URL.format(lang=doc_lang, version=get_major_minor_version(version))

return render(
request,
Expand All @@ -132,13 +141,13 @@ def index(request):
"BK_USER_MANAGE_HOST": BK_USER_MANAGE_HOST,
"BK_PAAS_ESB_HOST": settings.BK_PAAS_ESB_HOST,
"TAM_PROJECT_ID": settings.TAM_PROJECT_ID,
"DOC_URL": settings.BK_DOC_URL,
"DOC_URL": doc_url,
"BK_DOC_CENTER_HOST": settings.BK_DOC_CENTER_HOST,
"SOPS_URL": settings.SOPS_SITE_URL,
"NOTICE_CENTER_SWITCH": notice_center_switch_value,
"BK_SHARED_RES_URL": settings.BK_SHARED_RES_URL,
"BK_PLATFORM_NAME": settings.BK_PLATFORM_NAME,
"VERSION": get_version(),
"VERSION": version,
"BKAPP_CSRF_COOKIE_NAME": settings.CSRF_COOKIE_NAME,
},
)
Expand Down Expand Up @@ -174,4 +183,12 @@ def get_version():
return content.strip()


def get_major_minor_version(version_string):
# 使用 split() 方法分割字符串
parts = version_string.split('.')
# 取前两个部分并用 '.' 连接
major_minor = '.'.join(parts[:2])
return major_minor


template_name = "wiki/create.html"

0 comments on commit bfeac35

Please sign in to comment.