Skip to content

Commit

Permalink
feat: fix website type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsJacobsen committed Apr 16, 2024
1 parent a67ff72 commit 2294037
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
18 changes: 10 additions & 8 deletions inlang/source-code/website/src/pages/g/@uid/@id/+Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ export default function Page(props: PageProps) {
</section>
<section class="max-w-4xl mx-auto mb-24">
<Markdown markdown={props.markdown} />
<a
class="text-info/80 hover:text-info/100 text-sm font-semibold flex items-center"
href={convertLinkToGithub(readme())}
target="_blank"
>
<EditOutline class="inline-block mr-2" />
Edit on GitHub
</a>
<Show when={readme()}>
<a
class="text-info/80 hover:text-info/100 text-sm font-semibold flex items-center"
href={convertLinkToGithub(readme()!)}
target="_blank"
>
<EditOutline class="inline-block mr-2" />
Edit on GitHub
</a>
</Show>
</section>
<section class="max-w-4xl mx-auto">
<h3 class="text-surface-400 text-sm mb-4">Keywords</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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)

Expand Down
22 changes: 12 additions & 10 deletions inlang/source-code/website/src/pages/m/@uid/@id/+Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,18 @@ export default function Page(props: PageProps) {
</Show>
</div>
</section>
<div>
<a
class="text-info/80 hover:text-info/100 text-sm font-semibold flex items-center"
href={convertLinkToGithub(readme())}
target="_blank"
>
<EditOutline class="inline-block mr-2" />
Edit on GitHub
</a>
</div>
<Show when={readme()}>
<div>
<a
class="text-info/80 hover:text-info/100 text-sm font-semibold flex items-center"
href={convertLinkToGithub(readme()!)}
target="_blank"
>
<EditOutline class="inline-block mr-2" />
Edit on GitHub
</a>
</div>
</Show>
<div class="md:col-span-3 md:my-0 my-12">
<div>
<h3 class="text-surface-400 text-sm mb-2">Keywords</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2294037

Please sign in to comment.