Skip to content

Commit

Permalink
Repos work.
Browse files Browse the repository at this point in the history
  • Loading branch information
arran4 committed Jun 20, 2024
1 parent 1e21dfc commit 4926212
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 0 deletions.
66 changes: 66 additions & 0 deletions content/repos/_content.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/* Get remote data. */}}
{{ $data := slice }}
{{ $url := "https://api.github.com/users/arran4/repos" }}
{{ $githubToken := getenv "GITHUB_TOKEN" }}
{{ $headers := dict }}
{{ if $githubToken }}
{{ $headers = dict "Authorization" (printf "token %s" $githubToken) }}
{{ end }}
{{ $perPage := 100 }}
{{ $maxPages := 20 }}
{{ $morePages := true }}

{{ range seq 1 $maxPages }}
{{ if $morePages }}
{{ $pagedUrl := printf "%s?page=%d&per_page=%d" $url . $perPage }}
{{ with resources.GetRemote $pagedUrl (dict "headers" $headers) }}
{{ with .Err }}
{{ errorf "Unable to get remote resource %s: %s" $pagedUrl . }}
{{ else }}
{{ $pageData := . | transform.Unmarshal }}
{{ $data = $data | append $pageData }}
{{ if lt (len $pageData) $perPage }}
{{ $morePages = false }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %s" $pagedUrl }}
{{ end }}
{{ end }}
{{ end }}


{{/* Add pages and page resources. */}}
{{ range $data }}

{{/* Add page. */}}
{{ $content := dict "mediaType" "text/markdown" "value" .description }}
{{ $dates := dict "date" (time.AsTime .updated_at) }}
{{ $heroUrl := printf "https://opengraph.githubassets.com/%s/%s" .default_branch .full_name }}
{{ $repotags := (slice "Untagged") }}
{{ if gt (len .topics) 0 }}
{{ $repotags = .topics }}
{{ end }}
{{ $params := dict
"owner" .owner
"language" .language
"homepage" .homepage
"html_url" .html_url
"repo-tags" $repotags
"tags" (slice "Repos")
"categories" (slice "Repos")
"default_branch" .default_branch
"heroUrl" $heroUrl
}}
{{ $page := dict
"content" $content
"dates" $dates
"kind" "page"
"params" $params
"path" .node_id
"title" .full_name
}}
{{ $.AddPage $page }}

{{ end }}

3 changes: 3 additions & 0 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ taxonomies:
category: categories
tag: tags
star-tag: star-tags
repo-tag: repo-tags

security:
funcs:
Expand All @@ -51,6 +52,8 @@ params:
customMenus:
- name: Stars
url: /stars/
- name: Repos
url: /repos/

features:
toc:
Expand Down
6 changes: 6 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ other = "Stars"
[star-tags]
other = "Star Tags"

[repos]
other = "Repos"

[repo-tags]
other = "Repo Tags"

[more]
other = "More"
8 changes: 8 additions & 0 deletions layouts/partials/misc/repotags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="tags">
<ul style="padding-left: 0;">
{{ range . }}
{{ $url:= printf "repo-tags/%s/" . }}
<li class="rounded"><a href="{{ $url | urlize | relLangURL }}" class="btn btn-sm btn-info">{{ . }}</a></li>
{{ end }}
</ul>
</div>
16 changes: 16 additions & 0 deletions layouts/partials/navigators/repo-taxonomies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ $context := .context }}
{{ $taxo := .taxo }}
{{ $class:= "" }}
{{ if isset $context.Site.Taxonomies ( lower $taxo ) }}
{{ $taxonomy := index $context.Site.Taxonomies ( lower $taxo ) }}
{{ if (gt (len $taxonomy) 0)}}
{{ range $taxonomy }}
{{if eq $context.Title .Page.Title}}
{{ $class = "active" }}
{{else}}
{{$class = ""}}
{{end}}
<li><a class="taxonomy-term {{ $class }}" href="{{ .Page.Permalink }}" data-taxonomy-term="{{ urlize .Page.Title }}"><span class="taxonomy-label">{{ .Page.Title }}</span></a></li>
{{ end }}
{{ end }}
{{ end }}
26 changes: 26 additions & 0 deletions layouts/partials/repocards/post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="post-card repo-card">
<div class="card">
<div class="card-head">
<a href="{{ .RelPermalink | relLangURL }}" class="post-card-link">
<img class="card-img-top" src='{{ partial "helpers/get-hero.html" . }}' alt="Hero Image">
</a>
</div>
<div class="card-body">
<a href="{{ .RelPermalink | relLangURL }}" class="post-card-link">
<h5 class="card-title">{{ .Title }}</h5>
<p class="card-text post-summary">{{ .Summary }}</p>
</a>
{{ if and site.Params.features.tags.enable site.Params.features.tags.on_card }}
{{ partial "misc/repotags.html" (index .Params "repo-tags" ) }}
{{ end }}
</div>
<div class="card-footer">
<span class="float-repot">
{{ .Date | time.Format ":date_full" }}
{{ if site.Params.features.readingTime }} | {{.ReadingTime}} {{ i18n "minute" .ReadingTime }} {{ end }}</span>
<a
href="{{ .RelPermalink | relLangURL }}"
class="float-end btn btn-outline-info btn-sm">{{ i18n "more" }}</a>
</div>
</div>
</div>
56 changes: 56 additions & 0 deletions layouts/repo-tags/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{ define "navbar" }}
{{ partial "navigators/navbar.html" . }}
{{ end }}

{{ define "sidebar" }}
{{ $homePage:="#" }}
{{ if hugo.IsMultilingual }}
{{ $homePage = (path.Join (cond ( eq .Language.Lang "en") "" .Language.Lang) .Type) }}
{{ end }}

<section class="sidebar-section" id="sidebar-section">
<div class="sidebar-holder">
<div class="sidebar" id="sidebar">
<form class="mx-auto" method="get" action="{{ "search" | relLangURL }}">
<input type="text" name="keyword" value="" placeholder="{{ i18n "search" }}" data-search="" id="search-box" />
</form>
<div class="sidebar-tree">
<ul class="tree">
<li style="padding-left: 0px !important;"><a href="{{ "repos" | relLangURL }}" data-filter="all">{{ i18n "repos" }}</a></li>
</ul>
</div>
<div class="sidebar-tree">
<ul class="tree" id="tree">
<li id="list-heading">{{ i18n .Type }}</li>
<div class="subtree taxonomy-terms">
{{ $context := . }}
{{ partial "navigators/repo-taxonomies.html" (dict "context" $context "taxo" "repo-tags" "title" ( humanize "repos" ) ) }}
</div>
</ul>
</div>
</div>
</div>
</section>
{{ end }}

{{ define "content" }}
<section class="content-section" id="content-section">
<div class="content container-fluid" id="content">
<div class="container-fluid post-card-holder" id="post-card-holder">
{{ $posts := where .RegularPagesRecursive "Layout" "!=" "search" }}
{{ $numShow := site.Params.features.pagination.maxPostsPerPage | default 12}}
{{ $paginator := .Paginate $posts $numShow }}
{{ range $paginator.Pages }}
{{ if .Layout }}
{{/* ignore the search.md file*/}}
{{ else }}
{{ partial "repocards/post.html" . }}
{{ end }}
{{ end }}
</div>
<div class="paginator">
{{ template "_internal/pagination.html" . }}
</div>
</div>
</section>
{{ end }}
55 changes: 55 additions & 0 deletions layouts/repos/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{ define "navbar" }}
{{ partial "navigators/navbar.html" . }}
{{ end }}

{{ define "sidebar" }}
{{ $homePage:="#" }}
{{ if hugo.IsMultilingual }}
{{ $homePage = (path.Join (cond ( eq .Language.Lang "en") "" .Language.Lang) .Type) }}
{{ end }}

<section class="sidebar-section" id="sidebar-section">
<div class="sidebar-holder">
<div class="sidebar" id="sidebar">
<form class="mx-auto" method="get" action="{{ "search" | relLangURL }}">
<input type="text" name="keyword" value="" placeholder="{{ i18n "search" }}" data-search="" id="search-box" />
</form>
<div class="sidebar-tree">
<ul class="tree">
<li style="padding-left: 0px !important;"><a href="{{ .Type | relLangURL }}" data-filter="all">{{ i18n .Type }}</a></li>
</ul>
</div>
<div class="sidebar-tree">
<ul class="tree" id="tree">
<li id="list-heading">{{ i18n "repo-tags" }}</li>
<div class="subtree">
{{ partial "navigators/repo-taxonomies.html" (dict "context" . "taxo" "repo-tags" "title" ( humanize "tags" ) ) }}
</div>
</ul>
</div>
</div>
</div>
</section>
{{ end }}

{{ define "content" }}
<section class="content-section" id="content-section">
<div class="content container-fluid" id="content">
<div class="container-fluid post-card-holder" id="post-card-holder repo-card-holder">
{{ $posts := where .RegularPagesRecursive "Layout" "!=" "search" }}
{{ $numShow := site.Params.features.pagination.maxPostsPerPage | default 12}}
{{ $paginator := .Paginate $posts $numShow }}
{{ range $paginator.Pages }}
{{ if .Layout }}
{{/* ignore the search.md file*/}}
{{ else }}
{{ partial "repocards/post.html" . }}
{{ end }}
{{ end }}
</div>
<div class="paginator">
{{ template "_internal/pagination.html" . }}
</div>
</div>
</section>
{{ end }}
Loading

0 comments on commit 4926212

Please sign in to comment.