Skip to content

Commit 45ffca2

Browse files
authored
Merge pull request #415 from TypedDevs/docs/add-installations
Add weekly downloads chart and minor documentation improvements
2 parents 35ce281 + f714440 commit 45ffca2

25 files changed

+1620
-536
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/iron
1+
lts/jod

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fix typo "to has been called"
6+
- Add weekly downloads to the docs
67

78
## [0.20.0](https://github.com/TypedDevs/bashunit/compare/0.19.1...0.20.0) - 2025-06-01
89

docs/components/WeeklyDownloads.vue

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<template>
2+
<div
3+
class="section"
4+
>
5+
<h2 class="title">
6+
{{ hoverTitle }}
7+
8+
<small class="result">
9+
{{ hoverLabel }}
10+
</small>
11+
</h2>
12+
13+
<div class="container">
14+
<canvas
15+
class="chart"
16+
ref="chart"
17+
@mouseleave="hoverIndex = null"
18+
></canvas>
19+
</div>
20+
</div>
21+
</template>
22+
23+
<script lang="ts">
24+
import { computed, defineComponent } from 'vue'
25+
import Chart from 'chart.js/auto'
26+
27+
type DownloadsItem = { week: string, count: number }
28+
29+
export default defineComponent({
30+
data() {
31+
return {
32+
downloads: [] as DownloadsItem[],
33+
hoverIndex: null as number | null,
34+
defaultLabel: 'loading...'
35+
}
36+
},
37+
38+
computed: {
39+
labels(): string[] {
40+
return this.downloads.map(({ week }) => week)
41+
},
42+
43+
series(): number[] {
44+
return this.downloads.map(({ count }) => count)
45+
},
46+
47+
hoverDownload(): DownloadsItem | undefined {
48+
return this.downloads[this.hoverIndex]
49+
},
50+
51+
hoverLabel(): string {
52+
if (this.hoverDownload === undefined) {
53+
return this.defaultLabel
54+
}
55+
56+
return this.formatNumber(this.hoverDownload.count)
57+
},
58+
59+
hoverTitle(): string {
60+
if (this.hoverDownload === undefined) {
61+
return 'Weekly downloads:'
62+
}
63+
64+
const start = new Date(this.hoverDownload.week + 'Z')
65+
const end = new Date(start)
66+
67+
end.setDate(start.getDate() + 6)
68+
69+
return this.formatDate(start) + ' to ' + this.formatDate(end) + ':'
70+
}
71+
},
72+
73+
methods: {
74+
formatDate(date: Date): string {
75+
return date.toISOString().slice(0, 10)
76+
},
77+
78+
formatNumber(number: number): string {
79+
return number.toLocaleString('es-ES', {
80+
maximumFractionDigits: 0,
81+
useGrouping: true,
82+
})
83+
}
84+
},
85+
86+
async mounted() {
87+
const response = await fetch('https://bashunit.typeddevs.com/downloads')
88+
89+
this.downloads = (await response.json()).reverse()
90+
91+
let dataCount = 0
92+
let totalCount = 0
93+
94+
this.downloads.forEach(({ count }) => {
95+
dataCount++
96+
totalCount += count
97+
})
98+
99+
if (totalCount !== 0) {
100+
this.defaultLabel = this.formatNumber(totalCount / dataCount)
101+
}
102+
103+
const chart = new Chart(this.$refs.chart as HTMLCanvasElement, {
104+
type: 'line',
105+
data: {
106+
labels: this.labels,
107+
datasets: [{
108+
label: 'Downloads',
109+
data: this.series,
110+
borderColor: '#6cbe1d',
111+
borderWidth: 3,
112+
pointRadius: 0,
113+
pointHoverRadius: 0,
114+
}]
115+
},
116+
options: {
117+
responsive: true,
118+
maintainAspectRatio: false,
119+
plugins: {
120+
tooltip: { enabled: false },
121+
legend: { display: false },
122+
},
123+
scales: {
124+
x: { display: false },
125+
y: { display: false },
126+
},
127+
interaction: {
128+
mode: 'index',
129+
intersect: false,
130+
},
131+
onHover: (_event, elements) => {
132+
if (elements.length > 0) {
133+
this.hoverIndex = elements[0].index
134+
} else {
135+
this.hoverIndex = null
136+
}
137+
}
138+
}
139+
});
140+
}
141+
})
142+
</script>
143+
144+
<style scoped lang="css">
145+
.title {
146+
border: none;
147+
padding: 0;
148+
font-variant-numeric: tabular-nums;
149+
}
150+
151+
.result {
152+
display: block;
153+
font-family: var(--vp-font-family-base);
154+
font-weight: normal;
155+
font-size: 32px;
156+
font-variant-numeric: tabular-nums;
157+
padding-top: 6px;
158+
}
159+
160+
.container {
161+
height: 200px;
162+
}
163+
164+
.chart {
165+
background-color: var(--vp-c-bg-elv);
166+
border-radius: 12px;
167+
padding: 24px;
168+
width: 100%;
169+
height: 200px;
170+
}
171+
</style>

docs/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,22 @@ features:
3737
src: /multiplatform.svg
3838
title: Multiplatform
3939
details: Seamlessly operates on Linux, macOS, and Windows (via WSL), facilitating a consistent testing environment across major platforms.
40+
---
41+
42+
<WeeklyDownloads />
43+
44+
<script setup lang="ts">
45+
import { onMounted } from 'vue';
46+
import VanillaTilt from 'vanilla-tilt';
47+
import WeeklyDownloads from './components/WeeklyDownloads.vue';
48+
49+
onMounted(() => {
50+
const heroImage = document.querySelector('.VPHero .VPImage');
51+
52+
VanillaTilt.init(heroImage, {
53+
'full-page-listening': true,
54+
reverse: true,
55+
gyroscope: false
56+
});
57+
});
58+
</script>

docs/public/awards/manfred-2023.jpg

-6.35 KB
Binary file not shown.
-39.5 KB
Loading
-63.1 KB
Loading
-53.5 KB
Loading
-121 KB
Loading
-57.5 KB
Loading

0 commit comments

Comments
 (0)