From 2294037257d89faa7e679c1da322aba969c9a41d Mon Sep 17 00:00:00 2001 From: Nils Jacobsen Date: Tue, 16 Apr 2024 10:57:14 +0200 Subject: [PATCH] feat: fix website type errors --- .../website/src/pages/g/@uid/@id/+Page.tsx | 18 ++++++++------- .../src/pages/g/@uid/@id/+onBeforeRender.tsx | 12 ++++++---- .../website/src/pages/m/@uid/@id/+Page.tsx | 22 ++++++++++--------- .../src/pages/m/@uid/@id/+onBeforeRender.tsx | 6 +++-- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/inlang/source-code/website/src/pages/g/@uid/@id/+Page.tsx b/inlang/source-code/website/src/pages/g/@uid/@id/+Page.tsx index 57b07069d8..e3f44230f6 100644 --- a/inlang/source-code/website/src/pages/g/@uid/@id/+Page.tsx +++ b/inlang/source-code/website/src/pages/g/@uid/@id/+Page.tsx @@ -142,14 +142,16 @@ export default function Page(props: PageProps) {
- - - Edit on GitHub - + + + + Edit on GitHub + +

Keywords

diff --git a/inlang/source-code/website/src/pages/g/@uid/@id/+onBeforeRender.tsx b/inlang/source-code/website/src/pages/g/@uid/@id/+onBeforeRender.tsx index a11710245f..a79cda2b03 100644 --- a/inlang/source-code/website/src/pages/g/@uid/@id/+onBeforeRender.tsx +++ b/inlang/source-code/website/src/pages/g/@uid/@id/+onBeforeRender.tsx @@ -8,7 +8,9 @@ import { redirect } from "vike/abort" const repositoryRoot = import.meta.url.slice(0, import.meta.url.lastIndexOf("inlang/source-code")) -export default async function onBeforeRender(pageContext: PageContext) { +export default async function onBeforeRender( + pageContext: PageContext +): Promise<{ pageContext: any }> { const item = registry.find( (item: any) => item.uniqueID === pageContext.routeParams.uid ) as MarketplaceManifest & { uniqueID: string } @@ -23,9 +25,11 @@ export default async function onBeforeRender(pageContext: PageContext) { return typeof item.readme === "object" ? item.readme.en : item.readme } - const text = await (readme().includes("http") - ? (await fetch(readme())).text() - : await fs.readFile(new URL(readme(), repositoryRoot), "utf-8")) + if (!readme()) throw redirect("/not-found") + + const text = await (readme()!.includes("http") + ? (await fetch(readme()!)).text() + : await fs.readFile(new URL(readme()!, repositoryRoot), "utf-8")) const markdown = await convert(text) diff --git a/inlang/source-code/website/src/pages/m/@uid/@id/+Page.tsx b/inlang/source-code/website/src/pages/m/@uid/@id/+Page.tsx index 38512c1f0c..13dd7f3013 100644 --- a/inlang/source-code/website/src/pages/m/@uid/@id/+Page.tsx +++ b/inlang/source-code/website/src/pages/m/@uid/@id/+Page.tsx @@ -427,16 +427,18 @@ export default function Page(props: PageProps) {
-
- - - Edit on GitHub - -
+ +
+ + + Edit on GitHub + +
+

Keywords

diff --git a/inlang/source-code/website/src/pages/m/@uid/@id/+onBeforeRender.tsx b/inlang/source-code/website/src/pages/m/@uid/@id/+onBeforeRender.tsx index d3d48c9102..105f3df1f4 100644 --- a/inlang/source-code/website/src/pages/m/@uid/@id/+onBeforeRender.tsx +++ b/inlang/source-code/website/src/pages/m/@uid/@id/+onBeforeRender.tsx @@ -50,8 +50,10 @@ export default async function onBeforeRender(pageContext: PageContext) { return typeof item.readme === "object" ? item.readme.en : item.readme } + if (!readme()) throw redirect("/not-found", 301) + const changelog = async () => { - const changelogPath = readme().replace(/\/[^/]*$/, "/CHANGELOG.md") + const changelogPath = readme()!.replace(/\/[^/]*$/, "/CHANGELOG.md") if (await fileExists(changelogPath)) { return changelogPath @@ -65,7 +67,7 @@ export default async function onBeforeRender(pageContext: PageContext) { ? fetch(path).then((res) => res.text()) : fs.readFile(new URL(path, repositoryRoot)).then((res) => res.toString()) - const readmeMarkdown = await convert(await text(readme())) + const readmeMarkdown = await convert(await text(readme()!)) const changelogPath = await changelog() const changelogMarkdown = changelogPath ? await convert(await text(changelogPath)) : undefined