UX: Improve git blob oneboxes (#30694)

Rearranges the info at the top of github/gitlab 'blob' oneboxes to make them easier to read
This commit is contained in:
David Taylor 2025-01-10 11:49:36 +00:00 committed by GitHub
parent 690ffcf1d5
commit ce97e51b63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 59 additions and 20 deletions

View File

@ -368,8 +368,16 @@ pre.onebox code ol.lines li:before {
counter-increment: li-counter; counter-increment: li-counter;
} }
.onebox.githubblob h4 { .onebox.githubblob,
.onebox.gitlabblob {
.onebox-body h4 {
word-break: break-all; word-break: break-all;
margin-bottom: 5px;
font-size: 1rem;
}
.git-blob-info {
font-size: var(--font-down-1);
}
} }
pre.onebox code ol { pre.onebox code ol {

View File

@ -35,13 +35,15 @@ module Onebox
"https://raw.githubusercontent.com/#{match[:org]}/#{match[:repo]}/#{match[:sha1]}/#{match[:file]}" "https://raw.githubusercontent.com/#{match[:org]}/#{match[:repo]}/#{match[:sha1]}/#{match[:file]}"
end end
def title
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(%r{^https?\://github\.com/}, ""))
end
def auth_headers(match) def auth_headers(match)
github_auth_header(match[:org]) github_auth_header(match[:org])
end end
private
def data
super.merge({ domain: "github.com/#{match[:org]}/#{match[:repo]}" })
end
end end
end end
end end

View File

@ -30,13 +30,15 @@ module Onebox
"https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}" "https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
end end
def title
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(%r{^https?\://gitlab\.com/}, ""))
end
def auth_headers(_match) def auth_headers(_match)
{} {}
end end
private
def data
super.merge({ domain: "gitlab.com/#{match[:user]}/#{match[:repo]}" })
end
end end
end end
end end

View File

@ -154,10 +154,30 @@ module Onebox
{ output: output_builder.join(), array: hash_builder } { output: output_builder.join(), array: hash_builder }
end end
def match
@match ||= @url.match(self.raw_regexp)
end
def sha1
full = match[:sha1]
# We don't actually know if this is an sha1, or a branch/tag name
# So we only truncate if it's exactly 40 characters long, which is fairly unlikely to be a branch/tag name.
if full.length == 40
full[0..8]
else
full
end
end
def title
Sanitize.fragment(match[:file])
end
def raw def raw
return @raw if defined?(@raw) return @raw if defined?(@raw)
m = @url.match(self.raw_regexp) m = match
if m if m
from = /\d+/.match(m[:from]) #get numeric should only match a positive interger from = /\d+/.match(m[:from]) #get numeric should only match a positive interger
@ -239,6 +259,7 @@ module Onebox
model_file: @model_file, model_file: @model_file,
width: 480, width: 480,
height: 360, height: 360,
sha1: sha1,
} }
end end
end end

View File

@ -1,5 +1,9 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4> <h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>
<div class="git-blob-info">
<a href="{{link}}" rel="noopener"><code>{{sha1}}</code></a>
</div>
{{^binary}} {{^binary}}
{{^has_lines}} {{^has_lines}}
{{#model_file}} {{#model_file}}

View File

@ -1,19 +1,21 @@
<h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4> <h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a></h4>
<div class="git-blob-info">
<a href="{{link}}" rel="noopener"><code>{{sha1}}</code></a>
</div>
{{^has_lines}} {{^has_lines}}
<pre><code class="{{lang}}">{{content}}</code></pre> <pre><code class="{{lang}}">{{content}}</code></pre>
{{/has_lines}} {{/has_lines}}
{{#has_lines}} {{#has_lines}}
<pre class="onebox"> <pre class="onebox"><code class="{{lang}}">
<code class="{{lang}}">
<ol class="start lines" start="{{cr_results.from}}" style="counter-reset: li-counter {{cr_results.from_minus_one}} ;"> <ol class="start lines" start="{{cr_results.from}}" style="counter-reset: li-counter {{cr_results.from_minus_one}} ;">
{{#lines}} {{#lines}}
<li{{#selected}} class="selected"{{/selected}}>{{data}}</li> <li{{#selected}} class="selected"{{/selected}}>{{data}}</li>
{{/lines}} {{/lines}}
</ol> </ol>
</code> </code></pre>
</pre>
{{/has_lines}} {{/has_lines}}
{{#truncated}} {{#truncated}}