From 47519afe4a102a3beb4f8dd2842c37d45180fa51 Mon Sep 17 00:00:00 2001 From: lutinglt Date: Thu, 27 Nov 2025 17:50:57 +0800 Subject: [PATCH] Synchronized repository template --- CHANGELOG.md | 5 +- gitea/repo/view_content.tmpl | 112 +++++++++++++++++++++++ gitea/repo/view_list.tmpl | 61 +++++++++++++ package.json | 12 +-- styles/index.ts | 2 + styles/public/button.ts | 1 + styles/templates/index.ts | 1 + styles/templates/repo/index.ts | 2 + styles/templates/repo/view_content.ts | 41 +++++++++ styles/templates/repo/view_list.ts | 32 +++++++ templates/repo/view_content.tmpl | 126 ++++++++++++++++++++++++++ templates/repo/view_list.tmpl | 66 ++++++++++++++ 12 files changed, 454 insertions(+), 7 deletions(-) create mode 100644 gitea/repo/view_content.tmpl create mode 100644 gitea/repo/view_list.tmpl create mode 100644 styles/templates/index.ts create mode 100644 styles/templates/repo/index.ts create mode 100644 styles/templates/repo/view_content.ts create mode 100644 styles/templates/repo/view_list.ts create mode 100644 templates/repo/view_content.tmpl create mode 100644 templates/repo/view_list.tmpl diff --git a/CHANGELOG.md b/CHANGELOG.md index 9592f0b..50eb1a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ##### Template File +- Synchronized repository code list page layout and styles +- Synchronized repository add file button menu styles + ### 🐞 Fix -- Fixed extra lines under heatmap. \ No newline at end of file +- Fixed extra lines under heatmap. diff --git a/gitea/repo/view_content.tmpl b/gitea/repo/view_content.tmpl new file mode 100644 index 0000000..66e4fff --- /dev/null +++ b/gitea/repo/view_content.tmpl @@ -0,0 +1,112 @@ +{{$isTreePathRoot := not .TreeNames}} + +
+{{template "repo/sub_menu" .}} +
+
+ {{if not $isTreePathRoot}} + + {{end}} + + {{template "repo/branch_dropdown" dict + "Repository" .Repository + "ShowTabBranches" true + "ShowTabTags" true + "CurrentRefType" .RefFullName.RefType + "CurrentRefShortName" .RefFullName.ShortName + "CurrentTreePath" .TreePath + "RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}" + "AllowCreateNewRef" .CanCreateBranch + "ShowViewAllRefsEntry" true + }} + + {{if and .CanCompareOrPull .RefFullName.IsBranch (not .Repository.IsArchived)}} + {{$cmpBranch := ""}} + {{if ne .Repository.ID .BaseRepo.ID}} + {{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}} + {{end}} + {{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}} + {{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}} + + {{svg "octicon-git-pull-request"}} + + {{end}} + + + {{if $isTreePathRoot}} + {{ctx.Locale.Tr "repo.find_file.go_to_file"}} + {{end}} + + {{if and .RefFullName.IsBranch (not .IsViewFile)}} + + {{end}} + + {{if and $isTreePathRoot .Repository.IsTemplate}} + + {{ctx.Locale.Tr "repo.use_template"}} + + {{end}} + + {{if not $isTreePathRoot}} + {{$treeNameIdxLast := Eval (len .TreeNames) "-" 1}} + + {{StringUtils.EllipsisString .Repository.Name 30}} + {{- range $i, $v := .TreeNames -}} + / + {{- if eq $i $treeNameIdxLast -}} + {{$v}} + + {{- else -}} + {{$p := index $.Paths $i}}{{$v}} + {{- end -}} + {{- end -}} + + {{end}} +
+ +
+ + {{if $isTreePathRoot}} + {{template "repo/clone_panel" .}} + {{end}} + {{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}} + + {{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}} + + {{end}} +
+
+{{if .IsViewFile}} + {{template "repo/view_file" .}} +{{else if .IsBlame}} + {{template "repo/blame" .}} +{{else}}{{/* IsViewDirectory */}} + {{if $isTreePathRoot}} + {{template "repo/code/upstream_diverging_info" .}} + {{end}} + {{template "repo/view_list" .}} + {{if and .ReadmeExist (or .IsMarkup .IsPlainText)}} + {{template "repo/view_file" .}} + {{end}} +{{end}} diff --git a/gitea/repo/view_list.tmpl b/gitea/repo/view_list.tmpl new file mode 100644 index 0000000..145494a --- /dev/null +++ b/gitea/repo/view_list.tmpl @@ -0,0 +1,61 @@ +{{/* use grid layout, still use the old ID because there are many other CSS styles depending on this ID */}} +
+
+ {{template "repo/latest_commit" .}} +
{{if and .LatestCommit .LatestCommit.Committer}}{{DateUtils.TimeSince .LatestCommit.Committer.When}}{{end}}
+
+ {{$.FileIconPoolHTML}} + {{if .HasParentPath}} + + {{index $.FileIcons ".."}} .. + + {{end}} + {{range $item := .Files}} +
+ {{$entry := $item.Entry}} + {{$commit := $item.Commit}} + {{$submoduleFile := $item.SubmoduleFile}} + +
+ {{if $commit}} + {{$commitLink := printf "%s/commit/%s" $.RepoLink (PathEscape $commit.ID.String)}} + {{ctx.RenderUtils.RenderCommitMessageLinkSubject $commit.Message $commitLink $.Repository}} + {{else}} + … {{/* will be loaded again by LastCommitLoaderURL */}} + {{end}} +
+
{{if $commit}}{{DateUtils.TimeSince $commit.Committer.When}}{{end}}
+
+ {{end}} +
diff --git a/package.json b/package.json index cefef0b..bbca793 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,16 @@ "lint": "eslint .", "format": "prettier --write .", "commit": "npm run lint && npm run format && npm run build", - "version": "node scripts/version.cjs" + "version": "node scripts/version.cjs", + "install:clean": "npm cache clean --force && rm -rf node_modules package-lock.json && npm install" }, "devDependencies": { - "@babel/preset-typescript": "^7.27.1", + "@babel/preset-typescript": "^7.28.4", "@eslint/js": "^9.29.0", "@linaria/core": "^6.3.0", "@types/node": "^24.0.3", - "@vanilla-extract/css": "^1.17.4", - "@vanilla-extract/vite-plugin": "^5.0.6", + "@vanilla-extract/css": "^1.17.5", + "@vanilla-extract/vite-plugin": "^5.1.3", "@wyw-in-js/babel-preset": "^0.7.0", "@wyw-in-js/vite": "^0.7.0", "dotenv": "^17.0.0", @@ -30,8 +31,7 @@ "typescript": "^5.8.3", "typescript-eslint": "^8.34.1", "typescript-plugin-css-modules": "^5.1.0", - "typescript-styled-plugin": "^0.18.3", - "vite": "^7.1.9" + "vite": "^7.2.4" }, "prettier": { "printWidth": 120, diff --git a/styles/index.ts b/styles/index.ts index b20025a..b2e274b 100644 --- a/styles/index.ts +++ b/styles/index.ts @@ -6,3 +6,5 @@ import "./public"; // 组件样式 import "./components"; +// 模板专属样式 +import "./templates"; \ No newline at end of file diff --git a/styles/public/button.ts b/styles/public/button.ts index 858679a..2d00202 100644 --- a/styles/public/button.ts +++ b/styles/public/button.ts @@ -111,6 +111,7 @@ export const fixButtonHeight = css` // 修复仓库页仓库操作按钮高度对齐和修正 .repo-button-row .ui.button { min-height: 32px; + height: 32px; } // 修复因上面小按钮高度导致仓库星标克隆等按钮高度过高 .repo-header { diff --git a/styles/templates/index.ts b/styles/templates/index.ts new file mode 100644 index 0000000..7da1954 --- /dev/null +++ b/styles/templates/index.ts @@ -0,0 +1 @@ +import "./repo"; diff --git a/styles/templates/repo/index.ts b/styles/templates/repo/index.ts new file mode 100644 index 0000000..0a45a23 --- /dev/null +++ b/styles/templates/repo/index.ts @@ -0,0 +1,2 @@ +import "./view_content"; +import "./view_list"; diff --git a/styles/templates/repo/view_content.ts b/styles/templates/repo/view_content.ts new file mode 100644 index 0000000..0b4bd6a --- /dev/null +++ b/styles/templates/repo/view_content.ts @@ -0,0 +1,41 @@ +import { css, otherThemeVars, themeVars } from "src/types/vars"; + +export const repoButtonRow = css` + .github-theme-templates { + // 仓库按钮行 + &.repo-button-row { + margin: 0 0 16px 0; + .ui.button.compact.basic:not(.dropdown):not(.jump) { + padding: 0px 10px; + } + .repo-button-row-left .repository-summary { + > .item { + display: inline-flex; + align-items: center; + gap: 4px; + border-radius: ${otherThemeVars.border.radius}; + color: ${themeVars.color.text.light.num1}; + padding: 4px; + height: 32px; + min-height: 32px; + &:hover { + background-color: ${themeVars.github.control.transparent.bgColor.hover}; + text-decoration-line: none; + } + svg { + margin-right: 4px; + } + b { + color: ${themeVars.color.caret}; + } + } + } + .repo-button-row-right { + // 添加文件按钮菜单 + .repo-add-file > .menu { + min-width: 152px; + } + } + } + } +`; diff --git a/styles/templates/repo/view_list.ts b/styles/templates/repo/view_list.ts new file mode 100644 index 0000000..89a7685 --- /dev/null +++ b/styles/templates/repo/view_list.ts @@ -0,0 +1,32 @@ +import { css, otherThemeVars, themeVars } from "src/types/vars"; + +export const repoFileLastCommit = css` + // 仓库页的最后一次提交 + .repository.file.list #repo-files-table .github-theme-templates.repo-file-line.repo-file-last-commit { + padding-right: 10px; + // 提交时间 + .github-latest-time { + font-size: 12px; + } + // 提交历史按钮 + .github-latest-commit { + display: inline-flex; + align-items: center; + gap: 4px; + border-radius: ${otherThemeVars.border.radius}; + padding: 0px 8px; + min-height: 28px; + height: 28px; + font-size: 12px; + font-weight: 500; + &:hover { + background-color: ${themeVars.github.control.transparent.bgColor.hover}; + color: inherit; + text-decoration-line: none; + } + svg { + color: ${themeVars.color.text.light.num1}; + } + } + } +`; diff --git a/templates/repo/view_content.tmpl b/templates/repo/view_content.tmpl new file mode 100644 index 0000000..fbe6908 --- /dev/null +++ b/templates/repo/view_content.tmpl @@ -0,0 +1,126 @@ +{{$isTreePathRoot := not .TreeNames}} + +
+{{/* {{template "repo/sub_menu" .}} */}} +
+
+ {{if not $isTreePathRoot}} + + {{end}} + + {{template "repo/branch_dropdown" dict + "Repository" .Repository + "ShowTabBranches" true + "ShowTabTags" true + "CurrentRefType" .RefFullName.RefType + "CurrentRefShortName" .RefFullName.ShortName + "CurrentTreePath" .TreePath + "RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}" + "AllowCreateNewRef" .CanCreateBranch + "ShowViewAllRefsEntry" true + }} + + {{if and .CanCompareOrPull .RefFullName.IsBranch (not .Repository.IsArchived)}} + {{$cmpBranch := ""}} + {{if ne .Repository.ID .BaseRepo.ID}} + {{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}} + {{end}} + {{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}} + {{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}} + + {{svg "octicon-git-pull-request"}} + + {{end}} + + {{if and $isTreePathRoot (.Permission.CanRead ctx.Consts.RepoUnitTypeCode) (not .IsEmptyRepo)}} + + {{end}} + + {{if not $isTreePathRoot}} + {{$treeNameIdxLast := Eval (len .TreeNames) "-" 1}} + + {{StringUtils.EllipsisString .Repository.Name 30}} + {{- range $i, $v := .TreeNames -}} + / + {{- if eq $i $treeNameIdxLast -}} + {{$v}} + + {{- else -}} + {{$p := index $.Paths $i}}{{$v}} + {{- end -}} + {{- end -}} + + {{end}} +
+ +
+ + {{if $isTreePathRoot}} + + {{svg "octicon-search" 16}} + + {{end}} + + {{if and .RefFullName.IsBranch (not .IsViewFile)}} + + {{end}} + + {{if and $isTreePathRoot .Repository.IsTemplate}} + + {{ctx.Locale.Tr "repo.use_template"}} + + {{end}} + + {{if $isTreePathRoot}} + {{template "repo/clone_panel" .}} + {{end}} + {{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}} + + {{svg "octicon-history" 16}}{{ctx.Locale.Tr "repo.file_history"}} + + {{end}} +
+
+{{if .IsViewFile}} + {{template "repo/view_file" .}} +{{else if .IsBlame}} + {{template "repo/blame" .}} +{{else}}{{/* IsViewDirectory */}} + {{if $isTreePathRoot}} + {{template "repo/code/upstream_diverging_info" .}} + {{end}} + {{template "repo/view_list" .}} + {{if and .ReadmeExist (or .IsMarkup .IsPlainText)}} + {{template "repo/view_file" .}} + {{end}} +{{end}} \ No newline at end of file diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl new file mode 100644 index 0000000..f8701c9 --- /dev/null +++ b/templates/repo/view_list.tmpl @@ -0,0 +1,66 @@ +{{/* use grid layout, still use the old ID because there are many other CSS styles depending on this ID */}} +
+
+ {{template "repo/latest_commit" .}} +
{{if and .LatestCommit .LatestCommit.Committer}}{{DateUtils.TimeSince .LatestCommit.Committer.When}}{{end}}
+ {{if and (not .TreeNames) (.Permission.CanRead ctx.Consts.RepoUnitTypeCode) (not .IsEmptyRepo)}} + + {{svg "octicon-history"}} {{ctx.Locale.PrettyNumber .CommitsCount}} {{ctx.Locale.TrN .CommitsCount "repo.commit" "repo.commits"}} + + {{end}} +
+ {{$.FileIconPoolHTML}} + {{if .HasParentPath}} + + {{index $.FileIcons ".."}} .. + + {{end}} + {{range $item := .Files}} +
+ {{$entry := $item.Entry}} + {{$commit := $item.Commit}} + {{$submoduleFile := $item.SubmoduleFile}} + +
+ {{if $commit}} + {{$commitLink := printf "%s/commit/%s" $.RepoLink (PathEscape $commit.ID.String)}} + {{ctx.RenderUtils.RenderCommitMessageLinkSubject $commit.Message $commitLink $.Repository}} + {{else}} + … {{/* will be loaded again by LastCommitLoaderURL */}} + {{end}} +
+
{{if $commit}}{{DateUtils.TimeSince $commit.Committer.When}}{{end}}
+
+ {{end}} +