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
15 changes: 13 additions & 2 deletions packages/preset/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function createSocialLinks(socials: Socials | undefined): SocialLinks {
}));
}

// Extract an @handle from an X/Twitter profile URL
function extractXHandle(profileUrl: string): string {
try {
const url = new URL(profileUrl);
const handle = url.pathname.split('/')[1];
return `@${handle}`;
} catch {
throw new Error('Failed to extract X handle from X profile URL');
}
}

const createPreset = (config: PresetConfig): UserConfig => {
const { context, docs, theme, vercelAnalytics } = config;
const rootDir = path.join(context, docs.rootDir ?? 'docs');
Expand Down Expand Up @@ -85,9 +96,9 @@ const createPreset = (config: PresetConfig): UserConfig => {
url: docs.rootUrl,
image: `${docs.rootUrl}/${docs.ogImage}`,
description: docs.description,
twitter: docs.socials?.x
twitter: docs.socials?.X
? {
site: docs.socials?.x,
site: extractXHandle(docs.socials?.X),
card: 'summary_large_image',
}
: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/tester/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default withCallstackPreset(
rootUrl: 'https://callstack.com',
socials: {
github: 'https://github.com/callstack/rspress-theme',
X: 'https://github.com/callstack/rspress-theme',
X: 'https://x.com/repack_rn',
discord: 'https://github.com/callstack/rspress-theme',
},
},
Expand Down