Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
¿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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda