fix(plugins/code): handle no code snippet case
This commit is contained in:
@@ -45,8 +45,8 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
const files = events
|
||||
.flatMap(({sha, commit:{message, url}, files}) => files.map(({filename, status, additions, deletions, patch}) => ({sha, message, filename, status, additions, deletions, patch, repo:url.match(/repos[/](?<repo>[\s\S]+)[/]git[/]commits/)?.groups?.repo})))
|
||||
.filter(({patch}) => (patch ? (patch.match(/\n/mg)?.length ?? 1) : Infinity) < lines)
|
||||
const snippet = files[Math.floor(Math.random()*files.length)]
|
||||
|
||||
const snippet = files[Math.floor(Math.random()*files.length)] ?? null
|
||||
if (snippet) {
|
||||
//Trim common indent from content and change line feed
|
||||
if (!snippet.patch.split("\n").shift().endsWith("@@"))
|
||||
snippet.patch = snippet.patch.replace(/^(?<coord>@@.*?@@)/, "$<coord>\n")
|
||||
@@ -55,6 +55,7 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
|
||||
//Format patch
|
||||
snippet.patch = imports.htmlunescape((await imports.highlight(content, "diff")).trim())
|
||||
}
|
||||
|
||||
//Results
|
||||
return {snippet}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
</section>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<% if (plugins.code.snippet) { %>
|
||||
<div class="row">
|
||||
<section class="largeable-column-fields">
|
||||
<div class="field">
|
||||
@@ -39,6 +40,16 @@
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<div class="row">
|
||||
<section class="largeable-column-fields">
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"></path></svg>
|
||||
No recent code snippet found
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</section>
|
||||
<% } %>
|
||||
|
||||
Reference in New Issue
Block a user