Skip to content

Commit

Permalink
feat: add the repo parameters for actions and contributors (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed May 17, 2024
1 parent a34a67d commit 137b8d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
10 changes: 10 additions & 0 deletions assets/hb/modules/revision/scss/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
.hb-revision {
font-size: $hb-revision-font-size;
}

.hb-revision-contributor-img {
width: 36px;
height: 36px;
opacity: .75;

&:hover {
opacity: 1;
}
}
80 changes: 79 additions & 1 deletion layouts/partials/hb/modules/revision/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,88 @@
{{- $showContributors := default false site.Params.hb.revision.repo_contributors }}
{{- $repoActions := default true site.Params.hb.revision.repo_actions }}
{{- $createdAt := default true site.Params.hb.revision.created_at }}
{{- if or $createdAt (ne .Lastmod .Date) }}
{{- if or $showContributors (or $createdAt (ne .Lastmod .Date)) }}
<div class="hb-module hb-revision text-body-secondary d-flex flex-wrap">
{{- $tooltip := partial "hb/functions/module-exists" "github.com/hbstack/bs-tooltip" }}
{{- $params := site.Params.hb.revision }}
{{- $icons := default true $params.icons }}
{{- $format := default ":date_full" $params.date_format }}
{{- $path := "" }}
{{- with $.Page.File }}
{{- $path = printf "%scontent/%s"
(cond (eq $params.repo_subpath "") "" (printf "/%s" $params.repo_subpath))
.Path
}}
{{- end }}
{{- $viewURL := "" }}
{{- $editURL := "" }}
{{- $historyURL := "" }}
{{- $repoBranch := default "master" $params.repo_branch }}
{{- $contributors := dict }}
{{- if eq $params.repo_service "github" }}
{{- $url := printf "https://api.github.com/repos/%s/%s/commits?path=%s" $params.repo_owner $params.repo_name $path }}
{{- $editURL = printf "https://github.com/%s/%s/edit/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $viewURL = printf "https://github.com/%s/%s/blob/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $historyURL = printf "https://github.com/%s/%s/commits/%s/%s" $params.repo_owner $params.repo_name $repoBranch $path }}
{{- $opts := dict }}
{{- with getenv "GITHUB_TOKEN" }}
{{- $opts = merge $opts (dict "headers" (dict "Authorization" (printf "Bearer %s" .))) }}
{{- end }}
{{- with and $showContributors (resources.GetRemote $url $opts) }}
{{- range $weight, $commit := transform.Unmarshal . }}
{{- if not .author }}
{{- continue }}
{{- end }}
{{- if not (isset $contributors .author.login) }}
{{- $contributors = merge $contributors (dict .author.login (dict
"weight" $weight
"name" .commit.author.name
"img" .author.avatar_url
"url" .author.html_url))
}}
{{- end }}
{{- end }}
{{- end }}
{{- else if ne $params.repo_service "" }}

This comment has been minimized.

Copy link
@pleasantone

pleasantone Jun 4, 2024

I think you want this to be if (not $params.repo_service) to catch the nil/unset case.

This comment has been minimized.

Copy link
@razonyang

razonyang Jun 4, 2024

Author Member

Yeah, should fix by assiging it a default value (empty string) #69.

{{- warnf "[github.com/hbstack/revision] unsupported repo service: %s" $params.repo_service }}
{{- end }}
{{- with sort $contributors "weight" "desc" }}
<div class="d-flex hb-revision-contributors flex-wrap gap-1 w-100 hb-revision-repo mb-2">
{{- range . }}
<a class="hb-revision-contributor text-decoration-none" href="{{ .url }}" rel="external" target="_blank" title="{{ .name }}">
<img class="hb-revision-contributor-img rounded-circle" src="{{ .img }}" alt="{{ .name }}" />
</a>
{{- end }}
</div>
{{- end }}
{{- with and $repoActions $viewURL $editURL $historyURL }}
<div class="d-flex flex-wrap gap-2 w-100 hb-revision-repo-actions mb-2">
{{- with $viewURL }}
<a class="text-decoration-none" href="{{ . }}" rel="external" target="_blank">
{{- if $icons -}}
{{- partial "icons/icon" (dict "vendor" "bs" "name" "eye" "className" "me-1") -}}
{{- end -}}
View page source
</a>
{{- end }}
{{- with $editURL }}
<a class="text-decoration-none" href="{{ . }}" rel="external" target="_blank">
{{- if $icons -}}
{{- partial "icons/icon" (dict "vendor" "bs" "name" "pencil-square" "className" "me-1") -}}
{{- end -}}
Edit this page
</a>
{{- end }}
{{- with $historyURL}}
<a class="text-decoration-none" href="{{ . }}" rel="external" target="_blank">
{{- if $icons -}}
{{- partial "icons/icon" (dict "vendor" "bs" "name" "clock" "className" "me-1") -}}
{{- end -}}
History
</a>
{{- end }}
</div>
{{- end }}
{{- if ne .Lastmod .Date }}
{{- $lastmod := .Lastmod | time.Format $format }}
{{- $lastmodFull := printf "%s %s" (.Lastmod | time.Format ":date_full") (.Lastmod | time.Format ":time_full") }}
Expand Down

0 comments on commit 137b8d3

Please sign in to comment.