lukeonline - commit db8786b
fix: use encoded filepaths to prevent build errordb8786beb5bcc80e4353291570b58c391f893bb6LukeJ<luke.jones.2567@gmail.com>2026-09-29T23:15:32+01:00diff --git a/src/lib/repos.ts b/src/lib/repos.ts
index 2ab410e..4b5d49a 100644
--- a/src/lib/repos.ts
+++ b/src/lib/repos.ts
@@ -87,3 +87,11 @@ export function getDirectoryChildren(tree: RepoFile[], directory: string) {
files: [...files].sort(),
}
}
+
+export function encodeFilePath(filePath: string) {
+ return Buffer.from(filePath, 'utf-8').toString('base64url')
+}
+
+export function decodeFilePath(encodedPath: string) {
+ return Buffer.from(encodedPath, 'base64url').toString('utf-8')
+}
diff --git a/src/pages/projects/[name].astro b/src/pages/projects/[name].astro
index f6f9c13..dc0f533 100644
--- a/src/pages/projects/[name].astro
+++ b/src/pages/projects/[name].astro
@@ -3,8 +3,12 @@ import Base from '../../layouts/Base.astro'
import { getCollection } from 'astro:content'
import { getFileByPath, getTree } from '../../lib/repos'
-import { BUTTON_STYLING_SHARED, DISABLED_BUTTON_STYLING_SHARED } from '../../consts.ts'
+import {
+ BUTTON_STYLING_SHARED,
+ DISABLED_BUTTON_STYLING_SHARED,
+} from '../../consts.ts'
import CodeContainer from '../../components/CodeContainer.astro'
+import { encodeFilePath } from '../../lib/repos.ts'
export async function getStaticPaths() {
const repos = await getCollection('repos')
@@ -24,18 +28,13 @@ const { repo } = Astro.props
const tree = getTree(repo.data.name)
function getReadMeContent() {
- const readme = tree.find(
- (file) => file.path.toLowerCase() === 'readme.md',
- )
+ const readme = tree.find((file) => file.path.toLowerCase() === 'readme.md')
if (!readme) {
return 'No README provided in this repository.'
}
- const file = getFileByPath(
- repo.data.name,
- readme.path,
- )
+ const file = getFileByPath(repo.data.name, readme.path)
return file.binary ? '' : file.content
}
@@ -43,26 +42,28 @@ function getReadMeContent() {
<Base title={repo.data.name}>
<div class="flex flex-row items-baseline gap-2">
- <code class="text-sm"><a href={`/projects/${repo.data.name}`}>{repo.data.defaultBranch}</a></code>
+ <code class="text-sm"
+ ><a href={`/projects/${repo.data.name}`}>{repo.data.defaultBranch}</a
+ ></code
+ >
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
href={`/projects/${repo.data.name}/commits`}
- >{repo.data.commitCount} commits</a
+ >{repo.data.commitCount} commits</a
>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/files`}
- >{tree.length} files</a
+ href={`/projects/${repo.data.name}/files`}>{tree.length} files</a
>
<a
- class={DISABLED_BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- aria-disabled="true"
- >README</a
+ class={DISABLED_BUTTON_STYLING_SHARED +
+ ' h-8 p-1 pl-2 items-center gap-3'}
+ aria-disabled="true">README</a
>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/LICENSE`}
- >LICENSE</a
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('LICENSE')}`}
+ >LICENSE</a
>
</div>
<CodeContainer code={getReadMeContent()} />
diff --git a/src/pages/projects/[name]/commits/index.astro b/src/pages/projects/[name]/commits/index.astro
index 932589c..d6b0fd1 100644
--- a/src/pages/projects/[name]/commits/index.astro
+++ b/src/pages/projects/[name]/commits/index.astro
@@ -3,7 +3,11 @@ import Base from '../../../../layouts/Base.astro'
import { getCollection } from 'astro:content'
import { getCommits, getTree } from '../../../../lib/repos'
-import { BUTTON_STYLING_SHARED, DISABLED_BUTTON_STYLING_SHARED } from '../../../../consts.ts'
+import {
+ BUTTON_STYLING_SHARED,
+ DISABLED_BUTTON_STYLING_SHARED,
+} from '../../../../consts.ts'
+import { encodeFilePath } from '../../../../lib/repos.ts'
export async function getStaticPaths() {
const repos = await getCollection('repos')
@@ -27,10 +31,13 @@ const tree = getTree(name!)
<Base title={`${name}`}>
<div class="flex flex-row items-baseline gap-2">
- <code class="text-sm"><a href={`/projects/${name}`}>{repo.data.defaultBranch}</a></code>
+ <code class="text-sm"
+ ><a href={`/projects/${name}`}>{repo.data.defaultBranch}</a></code
+ >
<a
- class={DISABLED_BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
+ class={DISABLED_BUTTON_STYLING_SHARED +
+ ' h-8 p-1 pl-2 items-center gap-3'}
aria-disabled="true"
>
{repo.data.commitCount} commits
@@ -45,14 +52,14 @@ const tree = getTree(name!)
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${name}/file/README.md`}
+ href={`/projects/${name}/file/${encodeFilePath('README.md')}`}
>
README
</a>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${name}/file/LICENSE`}
+ href={`/projects/${name}/file/${encodeFilePath('LICENSE')}`}
>
LICENSE
</a>
diff --git a/src/pages/projects/[name]/file/[...path].astro b/src/pages/projects/[name]/file/[...path].astro
index 6fd18a2..c04becc 100644
--- a/src/pages/projects/[name]/file/[...path].astro
+++ b/src/pages/projects/[name]/file/[...path].astro
@@ -2,7 +2,12 @@
import Base from '../../../../layouts/Base.astro'
import { getCollection } from 'astro:content'
-import { getFileByPath, getTree } from '../../../../lib/repos'
+import {
+ decodeFilePath,
+ encodeFilePath,
+ getFileByPath,
+ getTree,
+} from '../../../../lib/repos'
import CodeContainer from '../../../../components/CodeContainer.astro'
import { BUTTON_STYLING_SHARED } from '../../../../consts.ts'
@@ -12,23 +17,27 @@ export async function getStaticPaths() {
return repos.flatMap((repo) => {
const tree = getTree(repo.data.name)
- return tree.map((file) => ({
- params: {
- name: repo.data.name,
- path: file.path,
- },
- props: {
- repo,
- file,
- },
- }))
+ return tree
+ .filter((file) => file.path)
+ .map((file) => ({
+ params: {
+ name: repo.data.name,
+ path: encodeFilePath(file.path),
+ },
+ props: {
+ repo,
+ file,
+ tree,
+ },
+ }))
})
}
const { repo, file } = Astro.props
const tree = getTree(repo.data.name)
-const fileData = getFileByPath(repo.data.name, file.path)
+const filePath = decodeFilePath(Astro.params.path!)
+const fileData = getFileByPath(repo.data.name, filePath)
---
<Base title={`${repo.data.name} - ${file.path}`}>
@@ -55,14 +64,14 @@ const fileData = getFileByPath(repo.data.name, file.path)
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/README.md`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('README.md')}`}
>
README
</a>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/LICENSE`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('LICENSE')}`}
>
LICENSE
</a>
diff --git a/src/pages/projects/[name]/files/[...path].astro b/src/pages/projects/[name]/files/[...path].astro
index 669111a..4998a2d 100644
--- a/src/pages/projects/[name]/files/[...path].astro
+++ b/src/pages/projects/[name]/files/[...path].astro
@@ -3,6 +3,7 @@ import { getCollection } from 'astro:content'
import { getTree, getDirectoryChildren } from '../../../../lib/repos'
import Base from '../../../../layouts/Base.astro'
import { BUTTON_STYLING_SHARED } from '../../../../consts.ts'
+import { encodeFilePath } from '../../../../lib/repos.ts'
export async function getStaticPaths() {
const repos = await getCollection('repos')
@@ -66,14 +67,14 @@ const parent = directory.includes('/')
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/README.md`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('README.md')}`}
>
README
</a>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/LICENSE`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('LICENSE')}`}
>
LICENSE
</a>
@@ -113,7 +114,7 @@ const parent = directory.includes('/')
return (
<a
class="p-0.5 hover:text-blue-800 focus:underline"
- href={`/projects/${repo.data.name}/file/${filePath}`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath(filePath)}`}
>
{file}
</a>
diff --git a/src/pages/projects/[name]/files/index.astro b/src/pages/projects/[name]/files/index.astro
index bd6d6c6..8f08dfc 100644
--- a/src/pages/projects/[name]/files/index.astro
+++ b/src/pages/projects/[name]/files/index.astro
@@ -2,7 +2,11 @@
import { getCollection } from 'astro:content'
import { getTree } from '../../../../lib/repos'
import Base from '../../../../layouts/Base.astro'
-import { BUTTON_STYLING_SHARED, DISABLED_BUTTON_STYLING_SHARED } from '../../../../consts.ts'
+import {
+ BUTTON_STYLING_SHARED,
+ DISABLED_BUTTON_STYLING_SHARED,
+} from '../../../../consts.ts'
+import { encodeFilePath } from '../../../../lib/repos.ts'
export async function getStaticPaths() {
const repos = await getCollection('repos')
@@ -36,26 +40,28 @@ const directories = [
<Base title={repo.data.name}>
<div class="flex flex-row items-baseline gap-2">
- <code class="text-sm"><a href={`/projects/${repo.data.name}`}>{repo.data.defaultBranch}</a></code>
+ <code class="text-sm"
+ ><a href={`/projects/${repo.data.name}`}>{repo.data.defaultBranch}</a
+ ></code
+ >
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
href={`/projects/${repo.data.name}/commits`}
- >{repo.data.commitCount} commits</a
+ >{repo.data.commitCount} commits</a
>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/files`}
- >{tree.length} files</a
+ href={`/projects/${repo.data.name}/files`}>{tree.length} files</a
>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/README.md`}
- >README</a
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('README.md')}`}
+ >README</a
>
<a
class={BUTTON_STYLING_SHARED + ' h-8 p-1 pl-2 items-center gap-3'}
- href={`/projects/${repo.data.name}/file/LICENSE`}
- >LICENSE</a
+ href={`/projects/${repo.data.name}/file/${encodeFilePath('LICENSE')}`}
+ >LICENSE</a
>
</div>
<div
@@ -76,7 +82,7 @@ const directories = [
files.map((file) => (
<a
class="p-0.5 hover:text-blue-800 focus:underline"
- href={`/projects/${repo.data.name}/file/${file.path}`}
+ href={`/projects/${repo.data.name}/file/${encodeFilePath(file.path)}`}
>
{file.path}
</a>