Skip to content

Commit b12bae4

Browse files
committed
Fix: 修复网络不好时,可通过 ignoreLogs = ['error-get-gh-repo'] 忽略错误
1 parent e03fd7d commit b12bae4

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ Use the `gh-repo-card-container` and `gh-repo-card` shortcodes in any page to di
8989
{{< gh-repo-card repo="Lruihao/hugo-blog" >}}
9090
{{< /gh-repo-card-container >}}
9191
```
92+
93+
## 故障排除
94+
95+
本地调试时,可以在 `hugo server` 命令后加上 `--ignoreCache` 参数以清除缓存。

README.zh-cn.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ Some text to display at the start of the page.
8989
{{< gh-repo-card repo="Lruihao/hugo-blog" >}}
9090
{{< /gh-repo-card-container >}}
9191
```
92+
93+
## Troubleshooting
94+
95+
You can add the `--ignoreCache` parameter to the `hugo server` command to clear the cache in local server.

i18n/en.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[projects]
55
relatedArticles = "Related Articles"
6+
errorGetGhRepo = "failed to fetch repo info from GitHub API, Please check the network!"
67

78
[projects.totalStarCount]
89
one = "Total one star"

i18n/zh-CN.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[projects]
66
relatedArticles = "相关文章"
7+
errorGetGhRepo = "从 GitHub API 获取仓库信息失败,请检查网络!"
78

89
[projects.totalStarCount]
910
other = "累计 {{ .Count }} stars"
Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
{{- $repoInfo := .RepoInfo -}}
22
{{- $githubLangColors := .GithubLangColors -}}
33

4-
<div class="gh-repo-card">
5-
<div class="repo-card-content">
6-
<div class="repo-name">
7-
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo mr-1 color-fg-muted">
8-
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path>
9-
</svg>
10-
<a href="{{ $repoInfo.html_url }}" class="repo-url" title="{{ $repoInfo.full_name }}" target="_blank">
11-
<span>{{ $repoInfo.owner.login }}/</span><span>{{ $repoInfo.name }}</span>
12-
</a>
13-
{{- $visibility := cond $repoInfo.is_template (add $repoInfo.visibility " template") $repoInfo.visibility -}}
14-
{{- $visibility = cond $repoInfo.archived (add $repoInfo.visibility " archived") $visibility -}}
15-
<span class="repo-visibility" data-archived="{{ $repoInfo.archived }}">{{ strings.FirstUpper $visibility }}</span>
16-
</div>
17-
{{- with $repoInfo.parent -}}
18-
<p class="repo-fork-from">Fork from <a href="{{ .html_url }}" target="_blank">{{ .full_name }}</a></p>
19-
{{- end -}}
20-
<p class="repo-desc">{{ $repoInfo.description }}</p>
21-
<p class="repo-statistics">
22-
{{- with $repoInfo.language -}}
23-
<span class="repo-lang">
24-
<span class="repo-lang-color" style="background-color: {{ (index $githubLangColors $repoInfo.language).color }};"></span>
25-
<span itemprop="programmingLanguage">{{ $repoInfo.language }}</span>
26-
</span>
27-
{{- end -}}
28-
{{- with $repoInfo.stargazers_count -}}
29-
<a href="{{ add $repoInfo.html_url `/stargazers` }}" title="{{ . }} stars" class="repo-stars" target="_blank">
30-
<svg aria-label="stars" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star">
31-
<path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path>
32-
</svg>
33-
{{- partial "function/format-number" (dict "NUMBER" .) -}}
4+
{{- if $repoInfo | and $githubLangColors -}}
5+
<div class="gh-repo-card">
6+
<div class="repo-card-content">
7+
<div class="repo-name">
8+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo mr-1 color-fg-muted">
9+
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path>
10+
</svg>
11+
<a href="{{ $repoInfo.html_url }}" class="repo-url" title="{{ $repoInfo.full_name }}" target="_blank">
12+
<span>{{ $repoInfo.owner.login }}/</span><span>{{ $repoInfo.name }}</span>
3413
</a>
14+
{{- $visibility := cond $repoInfo.is_template (add $repoInfo.visibility " template") $repoInfo.visibility -}}
15+
{{- $visibility = cond $repoInfo.archived (add $repoInfo.visibility " archived") $visibility -}}
16+
<span class="repo-visibility" data-archived="{{ $repoInfo.archived }}">{{ strings.FirstUpper $visibility }}</span>
17+
</div>
18+
{{- with $repoInfo.parent -}}
19+
<p class="repo-fork-from">Fork from <a href="{{ .html_url }}" target="_blank">{{ .full_name }}</a></p>
3520
{{- end -}}
36-
{{- with $repoInfo.forks_count -}}
37-
<a href="{{ add $repoInfo.html_url `/forks` }}" title="{{ . }} forks" class="repo-forks" target="_blank">
38-
<svg aria-label="forks" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-forked">
39-
<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
40-
</svg>
41-
{{- partial "function/format-number" (dict "NUMBER" .) -}}
42-
</a>
43-
{{- end -}}
44-
</p>
21+
<p class="repo-desc">{{ $repoInfo.description }}</p>
22+
<p class="repo-statistics">
23+
{{- with $repoInfo.language -}}
24+
<span class="repo-lang">
25+
<span class="repo-lang-color" style="background-color: {{ (index $githubLangColors $repoInfo.language).color }};"></span>
26+
<span itemprop="programmingLanguage">{{ $repoInfo.language }}</span>
27+
</span>
28+
{{- end -}}
29+
{{- with $repoInfo.stargazers_count -}}
30+
<a href="{{ add $repoInfo.html_url `/stargazers` }}" title="{{ . }} stars" class="repo-stars" target="_blank">
31+
<svg aria-label="stars" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star">
32+
<path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path>
33+
</svg>
34+
{{- partial "function/format-number" (dict "NUMBER" .) -}}
35+
</a>
36+
{{- end -}}
37+
{{- with $repoInfo.forks_count -}}
38+
<a href="{{ add $repoInfo.html_url `/forks` }}" title="{{ . }} forks" class="repo-forks" target="_blank">
39+
<svg aria-label="forks" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-forked">
40+
<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
41+
</svg>
42+
{{- partial "function/format-number" (dict "NUMBER" .) -}}
43+
</a>
44+
{{- end -}}
45+
</p>
46+
</div>
4547
</div>
46-
</div>
47-
{{- /* EOF */ -}}
48+
{{- else -}}
49+
{{- erroridf "error-get-gh-repo" (printf "[component-projects]: %v" (T "projects.errorGetGhRepo")) -}}
50+
{{- end -}}

layouts/shortcodes/gh-repo-card.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@
1212
{{- .Scratch.Set "githubLangColors" $githubLangColors -}}
1313
{{- end -}}
1414

15-
{{- if not $repoInfo -}}
16-
{{- erroridf "error-get-gh-repo" "gh-repo-card shortcode: failed to fetch repo info from GitHub API" -}}
17-
{{- end -}}
18-
1915
{{- dict "RepoInfo" $repoInfo "GithubLangColors" $githubLangColors | partial "plugin/gh-repo-card.html" -}}

0 commit comments

Comments
 (0)