{/* Days (rows) */}
{Array.from({ length: 7 }).map((_, dayIdx) => {
// Shift the dayIdx so that Monday is the first row and Sunday is the last
const shiftedDayIdx = (dayIdx + 1) % 7;
- const day = days[weekIdx * 7 + shiftedDayIdx];
+ const day = visibleDays[weekIdx * 7 + shiftedDayIdx];
+ if (!day) return ;
const dateStr = day.toISOString().slice(0, 10);
const count = data[dateStr] || 0;
return (
@@ -180,6 +250,28 @@ export default function ContributionCalendar({ data }) {
))}
More
+ {/* Toggle button for mobile */}
+ {isMobile && (
+
+ )}
);
}
\ No newline at end of file
diff --git a/src/pages/[lang]/development.astro b/src/pages/[lang]/development.astro
index 4b1db2d..f786cc7 100644
--- a/src/pages/[lang]/development.astro
+++ b/src/pages/[lang]/development.astro
@@ -16,53 +16,80 @@ const metadata = {
const lang = Astro.params.lang || 'en';
const t = getTranslation(lang);
-// Cache Gitea commits across all language builds
-let cachedCommits = null;
-async function getCachedCommits() {
- if (cachedCommits) return cachedCommits;
- const GITEA_COMMITS_URL = 'https://git.365devnet.eu/api/v1/repos/365DevNet/365devnet/commits?sha=main&stat=true&verification=true&files=true';
- let commits = [];
+// Fetch Gitea user heatmap at build time (cached)
+async function getUserHeatmap(username) {
+ const url = `https://git.365devnet.eu/api/v1/users/${username}/heatmap`;
+ let heatmap = [];
try {
const headers = { accept: 'application/json' };
if (import.meta.env.GITEA_TOKEN) {
headers['Authorization'] = `token ${import.meta.env.GITEA_TOKEN}`;
}
- const commitsResponse = await fetch(GITEA_COMMITS_URL, { headers });
- if (commitsResponse.ok) {
- commits = await commitsResponse.json();
+ const response = await fetch(url, { headers });
+ if (response.ok) {
+ heatmap = await response.json();
}
} catch (error) {
- console.error('Error fetching commits:', error);
+ console.error('Error fetching user heatmap:', error);
}
- cachedCommits = commits;
- return commits;
-}
-
-// Fetch Git repository data at build time (cached)
-const commits = await getCachedCommits();
-
-// Format date to a readable format
-const formatDate = (dateString: string) => {
- const date = new Date(dateString);
- const day = date.toLocaleString(lang, { day: '2-digit' });
- const month = date.toLocaleString(lang, { month: 'short' }).toLowerCase().replace('.', '');
- const year = date.getFullYear();
- return `${day}-${month}-${year}`;
-};
-
-// Helper: Group commits by date (YYYY-MM-DD)
-function getContributionData(commits) {
+ // Aggregate by date
const contributions = {};
- for (const commit of commits) {
- const date = commit.commit?.author?.date?.slice(0, 10);
- if (date) {
- contributions[date] = (contributions[date] || 0) + 1;
- }
+ for (const entry of heatmap) {
+ const date = new Date(entry.timestamp * 1000).toISOString().slice(0, 10);
+ contributions[date] = (contributions[date] || 0) + entry.contributions;
}
return contributions;
}
-const contributionData = getContributionData(commits);
+const contributionData = await getUserHeatmap('Richard');
+
+// Fetch latest user commits from activities/feeds
+async function getUserCommits(username) {
+ const url = `https://git.365devnet.eu/api/v1/users/${username}/activities/feeds`;
+ let feeds = [];
+ try {
+ const headers = { accept: 'application/json' };
+ if (import.meta.env.GITEA_TOKEN) {
+ headers['Authorization'] = `token ${import.meta.env.GITEA_TOKEN}`;
+ }
+ const response = await fetch(url, { headers });
+ if (response.ok) {
+ feeds = await response.json();
+ }
+ } catch (error) {
+ console.error('Error fetching user feeds:', error);
+ }
+ // Only keep commit_repo events
+ const commits = [];
+ for (const feed of feeds) {
+ if (feed.op_type === 'commit_repo' && feed.content) {
+ let content;
+ try {
+ content = JSON.parse(feed.content);
+ } catch (e) {
+ continue;
+ }
+ // Each feed may have multiple commits
+ if (content.Commits && Array.isArray(content.Commits)) {
+ for (const commit of content.Commits) {
+ commits.push({
+ sha: commit.Sha1,
+ message: commit.Message,
+ author: commit.AuthorName,
+ date: commit.Timestamp,
+ repo: feed.repo ? feed.repo.full_name : '',
+ repo_url: feed.repo ? feed.repo.html_url : '',
+ compare_url: content.CompareURL ? `https://git.365devnet.eu/${content.CompareURL}` : '',
+ });
+ }
+ }
+ }
+ if (commits.length >= 10) break;
+ }
+ return commits.slice(0, 10);
+}
+
+const userCommits = await getUserCommits('Richard');
export async function getStaticPaths() {
return [
@@ -72,6 +99,15 @@ export async function getStaticPaths() {
{ params: { lang: 'fr' } },
];
}
+
+// Format date to a readable format
+const formatDate = (dateString) => {
+ const date = new Date(dateString);
+ const day = date.toLocaleString(lang, { day: '2-digit' });
+ const month = date.toLocaleString(lang, { month: 'short' }).toLowerCase().replace('.', '');
+ const year = date.getFullYear();
+ return `${day}-${month}-${year}`;
+};
---
@@ -86,21 +122,22 @@ export async function getStaticPaths() {