Skip to content
Merged
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
7 changes: 7 additions & 0 deletions multimodal/websites/docs/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/// <reference types="@rspress/theme-default" />

// Virtual module for build-time injected showcase data
declare module 'showcase-data' {
import type { ApiShareItem } from './src/services/api';
export const showcaseData: ApiShareItem[];
export const lastUpdated: string;
}
24 changes: 24 additions & 0 deletions multimodal/websites/docs/plugins/showcase-data-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { RspressPlugin } from '@rspress/core';

/**
* Rspress plugin to fetch showcase data at build time
*/
export function showcaseDataPlugin(): RspressPlugin {
return {
name: 'showcase-data-plugin',
async addRuntimeModules() {
try {
const response = await fetch('https://agent-tars.toxichl1994.workers.dev/shares/public?page=1&limit=100');
const data = await response.json();

return {
'showcase-data': `export const showcaseData = ${JSON.stringify(data.success ? data.data : [])};`,
};
} catch {
return {
'showcase-data': 'export const showcaseData = [];',
};
}
},
};
}
2 changes: 2 additions & 0 deletions multimodal/websites/docs/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from '@rspress/core';
import mermaid from 'rspress-plugin-mermaid';

import { SEO_CONFIG } from './src/shared/seoConfig';
import { showcaseDataPlugin } from './plugins/showcase-data-plugin';

const isProd = process.env.NODE_ENV === 'production';

Expand Down Expand Up @@ -81,6 +82,7 @@ export default defineConfig({
fontSize: 16,
},
}),
showcaseDataPlugin(),
],
themeConfig: {
darkMode: false,
Expand Down
43 changes: 16 additions & 27 deletions multimodal/websites/docs/src/hooks/useShowcaseData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useState, useEffect, useMemo } from 'react';
import { shareAPI, ApiShareItem } from '../services/api';
import { processShowcaseData, ProcessedShowcaseData, ShowcaseItem } from '../services/dataProcessor';
import {
processShowcaseData,
ProcessedShowcaseData,
ShowcaseItem,
} from '../services/dataProcessor';
import { showcaseData } from 'showcase-data';

interface UseShowcaseDataResult {
items: ShowcaseItem[];
Expand All @@ -15,6 +20,9 @@ interface UseShowcaseDataProps {
slug?: string | null;
}

/**
* Showcase data hook using build-time data for public shares
*/
export function useShowcaseData({
sessionId,
slug,
Expand All @@ -23,49 +31,30 @@ export function useShowcaseData({
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);

// Process data only when apiItems change (performance optimization)
const processedData = useMemo(() => {
if (apiItems.length === 0) return null;
return processShowcaseData(apiItems);
}, [apiItems]);

// Extract items for backward compatibility
const items = processedData?.items || [];

const fetchData = async () => {
try {
setIsLoading(true);
setError(null);

if (sessionId) {
if (!sessionId && !slug) {
// Use build-time data for public shares
setApiItems(showcaseData.length > 0 ? showcaseData : await shareAPI.getPublicShares(1, 100).then(r => r.data));
} else if (sessionId) {
const response = await shareAPI.getShare(sessionId);

if (response.success) {
setApiItems([response.data]);
} else {
throw new Error(response.error || 'Failed to fetch share data');
}
setApiItems(response.success ? [response.data] : []);
} else if (slug) {
const response = await shareAPI.getShareBySlug(slug);

if (response.success) {
setApiItems([response.data]);
} else {
throw new Error(response.error || `No share found with slug: ${slug}`);
}
} else {
const response = await shareAPI.getPublicShares(1, 100);

if (response.success) {
setApiItems(response.data);
} else {
throw new Error(response.error || 'Failed to fetch showcase data');
}
setApiItems(response.success ? [response.data] : []);
}
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
setError(errorMessage);
console.error('Failed to fetch showcase data:', err);
setError(err instanceof Error ? err.message : 'Unknown error');
} finally {
setIsLoading(false);
}
Expand Down