Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add source transformer #8

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/(docs)/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { getPage, getPages } from "@/app/source"
import { DocsPage, DocsBody } from "fumadocs-ui/page"
import { notFound } from "next/navigation"
import { RollButton } from "fumadocs-ui/components/roll-button"
import { MDXRemote } from "next-mdx-remote/rsc"
// import { serialize } from "next-mdx-remote/serialize"

import type { Metadata } from "next"

export default async function Page({ params }: { params: { slug?: string[] } }) {
Expand Down Expand Up @@ -63,7 +66,13 @@ export default async function Page({ params }: { params: { slug?: string[] } })
</>
)

const MDX = page.data.exports.default
// TODO: Avoid this hack; See `source.ts`
let MDX = page.data.exports.default

if (typeof MDX === "string") {
// @ts-expect-error todo
MDX = MDX.replace("<", "&lt;").replace(">", "&gt;")
}

return (
<DocsPage
Expand All @@ -77,7 +86,7 @@ export default async function Page({ params }: { params: { slug?: string[] } })
<RollButton percentage={0.3} />
<DocsBody>
<h1>{page.data.title}</h1>
<MDX />
{typeof MDX === "string" ? <MDXRemote source={MDX} /> : <MDX />}
</DocsBody>
</DocsPage>
)
Expand Down
60 changes: 60 additions & 0 deletions app/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,65 @@ import { loader } from "fumadocs-core/source"
export const { getPage, getPages, pageTree, files } = loader({
baseUrl: "/",
rootDir: "docs",
transformers: [
async ({ storage }) => {
const releasesFile = storage.files.get("releases.page")
if (!releasesFile) {
console.log("No releases file found")
return
}

// Fetch latest release from GitHub
const ghResponse = await fetch(
"https://api.github.com/repos/gitbutlerapp/gitbutler/releases/latest"
)
if (!ghResponse.ok) {
console.log(`Failed to fetch latest release: ${ghResponse.statusText}`)
return
}

const ghResponsePayload = await ghResponse.json()
const latestRelease = Array.isArray(ghResponsePayload)
? ghResponsePayload[0]
: ghResponsePayload

if (latestRelease.draft || latestRelease.prerelease) {
console.log("Latest release is a draft or prerelease, skipping update")
return
}

// HACKY WAY
// @ts-expect-error TODO type data
const newContent = releasesFile.data.data.exports.structuredData.contents
newContent.splice(1, 0, {
heading: `v${latestRelease.name.replace("release/", "")}`,
content: `${latestRelease.body}\n\n---\n`
})
// TODO: This hack works, but it's not using their VFS APIs :thinking:
// @ts-expect-error TODO type data
releasesFile.data.data.exports.default = newContent
.map((item: { heading: string; content: string }) => {
let output = ""
if (item.heading) {
output = `### ${item.heading}`
}
output += `\n\n${item.content}`
return output
})
.join("\n\n")

// REAL WAY
// // @ts-expect-error TODO type data
// const newContent = releasesFile.data.data.exports.structuredData.contents
// newContent.splice(1, 0, {
// heading: `v${latestRelease.name.replace("release/", "")}`,
// content: latestRelease.body
// })
// // @ts-expect-error TODO type data
// releasesFile.data.data.exports.structuredData.contents = newContent
//
// storage.write("releases.mdx", "page", releasesFile.data)
}
],
source: createMDXSource(map)
})
5 changes: 0 additions & 5 deletions content/docs/releases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
title: Releases
---

import { Callout } from 'fumadocs-ui/components/callout';
import { Card, Cards } from 'fumadocs-ui/components/card';

Changelog for our GitButler client releases

<Callout type="info" title="Releases have moved!">

We have moved our releases announcements to our Discord channel. Come join us for updates.
</Callout>

Join our Discord [#releases](https://discord.com/channels/1060193121130000425/1183737922785116161) channel.

Expand Down
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import prettier from "eslint-plugin-prettier"
import typescriptEslint from "@typescript-eslint/eslint-plugin"
import globals from "globals"
import tsParser from "@typescript-eslint/parser"
import path from "node:path"
import { fileURLToPath } from "node:url"
import js from "@eslint/js"
import { FlatCompat } from "@eslint/eslintrc"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

const config = [
...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
),
{
plugins: {
prettier,
"@typescript-eslint": typescriptEslint
},

languageOptions: {
globals: {
...globals.browser
},

parser: tsParser,
ecmaVersion: 2023,
sourceType: "module"
}
}
]
export default config
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"fumadocs-mdx": "8.2.33",
"fumadocs-ui": "12.2.4",
"next": "^14.2.4",
"next-mdx-remote": "^5.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"shiki": "^1.9.0",
"tailwind-merge": "^2.3.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.6.0",
"@types/mdx": "^2.0.13",
"@types/node": "20.14.8",
"@types/react": "^18.3.3",
Expand All @@ -31,6 +34,7 @@
"eslint-config-next": "^14.2.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"globals": "^15.8.0",
"lint-staged": "^15.2.7",
"open-props": "^1.7.4",
"postcss": "^8.4.38",
Expand Down
Loading