微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用RSS Feed从博客恢复帖子到我的Gatsby网站,有人知道什么是好的插件以及如何解析查询?

如何解决尝试使用RSS Feed从博客恢复帖子到我的Gatsby网站,有人知道什么是好的插件以及如何解析查询?

GatsbyJS的新功能,我需要帮助来检查RSS Feed,但我迷路了!

我想将另一个博客RSS Feed检查到我的gatsby站点,我想将该博客的帖子找回我的gatsby站点

有人可以告诉我是否需要安装: “ gatsby源RSS提要”(我认为),“ gatsby源RSS”或“ gatsby RSS提要”(我认为不是,是将他的gatsby帖子推送到另一个博客的,我需要相反的意思)?

如果有人还可以向我展示如何声明RSS查询?在女巫文件夹中?

我的gatsby-config.js:

@H_502_10@const path = require("path") const config = require("./data/siteConfig") module.exports = { siteMetadata: { title: ``,author: config.authorName,description: config.siteDescription,siteUrl: config.siteUrl,...config,},pathPrefix: `/froggit.fr`,plugins: [ { resolve: `gatsby-source-filesystem`,options: { name: "pages",path: "content/pages",{ resolve: `gatsby-source-filesystem`,options: { name: "posts",path: "content/posts",//path: "src/page/blog",options: { name: "images",path: "content/images",{ resolve: `gatsby-plugin-page-creator`,options: { path: path.join(__dirname,`src`,`pages`),options: { path: `${__dirname}/src/settings/pages`,{ resolve: `gatsby-plugin-mdx`,options: { extensions: [`.mdx`,`.md`],defaultLayouts: { default: require.resolve("./src/templates/page.js"),gatsbyRemarkPlugins: [ { resolve: "gatsby-remark-images",options: { maxWidth: 590,linkImagesToOriginal: false,withWebp: true,{ resolve: "gatsby-remark-prismjs" },{ resolve: "gatsby-remark-responsive-iframe" },{ resolve: "gatsby-remark-copy-linked-files" },{ resolve: "gatsby-remark-smartypants" },{ resolve: "gatsby-remark-autolink-headers" },],{ resolve: `gatsby-transformer-remark`,options: { plugins: [`gatsby-remark-images`],`gatsby-transformer-sharp`,`gatsby-plugin-offline`,`gatsby-plugin-styled-components`,`gatsby-plugin-react-helmet`,`gatsby-plugin-sharp`,{ resolve: `gatsby-plugin-google-analytics`,options: { trackingId: config.googleAnalyticsId,{ resolve: `gatsby-source-RSS-Feed`,options: { url: `https://www.gatsbyjs.org/blog/RSS.xml`,name: `GatsbyBlog`,parserOption: { customFields: { item: ['itunes:duration'] } } } },{ resolve: '@uptimeventures/gatsby-source-RSS',options: { Feeds: ['https://www.uptime.ventures/blog/RSS.xml'],{ resolve: 'gatsby-source-RSS',options: { RSSURL: 'https://lydra.fr/tag/froggit/Feed/RSS.xml' } },{ resolve: `gatsby-plugin-Feed`,options: { setup: (options) => ({ ...options,custom_namespaces: { yournamespace: "https://lydra.fr/tag/froggit/Feed/",}),Feeds: [ { serialize: ({ query: { allMarkdownRemark },}) => { return allMarkdownRemark.edges.map((edge) => { return Object.assign( {},edge.node.frontmatter,{ custom_elements: [ //{ "content:encoded": edge.node.html },{ "yournamespace:yourcustomfield": edge.node.fields.someField },} ); }); },{ resolve: 'gatsby-source-RSS',options: { RSSURL: 'https://blog.jordanrhea.com/RSS.xml',customFields: { item: ['tags'],*/ { resolve: `gatsby-plugin-Feed`,options: { query: ` { site { siteMetadata { title description siteUrl site_url: siteUrl } } } `,Feeds: [ { serialize: ({ query: { site,allMarkdownRemark } }) => { return allMarkdownRemark.edges.map(edge => { return Object.assign({},{ description: edge.node.excerpt,date: edge.node.frontmatter.date,url: site.siteMetadata.siteUrl + edge.node.fields.slug,guid: site.siteMetadata.siteUrl + edge.node.fields.slug,custom_elements: [{ "content:encoded": edge.node.html }],}) }) },query: ` { allMarkdownRemark( sort: { order: DESC,fields: [frontmatter___date] },) { edges { node { excerpt html fields { slug } frontmatter { title date } } } } } `,output: "/RSS.xml",title: "Your Site's RSS Feed",{ resolve: `gatsby-source-podcast-RSS-Feed`,options: { FeedURL: `https://lydra.fr/ea-2-le-podcasteur-erwan/RSS`,id: 'guid',{ resolve: `@arshad/gatsby-theme-podcast-core`,options: { FeedUrl: `https://blog.jordanrhea.com/RSS.xml`,podcast: { name: `Name of podcast`,description: `Eligendi nisi nobis nisi voluptate. Corporis deserunt provident hic numquam. Veritatis vero necessitatibus adipisci cumque voluptate rerum at.`,image: `content/images/podcast.jpg`,social: [ { name: `Apple podcast`,url: `https://itunes.apple.com`,{ name: `Google podcast`,url: `https://podcasts.google.com`,{ resolve: `gatsby-source-youtube`,options: { channelId: '<<Youtube channelID eg. UCK8sQmJBp8GCxrOtXWBpyEA >>',apiKey: '<< Add your Youtube api key here>>',maxVideos: 50 // Defaults to 50 },{ resolve: `gatsby-plugin-manifest`,options: { name: config.siteTitle,short_name: config.siteTitle,start_url: config.pathPrefix,background_color: config.background_color,theme_color: config.theme_color,display: config.display,icon: "content/images/logo_froggit.png",{ resolve: "gatsby-plugin-compile-es6-packages",options: { modules: ["gatsby-starter-morning-dew"],}

在我的文件中: gatsby-node.js ?我已经复制了一些用于创建RSS Feed代码,但是我不了解很多事情...

@H_502_10@const { createFilePath } = require("gatsby-source-filesystem") const { load,createFeed } = require('./internals') async function sourceNodes({ boundActionCreators },options = {}) { const { createNode } = boundActionCreators const { Feeds = [] } = options for (const f of Feeds) { const { RSS } = await load(f) if (RSS && RSS.channel) { const sources = (Array.isArray(RSS.channel) ? RSS.channel : [RSS.channel] ) sources.forEach(f => createFeed(f,createNode)) } } return Promise.resolve() } module.exports = { sourceNodes,} exports.createPages = async ({ graphql,actions,reporter }) => { const { createPage } = actions const BlogPostTemplate = require.resolve("./src/templates/blog-post.js") const BlogPostShareImage = require.resolve( "./src/templates/blog-post-share-image.js" ) const PageTemplate = require.resolve("./src/templates/page.js") const PostsBytagTemplate = require.resolve("./src/templates/tags.js") const ListPoststemplate = require.resolve( "./src/templates/list.js" ) const allMarkdownQuery = await graphql(` { allMarkdown: allMdx( sort: { fields: [frontmatter___date],order: DESC } filter: { frontmatter: { published: { ne: false } } } limit: 1000 ) { edges { node { fileAbsolutePath frontmatter { title slug tags language cover { publicURL } unlisted } timetoRead excerpt } } } } `) if (allMarkdownQuery.errors) { reporter.panic(allMarkdownQuery.errors) } const postPerPageQuery = await graphql(` { site { siteMetadata { postsPerPage } } } `) const markdownFiles = allMarkdownQuery.data.allMarkdown.edges const posts = markdownFiles.filter(item => item.node.fileAbsolutePath.includes("/content/posts/") ) actions.createPage({ path: '/blog',component: require.resolve(`./src/templates/list.js`),context: {},}) const postsPerPage = postPerPageQuery.data.site.siteMetadata.postsPerPage const nbPages = Math.ceil(listedPosts.length / postsPerPage) Array.from({ length: nbPages }).forEach((_,i) => { createPage({ path: i === 0 ? `/` : `/pages/${i + 1}`,component: ListPoststemplate,context: { limit: postsPerPage,skip: i * postsPerPage,currentPage: i + 1,nbPages: nbPages,}) posts.forEach((post,index,posts) => { const prevIoUs = index === posts.length - 1 ? null : posts[index + 1].node const next = index === 0 ? null : posts[index - 1].node createPage({ path: post.node.frontmatter.slug,component: BlogPostTemplate,context: { slug: post.node.frontmatter.slug,prevIoUs,next,}) if (process.env.gatsby_executing_command.includes("develop")) { createPage({ path: `${post.node.frontmatter.slug}/image_share`,component: BlogPostShareImage,context: { slug: post.node.frontmatter.slug,width: 440,height: 220,}) } }) markdownFiles .filter(item => item.node.fileAbsolutePath.includes("/content/pages/")) .forEach(page => { createPage({ path: page.node.frontmatter.slug,component: PageTemplate,context: { slug: page.node.frontmatter.slug,}) }) markdownFiles .filter(item => item.node.frontmatter.tags !== null) .reduce( (acc,cur) => [...new Set([...acc,...cur.node.frontmatter.tags])],[] ) .forEach(uniqTag => { createPage({ path: `tags/${uniqTag}`,component: PostsBytagTemplate,context: { tag: uniqTag,}) }) } exports.onCreateNode = ({ node,getNode }) => { const { createNodeField } = actions if (node.internal.type === `MarkdownRemark`) { const value = createFilePath({ node,getNode }) createNodeField({ name: `slug`,node,value,}) } } const parser = require('RSS-parser'); const crypto = require('crypto'); const createContentDigest = obj => crypto.createHash('md5').update(JSON.stringify(obj)).digest('hex'); function promisifiedParseURL(url) { return new Promise((resolve,reject) => { parser.parseURL(url,(err,data) => { if (err) { reject(err); } resolve(data.Feed); }); }); } const createChildren = (entries,parentId,createNode) => { const childIds = []; entries.forEach(entry => { childIds.push(entry.link); const node = Object.assign({},entry,{ id: entry.link,title: entry.title,link: entry.link,description: entry.description,parent: parentId,children: [] }); node.internal = { type: 'RSSFeedItem',contentDigest: createContentDigest(node) }; createNode(node); }); return childIds; }; async function sourceNodes({ boundActionCreators },{ RSSURL }) { const { createNode } = boundActionCreators; const data = await promisifiedParseURL(RSSURL); if (!data) { return; } const { title,description,link,entries } = data; const childrenIds = createChildren(entries,createNode); const FeedStory = { id: link,title,parent: null,children: childrenIds }; FeedStory.internal = { type: 'RSSFeed',contentDigest: createContentDigest(FeedStory) }; createNode(FeedStory); } exports.sourceNodes = sourceNodes;

还是在我模板的文件夹中?

非常感谢。

解决方法

此插件 gatsby-plugin-parse-rss 将解析来自 RSS 提要页面的信息并自动创建查询。

在您的 gatsby-config.js

中添加插件
plugins: [
  {
    resolve: "gatsby-plugin-parse-rss",options: {
      rss: [
        {
          urlToFetch:
            "https://lydra.fr/tag/froggit/feed/rss.xml",selectors: ["media:title"],name: "lydraRSS",},],];

使用 gatsby 的 useStaticQuery 检索数据

{
  allLydraRss {
    nodes {
      media_title
    }
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。