Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
¿Cómo puedo ordenar una fuente RSS a través de .isoDate y mantener conectados los contenidos de la fuente (título y enlace)?

Me gustaría ordenar la fuente RSS por elemento más reciente y mantener el título de un elemento emparejado con su enlace correspondiente. Así es como analizo y muestro el feed. La propiedad que he pensado que sería mejor para hacer esto es .isoDate, aunque no estoy seguro de cómo llevar a cabo este proceso.

Lo hice funcionar simplemente presionando: item.isoDate + item.title en una matriz y clasificándolo, y haciendo lo mismo para una matriz para item.isoDate + item.link. Sin embargo, esto fue una solución rápida y no siempre funciona con feeds más grandes.

 function MarinersFeed() { const [disable, setDisable] = React.useState(false); const [completeFeed, setCompletedFeed] = React.useState([]); const [feedTitle, setFeedTitle] = React.useState([]); const [feedLink, setFeedLink] = React.useState([]); React.useEffect(async () => { let Parser = require('rss-parser'); let parser = new Parser(); const tFeed = []; const tFeedTitle = []; const tFeedLink = [] let feed = await parser.parseURL('https:*******.herokuapp.com/https://www.mlb.com/mariners/feeds/news/rss.xml'); feed.items.forEach(item => { //sort by using item.isoDate, keep item.title and item.link connected tFeed.push(item.title); tFeedLink.push( item.link); }); setCompletedFeed(tFeed); //setFeedTitle(tFeedTitle); setFeedLink(tFeedLink); }, []); const renderData = () => { return completeFeed.map((f, index) => { const title = feedTitle[index]; const link = feedLink[index] const fullFeed = completeFeed[index] return <div key={index} > <h3>{fullFeed} <Button onClick={(e) => { e.preventDefault(); console.log(link) window.open(link, "_blank") }}></Button></h3> </div> }) } return( <> {renderData()} </> ) } export default MarinersFeed;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar el método de clasificación de matriz, por ejemplo

 const RssParser = require('rss-parser'); async function fetchRss({ url, sort = false, sortOrder = 'desc' } = {}) { const rssParser = new RssParser(); const feed = await rssParser.parseURL(url); if (sort) { feed.items.sort((a, b) => { return sortOrder === 'asc' ? new Date(a.isoDate) - new Date(b.isoDate) // Oldest first : new Date(b.isoDate) - new Date(a.isoDate); // Newest first }); } return feed; } async function main() { const output = await fetchRss({ url: 'https://www.mlb.com/mariners/feeds/news/rss.xml', sort: true }); console.log(output); } main();

Producción:

 { items: [ { creator: 'Jim Callis, Sam Dykstra and Jonathan Mayo', title: '30 AFL sleeper prospects -- 1 for each org.', link: 'https://www.mlb.com/mariners/news/sleeper-prospects-in-arizona-fall-league-2021', pubDate: 'Fri, 15 Oct 2021 01:46:57 GMT', 'dc:creator': 'Jim Callis, Sam Dykstra and Jonathan Mayo', guid: 'https://www.mlb.com/mariners/news/sleeper-prospects-in-arizona-fall-league-2021', isoDate: '2021-10-15T01:46:57.000Z' }, { creator: 'Daniel Kramer', title: 'J-Rod launches his own YouTube channel', link: 'https://www.mlb.com/mariners/news/julio-rodriguez-mariners-top-prospect-launching-youtube-channel', pubDate: 'Thu, 14 Oct 2021 14:31:30 GMT', 'dc:creator': 'Daniel Kramer', guid: 'https://www.mlb.com/mariners/news/julio-rodriguez-mariners-top-prospect-launching-youtube-channel', isoDate: '2021-10-14T14:31:30.000Z' }, ...
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!