flake: add treefmt, reorganize flake, format using treefmt

This commit is contained in:
Jan Kremer 2024-07-02 20:29:39 +02:00
parent 967b613d91
commit 12aa7125b5
No known key found for this signature in database
17 changed files with 187 additions and 123 deletions

View file

@ -32,17 +32,13 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: DeterminateSystems/flake-checker-action@main
- name: Build with Hugo
run: |
nix develop --command bash -c "hugo \
--environment production \
--minify \
--baseURL '${{ steps.pages.outputs.base_url }}/'"
run: nix run .
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@main
with:
path: ./public
- name: Upload to Netim FTP
uses: SamKirkland/FTP-Deploy-Action@main
uses: SamKirkland/FTP-Deploy-Action@master
with:
server: ftp.netim.hosting
username: AS12798_FTP1

View file

@ -1,6 +1,6 @@
---
title: {{ replace .Name "-" " " | title }}
date: {{ .Date }}
title: { { replace .Name "-" " " | title } }
date: { { .Date } }
description:
tags:
draft: true

View file

@ -1,5 +1,5 @@
---
title: {{ replace .Name "-" " " | title }}
date: {{ .Date }}
title: { { replace .Name "-" " " | title } }
date: { { .Date } }
draft: true
---

View file

@ -1,6 +1,6 @@
---
title: {{ replace .Name "-" " " | title }}
date: {{ .Date }}
title: { { replace .Name "-" " " | title } }
date: { { .Date } }
tags:
- micro
draft: true

View file

@ -1,6 +1,6 @@
---
title: {{ replace .Name "-" " " | title }}
date: {{ .Date }}
title: { { replace .Name "-" " " | title } }
date: { { .Date } }
description:
feature:
tags:

View file

@ -39,7 +39,9 @@ code {
body {
color: var(--text);
background: var(--background);
font-family: "EB Garamond", Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Athelas, Georgia, serif;
font-family: "EB Garamond", Constantia, "Lucida Bright", Lucidabright,
"Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif",
"Liberation Serif", Athelas, Georgia, serif;
/* font-family: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir, "Nimbus Sans L", Roboto, Noto, "Segoe UI", Arial, Helvetica, "Helvetica Neue", sans-serif; */
font-variant-numeric: oldstyle-nums;
line-height: 1.5;
@ -54,9 +56,7 @@ header {
margin-bottom: 1rem;
& nav {
& ul {
font-size: 1.25rem;
list-style: none;
display: flex;
@ -66,7 +66,6 @@ header {
.active {
text-decoration: underline;
}
}
}
}
@ -78,7 +77,7 @@ p {
text-justify: inter-word;
}
article>p:nth-of-type(2)::first-letter {
article > p:nth-of-type(2)::first-letter {
font-size: 3rem;
float: left;
line-height: 2.9rem;
@ -166,7 +165,6 @@ footer {
text-align: left;
text-decoration: none;
}
}
.tags {

52
flake.lock generated
View file

@ -16,9 +16,59 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1719690277,
"narHash": "sha256-0xSej1g7eP2kaUF+JQp8jdyNmpmCJKRpO12mKl/36Kc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2741b4b489b55df32afac57bc4bfd220e8bf617e",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt": "treefmt"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"id": "systems",
"type": "indirect"
}
},
"treefmt": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1719887753,
"narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},

View file

@ -1,36 +1,64 @@
{
description = "Hugo website";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.treefmt.url = "github:numtide/treefmt-nix";
outputs =
{ nixpkgs, ... }:
{
self,
nixpkgs,
systems,
treefmt,
...
}:
let
systems = [
"x86_64-linux"
"x86_64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs (systems) f;
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
devShell =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default =
with pkgs;
mkShell {
name = "Hugo website";
packages = with pkgs; [
go
hugo
nodePackages.prettier
];
};
};
treefmtEval = eachSystem (pkgs: treefmt.lib.evalModule pkgs ./treefmt.nix);
in
{
devShells = forAllSystems devShell;
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
buildInputs = with pkgs; [
go
hugo
];
};
});
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
checks = eachSystem (pkgs: {
formatting = treefmtEval.${pkgs.system}.config.build.check self;
});
apps = eachSystem (pkgs: {
default = {
type = "app";
program =
(pkgs.writeShellScript "build-website" ''
set -e
${pkgs.hugo}/bin/hugo --minify
'').outPath;
};
test = {
type = "app";
program =
(pkgs.writeShellScript "test-website" ''
set -e
${pkgs.hugo}/bin/hugo --environment="development"
'').outPath;
};
server = {
type = "app";
program =
(pkgs.writeShellScript "serve-website" ''
set -e
${pkgs.hugo}/bin/hugo server
'').outPath;
};
});
};
}

View file

@ -1,21 +1,15 @@
<!DOCTYPE html>
<html lang="{{ or site.Language.LanguageCode site.Language.Lang }}"
dir="{{ or site.Language.LanguageDirection `ltr` }}">
<head>
{{ partial "head.html" . }}
</head>
<body>
<header>
{{ partial "header.html" . }}
</header>
<main>
{{ block "main" . }}{{ end }}
</main>
<footer>
{{ partial "footer.html" . }}
</footer>
</body>
<!doctype html>
<html
lang="{{ or site.Language.LanguageCode site.Language.Lang }}"
dir="{{ or site.Language.LanguageDirection `ltr` }}"
>
<head>
{{ partial "head.html" . }}
</head>
<body>
<header>{{ partial "header.html" . }}</header>
<main>{{ block "main" . }}{{ end }}</main>
<footer>{{ partial "footer.html" . }}</footer>
</body>
</html>

View file

@ -1,11 +1,9 @@
{{ 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>
@ -13,5 +11,4 @@
<p class="lead">{{ .Description }}</p>
</div>
</a>
{{ end }}
{{ end }}
{{ end }} {{ end }}

View file

@ -1,10 +1,8 @@
{{ 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>
@ -12,5 +10,4 @@
<p class="lead">{{ .Description }}</p>
</div>
</a>
{{ end }}
{{ end }}
{{ end }} {{ end }}

View file

@ -1,9 +1,9 @@
{{ define "main" }}
<article>
{{ $dateMachine := .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }}
{{ $dateHuman := .Lastmod | time.Format "2006-01-02" }}
{{ $dateMachine := .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }} {{
$dateHuman := .Lastmod | time.Format "2006-01-02" }}
<time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
<br>
<br />
<h1>{{ .Title }}</h1>
@ -11,5 +11,4 @@
{{ .Content }}
</article>
{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
{{ end }}
{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }} {{ end }}

View file

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

View file

@ -1,9 +1,11 @@
{{- 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 }}
{{- 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 }}

View file

@ -1,12 +1,11 @@
{{- 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 }}
{{- 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 }}

View file

@ -1,17 +1,8 @@
{{- /*
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 }}
{{- /* 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">
<ul>
{{- range . }}

9
treefmt.nix Normal file
View file

@ -0,0 +1,9 @@
{
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
gofmt.enable = true;
taplo.enable = true;
prettier.enable = true;
};
}