1{{ define "fragments/diff" }}
2{{ $repo := index . 0 }}
3{{ $diff := index . 1 }}
4{{ $commit := $diff.Commit }}
5{{ $stat := $diff.Stat }}
6{{ $diff := $diff.Diff }}
7
8 {{ $this := $commit.This }}
9 {{ $parent := $commit.Parent }}
10
11 {{ $last := sub (len $diff) 1 }}
12 {{ range $idx, $hunk := $diff }}
13 {{ with $hunk }}
14 <section class="mt-6 border border-gray-200 dark:border-gray-700 w-full mx-auto rounded bg-white dark:bg-gray-800 drop-shadow-sm">
15 <div id="file-{{ .Name.New }}">
16 <div id="diff-file">
17 <details open>
18 <summary class="list-none cursor-pointer sticky top-0">
19 <div id="diff-file-header" class="rounded cursor-pointer bg-white dark:bg-gray-800 flex justify-between">
20 <div id="left-side-items" class="p-2 flex gap-2 items-center overflow-x-auto" style="direction: rtl;">
21 {{ $markerstyle := "diff-type p-1 mr-1 font-mono text-sm rounded select-none" }}
22
23 <div class="flex gap-2 items-center" style="direction: ltr;">
24 {{ if .IsNew }}
25 <span class="bg-green-100 text-green-700 dark:bg-green-800/50 dark:text-green-400 {{ $markerstyle }}">ADDED</span>
26 {{ else if .IsDelete }}
27 <span class="bg-red-100 text-red-700 dark:bg-red-800/50 dark:text-red-400 {{ $markerstyle }}">DELETED</span>
28 {{ else if .IsCopy }}
29 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">COPIED</span>
30 {{ else if .IsRename }}
31 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">RENAMED</span>
32 {{ else }}
33 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">MODIFIED</span>
34 {{ end }}
35
36 {{ if .IsDelete }}
37 <a class="dark:text-white whitespace-nowrap overflow-x-auto" {{if $this }}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.Old }}"{{end}}>
38 {{ .Name.Old }}
39 </a>
40 {{ else if (or .IsCopy .IsRename) }}
41 <a class="dark:text-white whitespace-nowrap overflow-x-auto" {{if $parent}}href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}"{{end}}>
42 {{ .Name.Old }}
43 </a>
44 {{ i "arrow-right" "w-4 h-4" }}
45 <a class="dark:text-white whitespace-nowrap overflow-x-auto" {{if $this}}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}"{{end}}>
46 {{ .Name.New }}
47 </a>
48 {{ else }}
49 <a class="dark:text-white whitespace-nowrap overflow-x-auto" {{if $this}}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}"{{end}}>
50 {{ .Name.New }}
51 </a>
52 {{ end }}
53 </div>
54 </div>
55
56 {{ $iconstyle := "p-1 mx-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded" }}
57 <div id="right-side-items" class="p-2 flex items-center">
58 <a title="top of file" href="#file-{{ .Name.New }}" class="{{ $iconstyle }}">{{ i "arrow-up-to-line" "w-4 h-4" }}</a>
59 {{ if gt $idx 0 }}
60 {{ $prev := index $diff (sub $idx 1) }}
61 <a title="previous file" href="#file-{{ $prev.Name.New }}" class="{{ $iconstyle }}">{{ i "arrow-up" "w-4 h-4" }}</a>
62 {{ end }}
63
64 {{ if lt $idx $last }}
65 {{ $next := index $diff (add $idx 1) }}
66 <a title="next file" href="#file-{{ $next.Name.New }}" class="{{ $iconstyle }}">{{ i "arrow-down" "w-4 h-4" }}</a>
67 {{ end }}
68 </div>
69
70 </div>
71 </summary>
72
73 <div class="transition-all duration-700 ease-in-out">
74 {{ if .IsDelete }}
75 <p class="text-center text-gray-400 dark:text-gray-500 p-4">
76 This file has been deleted in this commit.
77 </p>
78 {{ else }}
79 {{ if .IsBinary }}
80 <p class="text-center text-gray-400 dark:text-gray-500 p-4">
81 This is a binary file and will not be displayed.
82 </p>
83 {{ else }}
84 <pre class="overflow-x-auto"><div class="overflow-x-auto"><div class="min-w-full inline-block">{{- range .TextFragments -}}<div class="bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 select-none">{{- .Header -}}</div>{{- range .Lines -}}
85 {{- if eq .Op.String "+" -}}
86 <div class="bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 flex min-w-full">
87 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div>
88 <div class="p-1 whitespace-pre">{{ .Line }}</div>
89 </div>
90 {{- end -}}
91 {{- if eq .Op.String "-" -}}
92 <div class="bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 flex min-w-full">
93 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div>
94 <div class="p-1 whitespace-pre">{{ .Line }}</div>
95 </div>
96 {{- end -}}
97 {{- if eq .Op.String " " -}}
98 <div class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex min-w-full">
99 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div>
100 <div class="p-1 whitespace-pre">{{ .Line }}</div>
101 </div>
102 {{- end -}}
103 {{- end -}}
104 {{- end -}}</div></div></pre>
105 {{- end -}}
106 {{ end }}
107 </div>
108
109 </details>
110
111 </div>
112 </div>
113 </section>
114 {{ end }}
115 {{ end }}
116{{ end }}