lukeonline

source for my website
git clone https://git.lukeonline.net/repos/lukeonline
Log | Files | Refs | README | LICENSE

commit 7b6c56b71d34a6e7a34ee981b61e8be72c1c50da
parent dc31a28543232670c1ab3bad6f6059ba85528d06
Author: LukeJ <luke.jones.2567@gmail.com>
Date:   Tue, 29 Sep 2026 21:00:26 +0100

feat: basic repository library for pulling in commit details

Diffstat:
Asrc/lib/repos.ts | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/lib/repos.ts b/src/lib/repos.ts @@ -0,0 +1,56 @@ +import fs from 'node:fs' +import path from 'node:path' + +const reposRoot = path.join(process.cwd(), 'src/content/repos') + +export interface Repo { + name: string + head: string + defaultBranch: string + branches: string[] + tags: string[] + commitCount: number +} + +export interface Commit { + sha: string + shortSha: string + parents: string[] + author: { + name: string + email: string + } + date: string + message: string +} + +export interface RepoFile { + path: string + mode: string + type: string + sha: string +} + +export function getCommits(name: string): Commit[] { + const file = path.join(reposRoot, name, 'commits.json') + + return JSON.parse(fs.readFileSync(file, 'utf-8')) +} + +export function getTree(name: string): RepoFile[] { + const file = path.join(reposRoot, name, 'tree.json') + + return JSON.parse(fs.readFileSync(file, 'utf-8')) +} + +export function getCommit(name: string, sha: string) { + const file = path.join(reposRoot, name, 'commits', `${sha}.json`) + + return JSON.parse(fs.readFileSync(file, 'utf-8')) +} + +export function getFile(name: string, encodedPath: string) { + const file = path.join(reposRoot, name, 'files', `${encodedPath}.json`) + + return JSON.parse(fs.readFileSync(file, 'utf-8')) +}