forked from tangled.org/core
this repo has no description
at fork-repo 5.7 kB view raw
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"> 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 dark:bg-green-800/50 dark:text-green-400 {{ $markerstyle }}">ADDED</span> 25 {{ else if .IsDelete }} 26 <span class="bg-red-100 text-red-700 dark:bg-red-800/50 dark:text-red-400 {{ $markerstyle }}">DELETED</span> 27 {{ else if .IsCopy }} 28 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">COPIED</span> 29 {{ else if .IsRename }} 30 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">RENAMED</span> 31 {{ else }} 32 <span class="bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300 {{ $markerstyle }}">MODIFIED</span> 33 {{ end }} 34 35 {{ if .IsDelete }} 36 <a class="dark:text-white" {{if $this }}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.Old }}"{{end}}> 37 {{ .Name.Old }} 38 </a> 39 {{ else if (or .IsCopy .IsRename) }} 40 <a class="dark:text-white" {{if $parent}}href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}"{{end}}> 41 {{ .Name.Old }} 42 </a> 43 {{ i "arrow-right" "w-4 h-4" }} 44 <a class="dark:text-white" {{if $this}}href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}"{{end}}> 45 {{ .Name.New }} 46 </a> 47 {{ else }} 48 <a class="dark:text-white" {{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 dark:hover:bg-gray-700 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 "arrow-up-to-line" "w-4 h-4" }}</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 "arrow-up" "w-4 h-4" }}</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 "arrow-down" "w-4 h-4" }}</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 dark:text-gray-500 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 dark:text-gray-500 p-4"> 79 This is a binary file and will not be displayed. 80 </p> 81 {{ else }} 82 <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 -}} 83 {{- if eq .Op.String "+" -}} 84 <div class="bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 flex min-w-full"> 85 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div> 86 <div class="p-1 whitespace-pre">{{ .Line }}</div> 87 </div> 88 {{- end -}} 89 {{- if eq .Op.String "-" -}} 90 <div class="bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 flex min-w-full"> 91 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div> 92 <div class="p-1 whitespace-pre">{{ .Line }}</div> 93 </div> 94 {{- end -}} 95 {{- if eq .Op.String " " -}} 96 <div class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex min-w-full"> 97 <div class="w-10 flex-shrink-0 select-none p-1 text-center">{{ .Op.String }}</div> 98 <div class="p-1 whitespace-pre">{{ .Line }}</div> 99 </div> 100 {{- end -}} 101 {{- end -}} 102 {{- end -}}</div></div></pre> 103 {{- end -}} 104 {{ end }} 105 </div> 106 107 </details> 108 109 </div> 110 </div> 111 </section> 112 {{ end }} 113 {{ end }} 114{{ end }}