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