forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
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 w-full mx-auto rounded bg-white 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 flex justify-between"> 20 <div id="left-side-items" class="p-2 flex gap-2 items-center"> 21 {{ $markerstyle := "diff-type p-1 mr-1 font-mono text-sm rounded select-none" }} 22 23 {{ if .IsNew }} 24 <span class="bg-green-100 text-green-700 {{ $markerstyle }}">ADDED</span> 25 {{ else if .IsDelete }} 26 <span class="bg-red-100 text-red-700 {{ $markerstyle }}">DELETED</span> 27 {{ else if .IsCopy }} 28 <span class="bg-gray-100 text-gray-700 {{ $markerstyle }}">COPIED</span> 29 {{ else if .IsRename }} 30 <span class="bg-gray-100 text-gray-700 {{ $markerstyle }}">RENAMED</span> 31 {{ else }} 32 <span class="bg-gray-100 text-gray-700 {{ $markerstyle }}">MODIFIED</span> 33 {{ end }} 34 35 {{ if .IsDelete }} 36 <a {{if $this }}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.Old }}"{{end}}> 37 {{ .Name.Old }} 38 </a> 39 {{ else if (or .IsCopy .IsRename) }} 40 <a {{if $parent}}href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}"{{end}}> 41 {{ .Name.Old }} 42 </a> 43 <i class="w-4 h-4" data-lucide="arrow-right"></i> 44 <a {{if $this}}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}"{{end}}> 45 {{ .Name.New }} 46 </a> 47 {{ else }} 48 <a {{if $this}}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}"{{end}}> 49 {{ .Name.New }} 50 </a> 51 {{ end }} 52 </div> 53 54 {{ $iconstyle := "p-1 mx-1 hover:bg-gray-100 rounded" }} 55 <div id="right-side-items" class="p-2 flex items-center"> 56 <a title="top of file" href="#file-{{ .Name.New }}" class="{{ $iconstyle }}"><i class="w-4 h-4" data-lucide="arrow-up-to-line"></i></a> 57 {{ if gt $idx 0 }} 58 {{ $prev := index $diff (sub $idx 1) }} 59 <a title="previous file" href="#file-{{ $prev.Name.New }}" class="{{ $iconstyle }}"><i class="w-4 h-4" data-lucide="arrow-up"></i></a> 60 {{ end }} 61 62 {{ if lt $idx $last }} 63 {{ $next := index $diff (add $idx 1) }} 64 <a title="next file" href="#file-{{ $next.Name.New }}" class="{{ $iconstyle }}"><i class="w-4 h-4" data-lucide="arrow-down"></i></a> 65 {{ end }} 66 </div> 67 68 </div> 69 </summary> 70 71 <div class="transition-all duration-700 ease-in-out"> 72 {{ if .IsDelete }} 73 <p class="text-center text-gray-400 p-4"> 74 This file has been deleted in this commit. 75 </p> 76 {{ else }} 77 {{ if .IsBinary }} 78 <p class="text-center text-gray-400 p-4"> 79 This is a binary file and will not be displayed. 80 </p> 81 {{ else }} 82 <pre class="overflow-auto"> 83 {{- range .TextFragments -}} 84 <div class="bg-gray-100 text-gray-500 select-none">{{ .Header }}</div> 85 {{- range .Lines -}} 86 {{- if eq .Op.String "+" -}} 87 <div class="bg-green-100 text-green-700 p-1"><span class="select-none mx-2">{{ .Op.String }}</span><span>{{ .Line }}</span></div> 88 {{- end -}} 89 90 {{- if eq .Op.String "-" -}} 91 <div class="bg-red-100 text-red-700 p-1"><span class="select-none mx-2">{{ .Op.String }}</span><span>{{ .Line }}</span></div> 92 {{- end -}} 93 94 {{- if eq .Op.String " " -}} 95 <div class="bg-white text-gray-500 px"><span class="select-none mx-2">{{ .Op.String }}</span><span>{{ .Line }}</span></div> 96 {{- end -}} 97 98 {{- end -}} 99 {{- end -}} 100 </pre> 101 {{- end -}} 102 {{ end }} 103 </div> 104 105 </details> 106 107 </div> 108 </div> 109 </section> 110 {{ end }} 111 {{ end }} 112{{ end }}