diff --git a/gitea/templates/base/head_navbar.tmpl b/gitea/templates/base/head_navbar.tmpl index b721779..8cb72d6 100644 --- a/gitea/templates/base/head_navbar.tmpl +++ b/gitea/templates/base/head_navbar.tmpl @@ -120,6 +120,13 @@ {{svg "octicon-question"}} {{ctx.Locale.Tr "help"}} + {{if .IsAdmin}} +
+ + {{svg "octicon-server"}} + {{ctx.Locale.Tr "admin_panel"}} + + {{end}}
{{svg "octicon-sign-out"}} diff --git a/package.json b/package.json index c98ce79..f620770 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitea-github-theme", - "version": "1.25.3.rc", + "version": "1.25.3", "type": "module", "scripts": { "dev": "vite build --mode dev", @@ -10,6 +10,7 @@ "commit": "npm run lint && npm run format && npm run build", "version": "node scripts/version.cjs", "tr": "node scripts/translate.cjs", + "tmpl": "node scripts/update_template.cjs", "release": "npm run build && npm run tr", "install:clean": "npm cache clean --force && rm -rf node_modules package-lock.json && npm install", "install:vite8": "npm install --force" diff --git a/scripts/translate.cjs b/scripts/translate.cjs index 76a183b..858e38a 100644 --- a/scripts/translate.cjs +++ b/scripts/translate.cjs @@ -17,7 +17,7 @@ const localePath = "options/locale"; const [major, minor, patch, tag = ""] = pkg.version.split("."); -console.log("Version: ", pkg.version); +console.log("Version:", pkg.version); let versionPath = ""; if (tag.includes("rc") || patch.includes("latest")) { versionPath = `${githubBranchPath}/v${major}.${minor}`; @@ -26,14 +26,12 @@ if (tag.includes("rc") || patch.includes("latest")) { } const githubUrl = `${githubSite}/${giteaRepo}/${versionPath}/${localePath}`; - const locales = fs.readdirSync(path.join(rootDir, localePath)).filter(file => file.endsWith(".ini")); -// 使用立即执行异步函数 (async () => { for (const locale of locales) { const localUrl = `${githubUrl}/${locale}`; - console.log("LocaleUrl: ", localUrl); + console.log("LocaleUrl:", localUrl); const themeLocale = fs.readFileSync(path.join(rootDir, localePath, locale), "utf-8"); const response = await fetch(localUrl); diff --git a/scripts/update_template.cjs b/scripts/update_template.cjs new file mode 100644 index 0000000..6874660 --- /dev/null +++ b/scripts/update_template.cjs @@ -0,0 +1,54 @@ +const fs = require("fs"); +const path = require("path"); + +const rootDir = path.join(__dirname, ".."); +const pkgPath = path.join(rootDir, "package.json"); +const pkg = JSON.parse(fs.readFileSync(pkgPath)); + +const githubSite = "https://raw.githubusercontent.com"; +const giteaRepo = "go-gitea/gitea"; +const githubTagPath = "refs/tags"; +const tmplPath = "templates"; +const localTmplPath = path.join(rootDir, "gitea", tmplPath); +const [major, minor, patch = ""] = pkg.version.split("."); +console.log("Version:", pkg.version); +const versionPath = `${githubTagPath}/v${major}.${minor}.${patch}`; +const githubUrl = `${githubSite}/${giteaRepo}/${versionPath}/${tmplPath}`; + +// 递归读取所有子目录中的 .tmpl 文件 +function readTmplFilesRecursively(dir) { + const results = []; + const files = fs.readdirSync(dir); + + for (const file of files) { + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) { + // 如果是目录,递归读取 + results.push(...readTmplFilesRecursively(filePath)); + } else if (file.endsWith(".tmpl")) { + // 如果是 .tmpl 文件,添加到结果中(相对于模板目录的相对路径) + const relativePath = path.relative(localTmplPath, filePath); + results.push(relativePath); + } + } + + return results; +} + +// 读取所有模板文件 +const tmpls = readTmplFilesRecursively(localTmplPath); +(async () => { + for (const tmpl of tmpls) { + const tmplUrl = `${githubUrl}/${tmpl}`; + console.log("TmplUrl:", tmplUrl); + + const response = await fetch(tmplUrl); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + let content = await response.text(); + fs.writeFileSync(path.join(localTmplPath, tmpl), content); + } +})(); diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 8bdd240..e4a9a85 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -114,6 +114,13 @@ {{svg "octicon-question"}} {{ctx.Locale.Tr "help"}} + {{if .IsAdmin}} +
+ + {{svg "octicon-server"}} + {{ctx.Locale.Tr "admin_panel"}} + + {{end}}
{{svg "octicon-sign-out"}}