diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index cb89ff4..1a8d4a8 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -4,6 +4,8 @@ import ( "fmt" "html" "html/template" + "log" + "path/filepath" "reflect" "strings" @@ -119,5 +121,39 @@ func funcMap() template.FuncMap { "list": func(args ...any) []any { return args }, + "i": func(name string, classes ...string) template.HTML { + data, err := icon(name, classes) + if err != nil { + log.Printf("icon %s does not exist", name) + data, _ = icon("airplay", classes) + } + return template.HTML(data) + }, } } + +func icon(name string, classes []string) (template.HTML, error) { + iconPath := filepath.Join("static", "icons", name) + + if filepath.Ext(name) == "" { + iconPath += ".svg" + } + + data, err := Files.ReadFile(iconPath) + if err != nil { + return "", fmt.Errorf("icon %s not found: %w", name, err) + } + + // Convert SVG data to string + svgStr := string(data) + + svgTagEnd := strings.Index(svgStr, ">") + if svgTagEnd == -1 { + return "", fmt.Errorf("invalid SVG format for icon %s", name) + } + + classTag := ` class="` + strings.Join(classes, " ") + `"` + + modifiedSVG := svgStr[:svgTagEnd] + classTag + svgStr[svgTagEnd:] + return template.HTML(modifiedSVG), nil +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index b5542e0..8e2a580 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -25,8 +25,8 @@ import ( "github.com/sotangled/tangled/types" ) -//go:embed templates/* static/* -var files embed.FS +//go:embed templates/* static +var Files embed.FS type Pages struct { t map[string]*template.Template @@ -36,7 +36,7 @@ func NewPages() *Pages { templates := make(map[string]*template.Template) // Walk through embedded templates directory and parse all .html files - err := fs.WalkDir(files, "templates", func(path string, d fs.DirEntry, err error) error { + err := fs.WalkDir(Files, "templates", func(path string, d fs.DirEntry, err error) error { if err != nil { return err } @@ -49,7 +49,7 @@ func NewPages() *Pages { if strings.HasPrefix(path, "templates/fragments/") { tmpl, err := template.New(name). Funcs(funcMap()). - ParseFS(files, path) + ParseFS(Files, path) if err != nil { return fmt.Errorf("setting up fragment: %w", err) } @@ -64,7 +64,7 @@ func NewPages() *Pages { // Add the page template on top of the base tmpl, err := template.New(name). Funcs(funcMap()). - ParseFS(files, "templates/layouts/*.html", "templates/fragments/*.html", path) + ParseFS(Files, "templates/layouts/*.html", "templates/fragments/*.html", path) if err != nil { return fmt.Errorf("setting up template: %w", err) } @@ -577,7 +577,7 @@ func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error } func (p *Pages) Static() http.Handler { - sub, err := fs.Sub(files, "static") + sub, err := fs.Sub(Files, "static") if err != nil { log.Fatalf("no static dir found? that's crazy: %v", err) } diff --git a/appview/pages/static/.gitkeep b/appview/pages/static/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/appview/pages/templates/fragments/diff.html b/appview/pages/templates/fragments/diff.html index 51b5cc1..47257a4 100644 --- a/appview/pages/templates/fragments/diff.html +++ b/appview/pages/templates/fragments/diff.html @@ -40,7 +40,7 @@ {{ .Name.Old }} - + {{ i "arrow-right" "w-4 h-4" }} {{ .Name.New }} @@ -53,15 +53,15 @@ {{ $iconstyle := "p-1 mx-1 hover:bg-gray-100 rounded" }}
- + {{ i "arrow-up-to-line" "w-4 h-4" }} {{ if gt $idx 0 }} {{ $prev := index $diff (sub $idx 1) }} - + {{ i "arrow-up" "w-4 h-4" }} {{ end }} {{ if lt $idx $last }} {{ $next := index $diff (add $idx 1) }} - + {{ i "arrow-down" "w-4 h-4" }} {{ end }}
diff --git a/appview/pages/templates/fragments/editRepoDescription.html b/appview/pages/templates/fragments/editRepoDescription.html index 9e00468..20e3465 100644 --- a/appview/pages/templates/fragments/editRepoDescription.html +++ b/appview/pages/templates/fragments/editRepoDescription.html @@ -1,11 +1,11 @@ {{ define "fragments/editRepoDescription" }} -
- - -
{{ end }} diff --git a/appview/pages/templates/fragments/repoDescription.html b/appview/pages/templates/fragments/repoDescription.html index 3b7ee06..0ae3acd 100644 --- a/appview/pages/templates/fragments/repoDescription.html +++ b/appview/pages/templates/fragments/repoDescription.html @@ -1,5 +1,5 @@ {{ define "fragments/repoDescription" }} - + {{ if .RepoInfo.Description }} {{ .RepoInfo.Description }} {{ else }} @@ -7,8 +7,9 @@ {{ end }} {{ if .RepoInfo.Roles.IsOwner }} - {{ end }} diff --git a/appview/pages/templates/fragments/star.html b/appview/pages/templates/fragments/star.html index 4af3545..c2635e2 100644 --- a/appview/pages/templates/fragments/star.html +++ b/appview/pages/templates/fragments/star.html @@ -15,19 +15,14 @@ >
{{ if .IsStarred }} - + {{ i "star" "w-3 h-3 fill-current" }} {{ else }} - + {{ i "star" "w-3 h-3" }} {{ end }} {{ .Stats.StarCount }}
- {{ end }} diff --git a/appview/pages/templates/layouts/base.html b/appview/pages/templates/layouts/base.html index 4b0c93b..b9c3bdf 100644 --- a/appview/pages/templates/layouts/base.html +++ b/appview/pages/templates/layouts/base.html @@ -24,10 +24,6 @@ {{ template "layouts/footer" . }} {{ end }} - - diff --git a/appview/pages/templates/layouts/topbar.html b/appview/pages/templates/layouts/topbar.html index 20eadf3..3d30a73 100644 --- a/appview/pages/templates/layouts/topbar.html +++ b/appview/pages/templates/layouts/topbar.html @@ -9,7 +9,7 @@
{{ with .LoggedInUser }} - + {{ i "plus" "w-6 h-6" }} {{ block "dropDown" . }} {{ end }} {{ else }} diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html index ffde4a0..ae9188b 100644 --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -37,7 +37,7 @@

{{ slice $commit.This 0 8 }} {{ if $commit.Parent }} - + {{ i "arrow-left" "w-3 h-3 mx-1" }} {{ slice $commit.Parent 0 8 }} {{ end }}

diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html index d4b4c0c..59d183e 100644 --- a/appview/pages/templates/repo/index.html +++ b/appview/pages/templates/repo/index.html @@ -49,7 +49,7 @@ href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}" class="ml-2 no-underline flex items-center gap-2 text-sm uppercase font-bold" > - + {{ i "logs" "w-4 h-4" }} {{ .TotalCommits }} {{ if eq .TotalCommits 1 }}commit{{ else }}commits{{ end }} @@ -70,11 +70,8 @@ class="{{ $linkstyle }}" >
- {{ .Name }} + {{ i "folder" "w-3 h-3 fill-current" }} + {{ .Name }}
@@ -95,11 +92,7 @@ class="{{ $linkstyle }}" >
- {{ .Name }} + {{ i "file" "w-3 h-3" }}{{ .Name }}
@@ -134,10 +127,7 @@ class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded" hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')" > - + {{ i "ellipsis" "w-3 h-3" }} {{ end }}
@@ -182,7 +172,7 @@ > {{ end }} {{ range $tagsForCommit }} - + {{ . }} {{ end }} diff --git a/appview/pages/templates/repo/issues/issue.html b/appview/pages/templates/repo/issues/issue.html index a32d2fb..0076084 100644 --- a/appview/pages/templates/repo/issues/issue.html +++ b/appview/pages/templates/repo/issues/issue.html @@ -19,7 +19,7 @@
- + {{ i $icon "w-4 h-4 mr-1.5 text-white" }} {{ .State }}
@@ -100,10 +100,7 @@ class="mt-8" >
diff --git a/appview/pages/templates/repo/issues/issues.html b/appview/pages/templates/repo/issues/issues.html index c343641..777e351 100644 --- a/appview/pages/templates/repo/issues/issues.html +++ b/appview/pages/templates/repo/issues/issues.html @@ -13,7 +13,7 @@ - + {{ i "plus" "w-4 h-4" }} new issue
@@ -44,7 +44,7 @@ {{ end }} - + {{ i $icon "w-3 h-3 mr-1.5 text-white" }} {{ $state }} diff --git a/appview/pages/templates/repo/log.html b/appview/pages/templates/repo/log.html index 1e07ab5..a1639d8 100644 --- a/appview/pages/templates/repo/log.html +++ b/appview/pages/templates/repo/log.html @@ -75,10 +75,7 @@ class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded" hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')" > - + {{ i "ellipsis" "w-3 h-3" }} {{ end }} @@ -138,7 +135,7 @@ hx-boost="true" onclick="window.location.href = window.location.pathname + '?page={{ sub .Page 1 }}'" > - + {{ i "chevron-left" "w-4 h-4" }} previous {{ else }} @@ -152,7 +149,7 @@ onclick="window.location.href = window.location.pathname + '?page={{ add .Page 1 }}'" > next - + {{ i "chevron-right" "w-4 h-4" }} {{ end }} diff --git a/appview/pages/templates/repo/pulls/patch.html b/appview/pages/templates/repo/pulls/patch.html index 4090907..2f05c22 100644 --- a/appview/pages/templates/repo/pulls/patch.html +++ b/appview/pages/templates/repo/pulls/patch.html @@ -10,7 +10,7 @@
- + {{ i "arrow-left" "w-5 h-5" }} back @@ -40,10 +40,7 @@ id="state" class="inline-flex items-center rounded px-3 py-1 {{ $bgColor }}" > - + {{ i $icon "w-4 h-4 mr-1.5 text-white" }} {{ .Pull.State.String }}
diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html index 284ad85..578085c 100644 --- a/appview/pages/templates/repo/pulls/pull.html +++ b/appview/pages/templates/repo/pulls/pull.html @@ -27,10 +27,7 @@ id="state" class="inline-flex items-center rounded px-3 py-1 {{ $bgColor }}" > - + {{ i $icon "w-4 h-4 mr-1.5 text-white" }} {{ .Pull.State.String }} @@ -139,7 +136,7 @@
- + {{ i "git-merge" "w-4 h-4" }} pull request successfully merged
@@ -148,16 +145,13 @@
- + {{ i "triangle-alert" "w-4 h-4" }} merge conflicts detected
    {{ range .MergeCheck.Conflicts }} {{ if .Filename }}
  • - + {{ i "file-warning" "w-3 h-3 mr-1.5 text-red-500" }} {{ slice .Filename 0 (sub (len .Filename) 2) }}
  • {{ end }} @@ -169,7 +163,7 @@
    - + {{ i "circle-check-big" "w-4 h-4" }} no conflicts, ready to merge
    @@ -191,7 +185,7 @@
    {{ if and $isPushAllowed $isOpen }} @@ -199,29 +193,39 @@ {{ if $isConflicted }} {{ $disabled = "disabled" }} {{ end }} - {{ end }} {{ if and $isPullAuthor $isOpen }} {{ end }} {{ if and $isPullAuthor $isPushAllowed $isOpen }} - {{ end }} {{ if and $isPullAuthor $isPushAllowed $isClosed }} - {{ end }} @@ -270,7 +274,7 @@ class="rounded relative bg-purple-50 border border-purple-200 p-4">
    - + {{ i "git-merge" "w-4 h-4" }} pull request successfully merged diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html index 9b56102..ae9d2d6 100644 --- a/appview/pages/templates/repo/pulls/pulls.html +++ b/appview/pages/templates/repo/pulls/pulls.html @@ -24,7 +24,7 @@ href="/{{ .RepoInfo.FullName }}/pulls/new" class="btn text-sm flex items-center gap-2 no-underline hover:no-underline" > - + {{ i "git-pull-request" "w-4 h-4" }} new pull request
    @@ -57,10 +57,7 @@ - + {{ i $icon "w-3 h-3 mr-1.5 text-white" }} {{ .State.String }} diff --git a/appview/pages/templates/repo/tree.html b/appview/pages/templates/repo/tree.html index b1c48cc..9d5214a 100644 --- a/appview/pages/templates/repo/tree.html +++ b/appview/pages/templates/repo/tree.html @@ -41,7 +41,7 @@
    - {{ .Name }} + {{ i "folder" "w-3 h-3 fill-current" }}{{ .Name }}
    @@ -56,7 +56,7 @@
    - {{ .Name }} + {{ i "file" "w-3 h-3" }}{{ .Name }}
    diff --git a/appview/pages/templates/settings.html b/appview/pages/templates/settings.html index bd71da3..15eada1 100644 --- a/appview/pages/templates/settings.html +++ b/appview/pages/templates/settings.html @@ -36,7 +36,7 @@
    - + {{ i "key" "w-3 h-3" }}

    {{ .Name }}

    added {{ .Created | timeFmt }}

    @@ -48,8 +48,8 @@ class="btn text-red-500 hover:text-red-700" title="Delete key" hx-delete="/settings/keys?name={{urlquery .Name}}&rkey={{urlquery .Rkey}}&key={{urlquery .Key}}" - hx-confirm="Are you sure you wish to delete the key '{{ .Name }}'?"> - + hx-confirm="Are you sure you want to delete the key '{{ .Name }}'?"> + {{ i "trash-2" "w-5 h-5" }}
    @@ -91,7 +91,7 @@
    - + {{ i "mail" "w-3 h-3" }}

    {{ .Address }}

    {{ if .Verified }} @@ -114,7 +114,7 @@ hx-swap="none" href="#" hx-vals='{"email": "{{ .Address }}"}'> - + {{ i "rotate-cw" "w-5 h-5" }} {{ end }} @@ -135,7 +135,7 @@ class="btn text-red-500 hover:text-red-700" title="Delete email" type="submit"> - + {{ i "trash-2" "w-5 h-5" }} diff --git a/appview/pages/templates/timeline.html b/appview/pages/templates/timeline.html index fa500cf..63f1eef 100644 --- a/appview/pages/templates/timeline.html +++ b/appview/pages/templates/timeline.html @@ -22,7 +22,7 @@ tangled
    - tightly-knit social coding, join now + tightly-knit social coding, join now {{ i "arrow-right" "w-4 h-4" }}

    Join our IRC channel: #tangled on Libera Chat. Read an introduction to Tangled here.

    diff --git a/appview/pages/templates/user/profile.html b/appview/pages/templates/user/profile.html index 6d81496..ac59c0a 100644 --- a/appview/pages/templates/user/profile.html +++ b/appview/pages/templates/user/profile.html @@ -62,10 +62,7 @@ {{ if .RepoStats.StarCount }}
    - + {{ i "star" "w-3 h-3 fill-current" }} {{ .RepoStats.StarCount }}
    {{ end }} @@ -100,10 +97,7 @@ {{ if .RepoStats.StarCount }}
    - + {{ i "star" "w-3 h-3 fill-current" }} {{ .RepoStats.StarCount }}
    {{ end }} diff --git a/appview/state/pull.go b/appview/state/pull.go index dc9094b..218801f 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -94,8 +94,6 @@ func (s *State) RepoSinglePull(w http.ResponseWriter, r *http.Request) { } } - log.Println(mergeCheckResponse) - s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ LoggedInUser: user, RepoInfo: f.RepoInfo(s, user), diff --git a/flake.lock b/flake.lock index 331a4bc..e10b5b6 100644 --- a/flake.lock +++ b/flake.lock @@ -67,13 +67,14 @@ "lucide-src": { "flake": false, "locked": { - "narHash": "sha256-5ipNSxTlQ7627lGgsyZxk7vS1sr9RkrlR8/QMj2Zg6s=", - "type": "file", - "url": "https://unpkg.com/lucide@0.482.0" + "lastModified": 1742302029, + "narHash": "sha256-OyPVtpnC4/AAmPq84Wt1r1Gcs48d9KG+UBCtZK87e9k=", + "type": "tarball", + "url": "https://github.com/lucide-icons/lucide/releases/download/0.483.0/lucide-icons-0.483.0.zip" }, "original": { - "type": "file", - "url": "https://unpkg.com/lucide@0.482.0" + "type": "tarball", + "url": "https://github.com/lucide-icons/lucide/releases/download/0.483.0/lucide-icons-0.483.0.zip" } }, "nixpkgs": { diff --git a/flake.nix b/flake.nix index 9e8ff3e..637929e 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,7 @@ flake = false; }; lucide-src = { - url = "https://unpkg.com/lucide@0.482.0"; + url = "https://github.com/lucide-icons/lucide/releases/download/0.483.0/lucide-icons-0.483.0.zip"; flake = false; }; ia-fonts-src = { @@ -71,9 +71,9 @@ src = gitignoreSource ./.; postUnpack = '' pushd source + mkdir -p appview/pages/static/{fonts,icons} cp -f ${htmx-src} appview/pages/static/htmx.min.js - cp -f ${lucide-src} appview/pages/static/lucide.min.js - mkdir -p appview/pages/static/fonts + cp -rf ${lucide-src}/*.svg appview/pages/static/icons/ cp -f ${ia-fonts-src}/"iA Writer Quattro"/Static/*.ttf appview/pages/static/fonts/ cp -f ${ia-fonts-src}/"iA Writer Mono"/Static/*.ttf appview/pages/static/fonts/ ${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css @@ -150,9 +150,9 @@ pkgs.nixos-shell ]; shellHook = '' + mkdir -p appview/pages/static/{fonts,icons} cp -f ${htmx-src} appview/pages/static/htmx.min.js - cp -f ${lucide-src} appview/pages/static/lucide.min.js - mkdir -p appview/pages/static/fonts/ + cp -rf ${lucide-src}/*.svg appview/pages/static/icons/ cp -f ${ia-fonts-src}/"iA Writer Quattro"/Static/*.ttf appview/pages/static/fonts/ cp -f ${ia-fonts-src}/"iA Writer Mono"/Static/*.ttf appview/pages/static/fonts/ '';