Skip to content

Add XCard tweet embeds for markdown content#207

Open
VAIBHAVSING wants to merge 8 commits into
accretional:mainfrom
VAIBHAVSING:emdash/x-card-7op
Open

Add XCard tweet embeds for markdown content#207
VAIBHAVSING wants to merge 8 commits into
accretional:mainfrom
VAIBHAVSING:emdash/x-card-7op

Conversation

@VAIBHAVSING

@VAIBHAVSING VAIBHAVSING commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an XCard component for rendering rich X/Twitter tweet embeds in Svelte pages
  • add a remark plugin that converts standalone X/Twitter URLs in markdown into server-rendered tweet cards
  • document supported markdown usage, component props, and styling hooks for tweet embeds
image

VAIBHAVSING and others added 3 commits March 13, 2026 21:33
Standalone X/Twitter URLs on their own line in markdown content are
automatically rendered as rich tweet cards at build time via a remark
plugin. The component is also exported for direct use in Svelte pages.

- src/lib/utils/x-api.js: tweet fetch utility using Twitter syndication API
- src/lib/components/XCard.svelte: Svelte 4 component with loading/error states
- src/lib/cms/remark-x-card.js: remark plugin for auto-detecting standalone X URLs
- src/lib/cms/content-processor.js: integrate remark-x-card into mdsvex pipeline
- src/lib/index.ts: export XCard component
- templates/default/content/docs/x-card.md: documentation
- Fix remark-x-card.js: import visit as default export (v2 is CJS,
  module.exports = visit directly, named ESM import fails under Vite SSR)
- Update components.md: use subpath imports (statue-ssg/components/*)
  instead of barrel imports; add LinkPreview and TagList docs; remove
  deprecated ContentGrid/ImageGridElement/CaptionedGridElement sections

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Create src/lib/embeds/ with provider registry (runtime.js), X provider
  (providers/x.js), and embedEnhancer Svelte action (action.js)
- Export embeds via statue-ssg/embeds/* in package.json
- Templates use `use:embedEnhancer` on content wrappers instead of
  manual $effect + tick + enhanceEmbeds boilerplate
- MutationObserver in the action auto-enhances embeds on content changes
- Remove X-specific video hooks from ContentBody and DocsContent
- Add data-embed-provider attribute to x-card HTML output
- Adding a new embed provider only requires a provider file + registration
@VAIBHAVSING VAIBHAVSING marked this pull request as ready for review March 16, 2026 10:22
Comment thread src/lib/utils/x-api.js
*/
export async function fetchTweet(id) {
const token = generateToken(id);
const url = `https://cdn.syndication.twimg.com/tweet-result?id=${id}&token=${token}&features=${encodeURIComponent(SYNDICATION_FEATURES)}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work? Searching online indicates this in an unofficial/internal API that has not supported stable request patterns over the past few years.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have taken this from https://react-tweet.vercel.app/
And I confirm this is working on local system and most of people are still using this approach.
If you have any other approach I would like to work on those

@VAIBHAVSING VAIBHAVSING requested a review from ben-fultz March 20, 2026 13:46
@ben-fultz

ben-fultz commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Could we refactor this to put the data gathering/enrichment logic in the component file itself? As a general principle we want these components to be portable outside of Statue, and I don't think that adding patterns like src/lib/embeds or src/lib/utils will help us maintain that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants