Tucker McKnight
Make language percent breakdown work; add optional config for extra buttons
23
element.innerHTML = `<span>💡</span>`
23
element.innerHTML = `<span>🌞</span>`
96 97
<button class="dropdown-toggle btn shadow-none" id="dark-mode-switch" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<li><button class="btn shadow-none" data-theme-pref="light" onclick="toggleDarkMode(this)"><span class="me-1">💡</span>Light</button></li>
96 97
<button class="dropdown-toggle btn btn-bg" id="dark-mode-switch" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<li><button class="btn shadow-none" data-theme-pref="light" onclick="toggleDarkMode(this)"><span class="me-1">🌞</span>Light</button></li>
36
36
homepageButtons: reposConfig.repos[repoName].defaultTemplateConfiguration?.homepageButtons
7
7
const latestCommitMessage = latestCommit.message.length > 72
? latestCommit.message.split('\n')[0].substr(0, 72) + '...'
: latestCommit.message
const languageCounts = branch.fileList.reduce((counts, currentFile) => {
const fileParts = currentFile.split(".")
const fileExtension = fileParts[fileParts.length - 1]
counts.set(fileExtension, (counts.get(fileExtension) + 1) || 1)
return counts
}, new Map<string, number>())
// todo: this is probably broken for repos that use fewer than 6 languages
let languagePercentages: Array<[string, number]> = []
const total = branch.fileList.length
for (const entry of languageCounts) {
languagePercentages.push([entry[0], entry[1] / total])
}
languagePercentages.sort((a, b) => {
return b[1] - a[1]
})
const topLanguagePercentages = languagePercentages.slice(0, 5)
const otherLanguagePercent = languagePercentages.slice(6, languagePercentages.length - 6).reduce((sum, current) => {
return sum + current[1]
}, 0)
const largestPercent = Math.max(...topLanguagePercentages.map(tuple => tuple[1]), otherLanguagePercent)
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
<div class="col-12 col-xl-6 d-flex flex-column">
<div class="row py-3 flex-grow-1 align-items-center">
<div class="col-12">
<div class="row">
<div class="col-12 language-percentages">
<span style="width: 25%;" class="language-name text-light font-monospace">HTML</span>
<span style="width: 15%;" class="language-name text-light font-monospace">CSS</span>
<span style="width: 10%;" class="language-name text-light font-monospace">Rust</span>
<span style="width: 33%;" class="language-name text-light font-monospace">Typescript</span>
<span style="width: 17%;" class="language-name text-light font-monospace">Bash</span>
</div>
</div>
<div class="row">
<div class="col-12 language-percentages">
<div style="background: #E273FA; width: 25%;" class="language-percent"></div>
<div style="background: #852CDF; width: 15%;" class="language-percent"></div>
<div style="background: #E273FA; width: 10%;" class="language-percent"></div>
<div style="background: #852CDF; width: 33%;" class="language-percent"></div>
<div style="background: #E273FA; width: 17%;" class="language-percent"></div>
</div>
<div class="row flex-grow-1 align-items-center">
<div class="col-md col-fluid py-3">
<button class="w-100 btn btn-info btn-lg dropdown-toggle" id="clone-popover-btn">Clone</button>
</div>
<div class="col-md col-fluid py-3">
<button class="w-100 btn btn-outline-info shadow-none btn-lg">Setup Instructions</button>
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
<div class="col-12 col-xl-6 d-flex flex-column justify-content-around">
<div class="row flex-grow-1 align-items-stretch language-percent-row">
<div class="col-12 d-flex align-items-stretch">
<div class="row d-flex flex-grow-1">
${topLanguagePercentages.map((percentTuple) => `<div class='col language-col'><div class="language-name text-light font-monospace">${percentTuple[0]}</div><div class="language-percent" style="flex-grow: ${percentTuple[1] / largestPercent}"></div></div>`).join(';')}
<div class='col language-col'><div class="language-name text-light font-monospace">other</div><div class="language-percent" style="flex-grow: ${otherLanguagePercent / largestPercent}"></div></div>
<div class="row align-items-center">
<div class="col-12">
<div class="header-button-container">
<button class="btn btn-info btn-lg dropdown-toggle" id="clone-popover-btn">Clone</button>
${nav.homepageButtons.map((buttonConfig) => {
return `<a class="btn btn-outline-info btn-lg shadow-none" href="${buttonConfig.url}" ${buttonConfig.newTab ? 'target="_blank"' : ''}>${buttonConfig.text}${buttonConfig.newTab ? ' <span>&#x29C9;</span>' : ''}</a>`
}).join('')}
</div>
61 62
<p class="font-monospace text-white text-truncate">
Latest commit: ${latestCommit.date.toDateString()} <a class="fw-bold link-info" href="${nav.repoBranchCommitsBase()}${latestCommit.hash}">${latestCommit.hash.substr(0, 6)}</a> ${latestCommit.message.split('\n')[0]}
61 62
<p class="font-monospace text-white">
Latest commit: ${latestCommit.date.toDateString()} <a class="fw-bold link-info" href="${nav.repoBranchCommitsBase()}${latestCommit.hash}">${latestCommit.hash.substr(0, 6)}</a> ${latestCommitMessage}
57
57
"defaultTemplateConfiguration": {
"additionalProperties": false,
"properties": {
"homepageButtons": {
"items": {
"additionalProperties": false,
"properties": {
"newTab": {
"type": "boolean"
},
"text": {
"type": "string"
},
"url": {
"type": "string"
}
},
"required": [
"url",
"text"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"homepageButtons"
],
"type": "object"
},
121
121
},
"useDefaultTemplate": {
"type": "boolean"
40 41 42 43 44 45
border-bottom: 6px solid color.adjust($lightblue, $lightness: -10%);
border-right: 6px solid color.adjust($lightblue, $lightness: -13%);
}
#dark-mode-switch span {
text-shadow: 0 0 12px $black;
40 41 42 43 44 45
border-bottom: 6px solid color.adjust($lightblue, $lightness: -30%);
border-right: 6px solid color.adjust($lightblue, $lightness: -40%);
78 79 80
#dark-mode-switch span {
text-shadow: 0 0 12px $white;
}
78 79 80
}
.btn-bg, .btn-bg:hover {
border: 1px solid $body-color;
165 166
height: 2rem;
165 166
.language-percent-row {
max-height: 60%;
}
.language-col {
display: flex;
flex-direction: column;
justify-content: end;
min-height: 4rem;
}
background-color: $lilac;
// background-color: #E273FA;
}
.language-col:nth-of-type(2n) .language-percent {
background-color: $magenta;
// background-color: #852CDF;
181 182 183 184
.branches, .branches:hover {
border: 1px solid $body-color;
}
181 182 183 184
210
210
.badge.bg-primary {
background: linear-gradient(color.adjust($primary, $lightness: 10%), $primary);
box-shadow: -1px -3px 4px inset color.adjust($primary, $lightness: -30%);
}
.badge.bg-info {
background: linear-gradient(color.adjust($info, $lightness: 10%), $info);
box-shadow: -1px -3px 4px inset color.adjust($info, $lightness: -30%);
}
.header-button-container {
display: flex;
flex-wrap: wrap;
margin: 10px -10px;
.btn {
flex: 1;
flex-basis: 200px;
margin: 10px 10px;
}
}
40
40
useDefaultTemplate?: boolean,
58
}[]
58
}[],
defaultTemplateConfiguration?: {
homepageButtons: Array<{
url: string,
text: string,
newTab?: boolean,
}>
},