Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
¿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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda