treefmt: fix config, add prettier-plugin-go-template

This commit is contained in:
Jan Kremer 2024-10-17 17:41:01 +02:00
parent 6ccec6f792
commit 9e8f680c52
Signed by: jan
GPG key ID: A7DA689CB3B078EC
10 changed files with 137 additions and 85 deletions

View file

@ -1,14 +1,19 @@
{{ define "main" }} {{ .Content }} {{ $pages := .Paginate (where
.Site.RegularPages "Type" "ne" "page") }} {{ range $pages.Pages }}
<a href="{{ .RelPermalink }}" style="display: block">
{{ define "main" }}
{{ .Content }}
{{ $pages := .Paginate (where
.Site.RegularPages "Type" "ne" "page")
}}
{{ range $pages.Pages }}
<a href="{{ .RelPermalink }}" style="display: block">
<div class="list">
{{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }} {{
$dateHuman := .Date | time.Format "2006-01-02" }}
{{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }}
{{ $dateHuman := .Date | time.Format "2006-01-02" }}
<time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
<h2>{{ .Title }}</h2>
<p class="lead">{{ .Description }}</p>
</div>
</a>
{{ end }} {{ end }}
</a>
{{ end }}
{{ end }}

View file

@ -1,13 +1,16 @@
{{ define "main" }} {{ .Content }} {{ range .Pages }}
<a href="{{ .RelPermalink }}" style="display: block">
{{ define "main" }}
{{ .Content }}
{{ range .Pages }}
<a href="{{ .RelPermalink }}" style="display: block">
<div class="list">
{{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }} {{
$dateHuman := .Date | time.Format "2006-01-02" }}
{{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }}
{{ $dateHuman := .Date | time.Format "2006-01-02" }}
<time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
<h2>{{ .Title }}</h2>
<p class="lead">{{ .Description }}</p>
</div>
</a>
{{ end }} {{ end }}
</a>
{{ end }}
{{ end }}

View file

@ -1,7 +1,7 @@
{{ define "main" }}
<article>
{{ $dateMachine := .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }} {{
$dateHuman := .Lastmod | time.Format "2006-01-02" }}
<article>
{{ $dateMachine := .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }}
{{ $dateHuman := .Lastmod | time.Format "2006-01-02" }}
<time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
<br />
@ -10,5 +10,6 @@
<p class="lead">{{ .Description }}</p>
{{ .Content }}
</article>
{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }} {{ end }}
</article>
{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
{{ end }}

View file

@ -5,10 +5,18 @@
<meta name="author" content="Jan Kremer" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
{{ if .IsHome }}{{ site.Title }}{{ else }}{{ printf "%s %s" .Title
site.Title }}{{ end }}
{{ if .IsHome }}
{{ site.Title }}
{{ else }}
{{ printf "%s %s" .Title
site.Title
}}
{{ end }}
</title>
{{ partialCached "head/css.html" . }} {{ partialCached "head/js.html" . }} {{
partial "head/analytics.html" . }} {{ with .OutputFormats.Get "rss" -}} {{
printf `<link rel="%q" type="%q" href="%q" title="%q" />` .Rel .MediaType.Type
.Permalink site.Title | safeHTML }} {{ end }}
{{ partialCached "head/css.html" . }} {{ partialCached "head/js.html" . }}
{{ partial "head/analytics.html" . }}
{{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%q" type="%q" href="%q" title="%q" />` .Rel .MediaType.Type
.Permalink site.Title | safeHTML
}}
{{ end }}

View file

@ -1,7 +1,7 @@
{{ if hugo.IsProduction }}
<script
<script
data-goatcounter="https://jankremer.goatcounter.com/count"
async
src="//gc.zgo.at/count.js"
></script>
></script>
{{ end }}

View file

@ -1,11 +1,16 @@
{{- with resources.Get "css/main.css" }} {{- if eq hugo.Environment
"development" }}
<link rel="stylesheet" href="{{ .RelPermalink }}" />
{{- else }} {{- with . | minify | fingerprint }}
<link
{{- with resources.Get "css/main.css" }}
{{- if eq hugo.Environment
"development"
}}
<link rel="stylesheet" href="{{ .RelPermalink }}" />
{{- else }}
{{- with . | minify | fingerprint }}
<link
rel="stylesheet"
href="{{ .RelPermalink }}"
integrity="{{ .Data.Integrity }}"
crossorigin="anonymous"
/>
{{- end }} {{- end }} {{- end }}
/>
{{- end }}
{{- end }}
{{- end }}

View file

@ -1,11 +1,18 @@
{{- with resources.Get "js/main.js" }} {{- if eq hugo.Environment "development"
}} {{- with . | js.Build }}
<script src="{{ .RelPermalink }}"></script>
{{- end }} {{- else }} {{- $opts := dict "minify" true }} {{- with . | js.Build
$opts | fingerprint }}
<script
{{- with resources.Get "js/main.js" }}
{{- if eq hugo.Environment "development" }}
{{- with . | js.Build }}
<script src="{{ .RelPermalink }}"></script>
{{- end }}
{{- else }}
{{- $opts := dict "minify" true }}
{{- with . | js.Build
$opts | fingerprint
}}
<script
src="{{ .RelPermalink }}"
integrity="{{- .Data.Integrity }}"
crossorigin="anonymous"
></script>
{{- end }} {{- end }} {{- end }}
></script>
{{- end }}
{{- end }}
{{- end }}

View file

@ -1,12 +1,12 @@
{{- /*
Renders a menu for the given menu ID.
Renders a menu for the given menu ID.
@context {page} page The current page.
@context {string} menuID The menu ID.
@context {page} page The current page.
@context {string} menuID The menu ID.
@example: {{ partial "menu.html" (dict "menuID" "main" "page" .) }}
@example: {{ partial "menu.html" (dict "menuID" "main" "page" .)
}}
*/}}
{{- $page := .page }}
{{- $menuID := .menuID }}
@ -24,7 +24,7 @@ Renders a menu for the given menu ID.
{{- $attrs := dict "href" .URL }}
{{- if $page.IsMenuCurrent .Menu . }}
{{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
{{- else if $page.HasMenuCurrent .Menu .}}
{{- else if $page.HasMenuCurrent .Menu . }}
{{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
{{- end }}
{{- $name := .Name }}
@ -40,7 +40,8 @@ Renders a menu for the given menu ID.
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end -}}
>{{ $name }}</a>
>{{ $name }}</a
>
{{- with .Children }}
<ul>
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}

View file

@ -1,13 +1,17 @@
{{- /* For a given taxonomy, renders a list of terms assigned to the page.
@context {page} page The current page. @context {string} taxonomy The taxonony.
@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }} */}} {{-
$page := .page }} {{- $taxonomy := .taxonomy }} {{- with $page.GetTerms
$taxonomy }} {{- $label := (index . 0).Parent.LinkTitle }}
<div class="tags">
@context {page} page The current page. @context {string} taxonomy The taxonony.
@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .)
}}
*/}} {{- $page := .page }} {{- $taxonomy := .taxonomy }}
{{- with $page.GetTerms
$taxonomy
}}
{{- $label := (index . 0).Parent.LinkTitle }}
<div class="tags">
<ul>
{{- range . }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{- end }}
</ul>
</div>
</div>
{{- end }}

View file

@ -1,9 +1,27 @@
{ pkgs, ... }:
{
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
gofmt.enable = true;
taplo.enable = true;
prettier.enable = true;
prettier = {
enable = true;
settings = {
plugins = [
"${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js"
];
overrides = [
{
files = [ "*.html" ];
options.parser = "go-template";
}
];
};
};
};
settings.global.excludes = [
"public/**"
"static/**"
];
}