appview/pages: Strip HTTP port from SSH clone URLs #749

merged
opened by evan.jarrett.net targeting master from evan.jarrett.net/core: ssh-strip-port

Summary#

Fixes SSH clone URL display to show correct format without HTTP API port.

SSH URLs were displaying with the HTTP API port:

git@localhost:6000:evan.jarrett.net/atcr-test

Strip the HTTP port from hostnames in SSH URL so that it becomes:

git@localhost:evan.jarrett.net/atcr-test

Note: even better would be if we knew what port the knot was listening on and add that to the url.

Changes#

  • Added stripPort template helper function to appview/pages/funcmap.go
  • Updated appview/pages/templates/repo/empty.html to use stripPort filter
  • Updated appview/pages/templates/repo/fragments/cloneDropdown.html to use stripPort filter
Changed files
+9 -3
appview
pages
templates
+6
appview/pages/funcmap.go
···
"contains": func(s string, target string) bool {
return strings.Contains(s, target)
},
"mapContains": func(m any, key any) bool {
mapValue := reflect.ValueOf(m)
if mapValue.Kind() != reflect.Map {
···
"contains": func(s string, target string) bool {
return strings.Contains(s, target)
},
+
"stripPort": func(hostname string) string {
+
if strings.Contains(hostname, ":") {
+
return strings.Split(hostname, ":")[0]
+
}
+
return hostname
+
},
"mapContains": func(m any, key any) bool {
mapValue := reflect.ValueOf(m)
if mapValue.Kind() != reflect.Map {
+1 -1
appview/pages/templates/repo/empty.html
···
<p><span class="{{$bullet}}">1</span>First, generate a new <a href="https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key" class="underline">SSH key pair</a>.</p>
<p><span class="{{$bullet}}">2</span>Then add the public key to your account from the <a href="/settings" class="underline">settings</a> page.</p>
-
<p><span class="{{$bullet}}">3</span>Configure your remote to <code>git@{{ $knot }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}</code></p>
<p><span class="{{$bullet}}">4</span>Push!</p>
</div>
</div>
···
<p><span class="{{$bullet}}">1</span>First, generate a new <a href="https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key" class="underline">SSH key pair</a>.</p>
<p><span class="{{$bullet}}">2</span>Then add the public key to your account from the <a href="/settings" class="underline">settings</a> page.</p>
+
<p><span class="{{$bullet}}">3</span>Configure your remote to <code>git@{{ $knot | stripPort }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}</code></p>
<p><span class="{{$bullet}}">4</span>Push!</p>
</div>
</div>
+2 -2
appview/pages/templates/repo/fragments/cloneDropdown.html
···
<code
class="flex-1 px-3 py-2 text-sm bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-l select-all cursor-pointer whitespace-nowrap overflow-x-auto"
onclick="window.getSelection().selectAllChildren(this)"
-
data-url="git@{{ $knot }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}"
-
>git@{{ $knot }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}</code>
<button
onclick="copyToClipboard(this, this.previousElementSibling.getAttribute('data-url'))"
class="px-3 py-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 border-l border-gray-300 dark:border-gray-600"
···
<code
class="flex-1 px-3 py-2 text-sm bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-l select-all cursor-pointer whitespace-nowrap overflow-x-auto"
onclick="window.getSelection().selectAllChildren(this)"
+
data-url="git@{{ $knot | stripPort }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}"
+
>git@{{ $knot | stripPort }}:{{ .RepoInfo.OwnerHandle }}/{{ .RepoInfo.Name }}</code>
<button
onclick="copyToClipboard(this, this.previousElementSibling.getAttribute('data-url'))"
class="px-3 py-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 border-l border-gray-300 dark:border-gray-600"