From d351bbeeb66f561fb65428dc7124ecf6ae3ebb38 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Fri, 23 May 2025 11:13:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0openatom=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/merge.js | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/scripts/merge.js b/scripts/merge.js index eef569015..555bfd103 100644 --- a/scripts/merge.js +++ b/scripts/merge.js @@ -52,6 +52,39 @@ const checkGitRepo = (repoPath) => { }); }; +// openatom 替换域名 +function replaceOrgDomain(targetPath) { + if (!fs.existsSync(targetPath)) { + console.log(`路径 ${targetPath} 不存在`); + return; + } + + fs.readdirSync(targetPath).forEach((name) => { + const completedPath = path.join(targetPath, name); + if (fs.statSync(completedPath).isDirectory()) { + replaceOrgDomain(completedPath); + return; + } + + if (!name.endsWith('js') && !name.endsWith('html') && !name.endsWith('toml')) { + return; + } + + const content = fs.readFileSync(completedPath, 'utf8'); + const newContent = content.replace(/([a-zA-Z0-9\-]*)?\.openeuler\.org/g, (match, $1) => { + if ($1 === 'forum' || $1 === 'pkgmanage' || $1 === 'compliance') { + return match; + } + + console.log('替换内容:', completedPath, `${match} -> ${`${$1 || ''}.openeuler.openatom.cn`}`); + + return `${$1 || ''}.openeuler.openatom.cn`; + }); + + fs.writeFileSync(completedPath, newContent, 'utf8'); + }); +} + // 检出分支 const checkoutBranch = (repoPath, branchName) => { return new Promise((resolve, reject) => { @@ -218,7 +251,7 @@ const normalizeContent = async (branch) => { } }; -const normalizeContentWithHugo = async (branch) => { +const normalizeContentWithHugo = async (branch, source) => { const branchName = getBranchName(branch); // 复制website内容到build目录 @@ -248,9 +281,15 @@ const normalizeContentWithHugo = async (branch) => { }); await copyContentToDir(`${REPO_DOCS_DIR}/docs/en/`, `${BUILD_DIR}/content/en/docs/${branchName}/`); } + + if (source === 'openatom') { + replaceOrgDomain(path.join(BUILD_DIR, 'i18n')); + replaceOrgDomain(path.join(BUILD_DIR, 'layouts')); + replaceOrgDomain(path.join(BUILD_DIR, 'static')); + } }; -const merge = async (branch) => { +const merge = async (branch, source) => { deleteBuildDir(BUILD_DIR); createBuildDir(BUILD_DIR); try { @@ -258,7 +297,7 @@ const merge = async (branch) => { if (NEW_VERSONS.includes(getBranchName(branch))) { await normalizeContent(branch); } else { - await normalizeContentWithHugo(branch); + await normalizeContentWithHugo(branch, source); } } catch (error) { console.error(error.message); @@ -271,5 +310,5 @@ if (args.length === 0) { console.error('请提供分支名称'); process.exit(1); } else { - merge(args[0]); + merge(args[0], args[1]); } -- Gitee