You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular是否支持嵌入Medium Feed?求类似vue-rss-blog的组件或通用方案

Great question! Let's break down how you can embed Medium content into your Angular app, since there isn't a direct drop-in equivalent to that Vue vue-rss-blog component you found.

1. Use Medium's Official Embedding Tools (Quick & Simple)

Medium provides built-in embedding options for single stories, collections, or even your entire publication — no custom code required beyond integrating the iframe into your Angular app. Here's how:

  • Go to any Medium story, click the ... menu in the top-right corner, then select Embed this story.
  • Copy the generated iframe code.
  • In your Angular component, use DomSanitizer to safely render the iframe (Angular blocks raw external URLs by default for security). Example code:
import { Component } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
  selector: 'app-medium-embed',
  template: `
    <iframe 
      [src]="safeEmbedUrl" 
      width="100%" 
      height="700" 
      frameborder="0" 
      scrolling="no"
      title="Medium Story Embed">
    </iframe>
  `
})
export class MediumEmbedComponent {
  safeEmbedUrl: SafeResourceUrl;

  constructor(private sanitizer: DomSanitizer) {
    // Replace with your embedded story URL from Medium
    const rawEmbedUrl = 'https://medium.com/embed/story/your-story-id-here';
    this.safeEmbedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(rawEmbedUrl);
  }
}

This works for single stories, collections, or even a full publication widget — just grab the right embed code from Medium.

2. Build a Custom Angular Component for Medium RSS Feeds

If you want a dynamic feed (like the Vue component you found, showing a list of your latest posts), you can pull Medium's RSS feed and render it in Angular. Here's a step-by-step approach:

Step 1: Get Your Medium RSS Feed URL

Every Medium user or publication has an RSS feed. For a user, it's https://medium.com/feed/@your-username; for a publication, it's https://medium.com/feed/publication-name.

Step 2: Install an RSS Parser

Use the rss-parser npm package to convert the XML RSS feed into usable JSON:

npm install rss-parser

Step 3: Create the Feed Component

Here's a complete example that fetches, parses, and renders your Medium posts:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import Parser from 'rss-parser';

interface MediumPost {
  title: string;
  link: string;
  pubDate: string;
  contentSnippet: string;
}

@Component({
  selector: 'app-medium-blog-feed',
  template: `
    <div class="medium-post-card" *ngFor="let post of mediumPosts">
      <h3 class="post-title">
        <a [href]="post.link" target="_blank" rel="noopener">{{ post.title }}</a>
      </h3>
      <p class="post-date">{{ post.pubDate | date:'longDate' }}</p>
      <p class="post-excerpt">{{ post.contentSnippet }}</p>
      <a [href]="post.link" target="_blank" rel="noopener" class="read-more-btn">
        Read Full Post on Medium
      </a>
    </div>
  `,
  styles: [`
    .medium-post-card { border: 1px solid #eee; padding: 1rem; margin-bottom: 1rem; border-radius: 8px; }
    .post-title { margin-top: 0; color: #000; }
    .post-date { color: #666; font-size: 0.9rem; }
    .read-more-btn { color: #00ab6b; text-decoration: none; font-weight: 500; }
  `]
})
export class MediumBlogFeedComponent implements OnInit {
  mediumPosts: MediumPost[] = [];
  private rssParser = new Parser();

  constructor(private http: HttpClient) {}

  ngOnInit(): void {
    const mediumFeedUrl = 'https://medium.com/feed/@your-username';
    
    // Note: Medium's RSS feed might block direct cross-origin requests.
    // For development, use a CORS proxy (replace with your own proxy in production)
    const corsProxyUrl = 'https://cors-anywhere.herokuapp.com/';
    const proxyFeedUrl = corsProxyUrl + mediumFeedUrl;

    this.http.get(proxyFeedUrl, { responseType: 'text' }).subscribe(async (xmlContent) => {
      const parsedFeed = await this.rssParser.parseString(xmlContent);
      this.mediumPosts = parsedFeed.items.map(item => ({
        title: item.title || 'Untitled Post',
        link: item.link || '',
        pubDate: item.pubDate || '',
        contentSnippet: item.contentSnippet || 'No excerpt available'
      }));
    });
  }
}

Important Note on CORS

Medium's RSS feed doesn't allow direct cross-origin requests from browsers. For production, avoid public CORS proxies — instead, set up a simple backend proxy (e.g., using Node.js, Express, or your existing backend) to forward the RSS feed request to Medium and return the response to your Angular app.

3. Universal Third-Party Widgets

If you don't want to build a custom component, you can use third-party RSS feed widgets (many are free) that generate an iframe embed code. Just copy that code into your Angular app (using DomSanitizer as shown earlier) to display your Medium feed. These are less customizable but require minimal code.

Final Verdict

Angular absolutely supports embedding Medium content:

  • Use official embeds for single stories/collections (quickest option).
  • Build a custom RSS component for a dynamic, styled feed (matches the Vue component's functionality).
  • Use universal widgets if you want a no-code middle ground.

内容的提问来源于stack exchange,提问作者Pavel Schoffer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:02:43