summaryrefslogtreecommitdiff
path: root/internal/templates/compare.gohtml
blob: d26be6df0a7049675fb9361a4284086b21881b60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{{- /*gotype: mokhan.ca/xlgmokha/gitmal/internal/templates.CompareParams*/ -}}
{{- define "head" -}}
<style>
  h1 code {
    border-radius: var(--border-radius);
    background: var(--c-bg-alt);
    padding: 4px 8px;
    font-family: var(--font-family-mono), monospace;
    font-weight: 500;
  }
  .compare-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
  }
  .compare-refs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  .ref-badge {
    color: var(--c-text-1);
    border: 1px solid var(--c-border);
    border-radius: 6px;
    padding: 6px 12px;
    font-family: var(--font-family-mono), monospace;
    font-size: 14px;
    background: var(--c-bg-alt);
  }
  .compare-arrow { color: var(--c-text-2); }
  .compare-stats {
    display: flex;
    gap: 16px;
    color: var(--c-text-2);
    font-size: 14px;
  }
  .commits-section { margin-bottom: 24px; }
  .commits-section h2 { font-size: 16px; margin-bottom: 12px; }
  .commits-list {
    border: 1px solid var(--c-border);
    border-radius: var(--border-radius);
    overflow: hidden;
  }
  .commit-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--c-border);
  }
  .commit-row:last-child { border-bottom: none; }
  .commit-row:hover { background-color: var(--c-bg-alt); }
  .commit-hash {
    font-family: var(--font-family-mono), monospace;
    color: var(--c-text-2);
    font-size: 13px;
  }
  .commit-hash a { color: inherit; }
  .commit-subject { flex: 1; min-width: 0; }
  .commit-subject a { color: var(--c-text-1); }
  .commit-subject a:hover { color: var(--c-brand-2); }
  .commit-author { color: var(--c-text-2); font-size: 13px; }
  .commit-date {
    font-family: var(--font-family-mono), monospace;
    font-size: 12px;
    color: var(--c-text-2);
  }
  .compare-layout { display: grid; grid-template-columns: 1fr; gap: 16px; }
  @media (min-width: 960px) {
    .compare-layout { grid-template-columns: 300px 1fr; align-items: start; }
    .files-tree { position: sticky; top: 16px; }
    .files-tree-content { max-height: calc(100vh - var(--header-height) - 40px); overflow: auto; }
  }
  .files-tree { border: 1px solid var(--c-border); border-radius: var(--border-radius); }
  .files-tree-header {
    display: flex;
    align-items: center;
    padding-inline: 16px;
    height: var(--header-height);
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg-alt);
    font-size: 14px;
    font-weight: 600;
  }
  .files-tree-content { padding-block: 6px; }
  .tree .children { margin-left: 16px; border-left: 1px dashed var(--c-border); }
  .tree .node { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
  .tree .file-name { flex: 1; font-weight: 500; color: var(--c-text-1); cursor: pointer; }
  .tree .file-name:hover { color: var(--c-brand-2); text-decoration: underline; }
  .tree .dir { color: var(--c-dir); }
  .tree .file-added { color: var(--c-green); }
  .tree .file-deleted { color: var(--c-red); }
  .tree .file-renamed { color: var(--c-yellow); }
  .files { min-width: 0; }
  .file-section + .file-section { margin-top: 16px; }
  pre {
    border: 1px solid var(--c-border);
    border-top: none;
    border-bottom-left-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
    margin: 0;
    padding: 8px 16px;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
    font-family: var(--font-family-mono), monospace;
  }
  pre > code {
    display: block;
    padding: 0 16px;
    width: fit-content;
    min-width: 100%;
    line-height: var(--code-line-height);
    font-size: var(--code-font-size);
  }
  .binary-file, .no-changes {
    padding: 8px 16px;
    font-style: italic;
    border: 1px solid var(--c-border);
    border-top: none;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
  }
</style>
{{- end}}

{{- define "body" -}}
<div class="compare-header">
  <h1>Comparing changes</h1>
  <div class="compare-refs">
    <span class="ref-badge">{{.Base}}</span>
    <span class="compare-arrow">→</span>
    <span class="ref-badge">{{.Head}}</span>
  </div>
  <div class="compare-stats">
    <span>{{len .Commits}} commits</span>
    <span>{{len .FileViews}} files changed</span>
  </div>
</div>
{{- if .Commits}}
<div class="commits-section">
  <h2>Commits</h2>
  <div class="commits-list">
{{- range .Commits}}
    <div class="commit-row">
      <span class="commit-hash"><a href="{{.Href}}">{{.ShortHash}}</a></span>
      <span class="commit-subject"><a href="{{.Href}}">{{.Subject}}</a></span>
      <span class="commit-author">{{.Author}}</span>
      <span class="commit-date">{{.Date | FormatDate}}</span>
    </div>
{{- end}}
  </div>
</div>
{{- end}}
<div class="compare-layout">
  <div class="files-tree">
    <div class="files-tree-header">Changed files ({{len .FileViews}})</div>
    <div class="files-tree-content">
{{- if .FileTree}}
      <div class="tree">{{- template "file_tree" (FileTreeParams .FileTree)}}</div>
{{- else}}
      <div style="color: var(--c-text-3)">(no files changed)</div>
{{- end}}
    </div>
  </div>
  <div class="files">
{{- range .FileViews}}
    <section id="{{.Path}}" class="file-section">
      <header class="file-header">
{{- if .IsRename}}
        <div class="path">{{.OldName}} → {{.NewName}}</div>
{{- else}}
        <div class="path">{{.Path}}</div>
{{- end}}
      </header>
{{- if .IsBinary}}
      <div class="binary-file">Binary file</div>
{{- else if (and .IsRename (not .HasChanges))}}
      <div class="no-changes">File renamed without changes</div>
{{- else}}
      <div class="file-diff">{{.HTML}}</div>
{{- end}}
    </section>
{{- end}}
  </div>
</div>
{{- end}}