Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(changelog): replace gray-matter with browser-compatible frontmatter parser (#14435)

Arvin Xuc72b1ee6985a
diff --git a/src/components/ChangelogModal/ChangelogContent.tsx b/src/components/ChangelogModal/ChangelogContent.tsx
index 325f255d9a9..5949a86bcf1 100644
--- a/src/components/ChangelogModal/ChangelogContent.tsx
+++ b/src/components/ChangelogModal/ChangelogContent.tsx
@@ -8,8 +8,8 @@ import urlJoin from 'url-join';
import { CustomMDX } from '@/components/mdx';
import { OFFICIAL_SITE } from '@/const/url';
+import { lambdaClient } from '@/libs/trpc/client';
import { type Locales } from '@/locales/resources';
-import { ChangelogService } from '@/server/services/changelog';
import { type ChangelogIndexItem } from '@/types/changelog';
import VersionTag from './VersionTag';
@@ -25,8 +25,7 @@ interface PostItemProps extends ChangelogIndexItem {
const PostItem = ({ id, versionRange, locale, showDivider = true }: PostItemProps) => {
const { data } = useSWR([`changelog-post-${id}`, locale], async () => {
- const changelogService = new ChangelogService();
- return await changelogService.getPostById(id, { locale });
+ return await lambdaClient.changelog.getPostById.query({ id, locale });
});
if (!data || !data.title) return null;
diff --git a/src/components/ChangelogModal/index.tsx b/src/components/ChangelogModal/index.tsx
index 2913682927b..c04ec3179b9 100644
--- a/src/components/ChangelogModal/index.tsx
+++ b/src/components/ChangelogModal/index.tsx
@@ -5,7 +5,7 @@ import { ArrowUpRightIcon } from 'lucide-react';
import { memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { ChangelogService } from '@/server/services/changelog';
+import { lambdaClient } from '@/libs/trpc/client';
import ChangelogContent from './ChangelogContent';
@@ -23,9 +23,8 @@ const ChangelogModal = memo<ChangelogModalProps>(({ open, onClose, shouldLoad })
useEffect(() => {
if (shouldLoad && data.length === 0) {
setIsLoading(true);
- const changelogService = new ChangelogService();
- changelogService
- .getChangelogIndex()
+ lambdaClient.changelog.getIndex
+ .query()
.then((result) => {
setData(result);
})
diff --git a/src/server/routers/lambda/changelog.ts b/src/server/routers/lambda/changelog.ts
new file mode 100644
index 00000000000..a4f51c49378
--- /dev/null
+++ b/src/server/routers/lambda/changelog.ts
@@ -0,0 +1,46 @@
+import { TRPCError } from '@trpc/server';
+import { z } from 'zod';
+
+import { publicProcedure, router } from '@/libs/trpc/lambda';
+import { ChangelogService } from '@/server/services/changelog';
+
+const changelogProcedure = publicProcedure.use(async ({ next }) => {
+ return next({
+ ctx: {
+ changelogService: new ChangelogService(),
+ },
+ });
+});
+
+export const changelogRouter = router({
+ getIndex: changelogProcedure.query(async ({ ctx }) => {
+ try {
+ return await ctx.changelogService.getChangelogIndex();
+ } catch (e) {
+ throw new TRPCError({
+ code: 'INTERNAL_SERVER_ERROR',
+ message: 'Failed to fetch changelog index',
+ });
+ }
+ }),
+
+ getPostById: changelogProcedure
+ .input(
+ z.object({
+ id: z.string(),
+ locale: z.string().optional(),
+ }),
+ )
+ .query(async ({ input, ctx }) => {
+ try {
+ return await ctx.changelogService.getPostById(input.id, { locale: input.locale as any });
+ } catch (e) {
+ throw new TRPCError({
+ code: 'INTERNAL_SERVER_ERROR',
+ message: 'Failed to fetch changelog post',
+ });
+ }
+ }),
+});
+
+export type ChangelogRouter = typeof changelogRouter;
diff --git a/src/server/routers/lambda/index.ts b/src/server/routers/lambda/index.ts
index 2078db8f5fc..0bc91ab886a 100644
--- a/src/server/routers/lambda/index.ts
+++ b/src/server/routers/lambda/index.ts
@@ -26,6 +26,7 @@ import { aiProviderRouter } from './aiProvider';
import { apiKeyRouter } from './apiKey';
import { botMessageRouter } from './botMessage';
import { briefRouter } from './brief';
+import { changelogRouter } from './changelog';
import { chunkRouter } from './chunk';
import { comfyuiRouter } from './comfyui';
import { configRouter } from './config';
@@ -77,6 +78,7 @@ export const lambdaRouter = router({
agentSkills: agentSkillsRouter,
agentSignal: agentSignalRouter,
task: taskRouter,
+ changelog: changelogRouter,
brief: briefRouter,
aiAgent: aiAgentRouter,
aiChat: aiChatRouter,