Skip to content

Commit

Permalink
Perf: 性能优化,不重复添加相同的页面并完善控制台提示信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Oct 4, 2024
1 parent cd8c7e0 commit 5d43f37
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions _content.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* @author Lruihao (https://lruihao.cn)
*/ -}}

{{- warnf "component-projects\n%v" (T "projects.warningAdapter") -}}
{{- $auth := dict "Authorization" "" -}}
{{- with (getenv "HUGO_PARAMS_GHTOKEN") -}}
{{- $auth = dict "Authorization" (printf "token %v" .) -}}
{{- end -}}
{{- $headers := dict "headers" $auth -}}
{{- $projectsAdapters := .Site.Params.projectsAdapters -}}
{{- $data := index .Site.Data (printf "projects.%v" .Site.Language.Lang) | default .Site.Data.projects -}}
{{- $renderedRepos := slice -}}

{{- /* Loop through the data and create a post for each repo */ -}}
{{- range $group := $data -}}
Expand All @@ -20,8 +22,8 @@
{{- break -}}
{{- end -}}
{{- range $repo := $group.repos -}}
{{- /* Ignore repos in the ignore list */ -}}
{{- if in $projectsAdapters.ignoreList $repo -}}
{{- /* Skip if the repo is in the ignore list or has been rendered */ -}}
{{- if (in $projectsAdapters.ignoreList $repo) | or (in $renderedRepos $repo) -}}
{{- continue -}}
{{- end -}}
{{- $projectsAdapters.ignoreList -}}
Expand All @@ -42,10 +44,12 @@
(not $readme) | or
(and $projectsAdapters.onlyPublic (eq $repoInfo.visibility "private"))
-}}
{{- warnidf "warning-projects-adapter" "Repo %v is not available or is private." $repo -}}
{{- continue -}}
{{- end -}}

{{- /* Add the repo to the rendered list */ -}}
{{- $renderedRepos = $renderedRepos | append $repo -}}

{{- /* Post dates from repo info */ -}}
{{- $dates := dict
"date" (time.AsTime $repoInfo.created_at)
Expand Down
4 changes: 3 additions & 1 deletion i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

[projects]
relatedArticles = "Related Articles"
errorGetGhRepo = "failed to fetch repo info from GitHub API, Please check the network!"
errorGetGhRepo = "Failed to fetch repo info from GitHub API, Please check the network!"
warningLayout = "The page {{ .Permalink }} is getting repositories via network, please wait a moment..."
warningAdapter = "The content adapter is getting GitHub README via network, please wait a moment..."
source = "Source: [{{ .Name }}]({{ .Link }}){{ with .Website }}<br>Website: <{{ . }}>{{ end }}"
poweredBy = "This page is powered by <a href=\"https://github.com/hugo-fixit/component-projects\">Component Projects</a>."

Expand Down
2 changes: 2 additions & 0 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[projects]
relatedArticles = "相关文章"
errorGetGhRepo = "从 GitHub API 获取仓库信息失败,请检查网络!"
warningLayout = "{{ .Permalink }} 页面正在通过网络获取仓库,请稍等片刻……"
warningAdapter = "内容适配器正在通过网络获取 GitHub README,请稍等片刻……"
source = "来源:[{{ .Name }}]({{ .Link }}){{ with .Website }}<br>网站:<{{ . }}>{{ end }}"
poweredBy = "本页面由 <a href=\"https://github.com/hugo-fixit/component-projects\">Component Projects</a> 强力驱动。"

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/plugin/gh-repo-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
</div>
</div>
{{- else -}}
{{- erroridf "error-get-gh-repo" (printf "[component-projects]: %v" (T "projects.errorGetGhRepo")) -}}
{{- erroridf "error-get-gh-repo" "component-projects\n%v" (T "projects.errorGetGhRepo") -}}
{{- end -}}
1 change: 1 addition & 0 deletions layouts/section/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ <h1 class="single-title animate__animated animate__pulse animate__faster">
{{- /* Content */ -}}
<div class="content" id="content">
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- warnf "component-projects]\n%v" (T "projects.warningLayout" (dict "Permalink" .Permalink)) -}}
{{- $headers := dict "headers" (.Scratch.Get "githubTokenHeader") -}}
{{- $githubLangColors := partial "function/get-remote-json" (dict "URL" "https://raw.githubusercontent.com/ozh/github-colors/master/colors.json" "OPTIONS" $headers ) -}}
{{- range $group := $data -}}
Expand Down

0 comments on commit 5d43f37

Please sign in to comment.