Skip to content

Commit

Permalink
Add repository-links feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Jan 13, 2025
1 parent beb5232 commit 4d295fa
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Quickstart a new site with the Zen theme by using the [Zen demo repo as a templa
* [Content security policy headers](#Content-security-policy-headers)
* [Choose between using AlpineJS, jQuery or Umbrella JS](#choose-between-using-alpinejs-jquery-or-umbrella-js)
* [Use npm to lint Sass and JavaScript](#use-npm-to-lint-sass-and-javascript)
* [Repository links](#repository-links)
* [Math typesetting with KaTeX](#math-typesetting-with-katex)
* [Getting help](#getting-help)
* [Credits](#credits)
Expand Down Expand Up @@ -865,6 +866,21 @@ Node.js software you need. To install them run:
nmp run lint (project + theme)


## Repository links

Add view and edit repo links on your post. Activates when you add repository settings, see example for GitHub below. See more in the partial `repository-links.html`.

```yaml
repository:
branch: "main"
owner: "kalle"
repo: "myhugowebsite"
urlPatternEdit: "https://github.com/%s/%s/edit/%s/%s"
urlPatternView: "https://github.com/%s/%s/blob/%s/%s"
```
Copied from example by [jmooring](https://discourse.gohugo.io/t/hugo-v0-112-0-new-template-functions/44512)
## Math typesetting with KaTeX
Download the latest release from <https://github.com/KaTeX/KaTeX/releases>. Unpack and place the resulting "katex" directory in the root `static` directory.
Expand Down
9 changes: 9 additions & 0 deletions assets/sass/_zen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ article {
text-align: end;
}

.repository-links {
justify-content: end;
align-items: center;

svg {
order: 1;
}
}

// Navigation

.main-menu {
Expand Down
6 changes: 6 additions & 0 deletions i18n/ar.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "محتوى حديث"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "يجب تفعيل جافاسكريبت في المتصفح لاستخدام هذه الوظيفة."

Expand Down
6 changes: 6 additions & 0 deletions i18n/da.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Seneste indhold"
[string_see_also]
other = "Se også"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Du skal have Javascript slået til for at bruge denne funktion."

Expand Down
6 changes: 6 additions & 0 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Aktuelle Inhalte"
[string_see_also]
other = "Siehe auch"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Javascript muss aktiviert sein um dieses Kontaktformular zu nutzen."

Expand Down
6 changes: 6 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Recent content"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "You must have Javascript enabled to use this function."

Expand Down
6 changes: 6 additions & 0 deletions i18n/fi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Viimeaikainen sisältö"
[string_see_also]
other = "Lue myös"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Javascript-teknologia täytyy olla tuettuna jotta tämä toiminto on käytössä."

Expand Down
6 changes: 6 additions & 0 deletions i18n/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Contenu récent"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Javascript doit être activé pour utiliser ce formulaire de contact."

Expand Down
6 changes: 6 additions & 0 deletions i18n/he.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "תוכן מעודכן"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "javascript פונקציה זו חייבת"

Expand Down
6 changes: 6 additions & 0 deletions i18n/id.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Konten Terkini"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Anda harus mengaktifkan Javascript untuk menggunakan fasilitas ini."

Expand Down
6 changes: 6 additions & 0 deletions i18n/nb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Siste innhold"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Du må ha skrudd på Javascript for å bruke denne funksjonen."

Expand Down
6 changes: 6 additions & 0 deletions i18n/pt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ other = "Conteúdo recente"
[string_see_also]
other = "See also"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Você deve ter o Javascript habilitado para usar este formulário de contato"

Expand Down
6 changes: 6 additions & 0 deletions i18n/sr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Скорашњи садржај"
[string_see_also]
other = "Такође погледајте"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Морате имати омогућен Јаваскрипт да би користили ову функцију."

Expand Down
6 changes: 6 additions & 0 deletions i18n/sv.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Senaste innehåll"
[string_see_also]
other = "Se också"

[string_edit]
other = "Redigera"

[string_view]
other = "Visa"

[js_required]
other = "Du behöver ha Javascript aktiverat för att använda denna funktion."

Expand Down
6 changes: 6 additions & 0 deletions i18n/sw.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "Maudhui ya hivi majuzi"
[string_see_also]
other = "Angalia pia"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "Javascript lazima iwezeshwe ili kutumia chaguo hili la kukokotoa."

Expand Down
6 changes: 6 additions & 0 deletions i18n/zh-cn.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ other = "近期文章"
[string_see_also]
other = "参见"

[string_edit]
other = "Edit"

[string_view]
other = "View"

[js_required]
other = "要使用此功能, 必须先启用 JavaScript"

Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ <h1 class="title{{ if $.Param "submitted" | default false }} mb--xxs{{ end }}">{

{{ .Content }}

{{ if $.Param "relatedposts" | default false }}{{ partial "relatedposts.html" . }}{{ end -}}

{{ if ne .Lastmod .Date }}{{ partial "dates.html" . }}{{ end -}}
{{ if site.Params.repository | default false }}{{ partial "repository-links.html" . }}{{ end -}}
{{ if $.Param "relatedposts" | default false }}{{ partial "relatedposts.html" . }}{{ end -}}
</article>
</main>
{{ end -}}
2 changes: 1 addition & 1 deletion layouts/partials/relatedposts.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<aside class="related layout__related">
<aside class="related">
{{ $related := site.RegularPages.Related . | first 3 -}}
{{ with $related -}}
<h2>{{ i18n "string_see_also" }}</h2>
Expand Down
14 changes: 14 additions & 0 deletions layouts/partials/repository-links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ if .File -}}
{{ with site.Params.repository -}}
{{ $branch := .branch | default "main" -}}
{{ $path := strings.TrimPrefix hugo.WorkingDir .File.Filename -}}
{{ $edithref := printf .urlPatternEdit .owner .repo $branch $path | urls.JoinPath -}}
{{ $viewhref := printf .urlPatternView .owner .repo $branch $path | urls.JoinPath -}}
<div class="repository-links flex-inline meta">
<svg width="30" height="30" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 92 92"><defs><clipPath id="a"><path d="M0 .113h91.887V92H0Zm0 0"/></clipPath></defs><g clip-path="url(#a)"><path style="stroke:none;fill-rule:nonzero;fill:#100f0d;fill-opacity:1" d="M90.156 41.965 50.036 1.848a5.913 5.913 0 0 0-8.368 0l-8.332 8.332 10.566 10.566a7.03 7.03 0 0 1 7.23 1.684 7.043 7.043 0 0 1 1.673 7.277l10.183 10.184a7.026 7.026 0 0 1 7.278 1.672 7.04 7.04 0 0 1 0 9.957 7.045 7.045 0 0 1-9.961 0 7.038 7.038 0 0 1-1.532-7.66l-9.5-9.497V59.36a7.04 7.04 0 0 1 1.86 11.29 7.04 7.04 0 0 1-9.957 0 7.04 7.04 0 0 1 0-9.958 7.034 7.034 0 0 1 2.308-1.539V33.926a7.001 7.001 0 0 1-2.308-1.535 7.049 7.049 0 0 1-1.516-7.7L29.242 14.273 1.734 41.777a5.918 5.918 0 0 0 0 8.371L41.855 90.27a5.92 5.92 0 0 0 8.368 0l39.933-39.934a5.925 5.925 0 0 0 0-8.371"/></g></svg>
<a href="{{ $viewhref }}" rel="external">{{ i18n "string_view" }}</a>
<a href="{{ $edithref }}" rel="external">{{ i18n "string_edit" }}</a>
</div>
{{ end -}}
{{ end -}}

0 comments on commit 4d295fa

Please sign in to comment.