markmichon / gatsby-plugin-feed-generator Goto Github PK
View Code? Open in Web Editor NEWJSON Feed and RSS Feed Generator for Gatsby
JSON Feed and RSS Feed Generator for Gatsby
This could really use some tests so a running Gatsby site doesn't need to be used as a sandbox.
Currently the plugin relies heavily on the use and structure of allMarkdownRemark and it's graphql structure. It would be ideal if this could be abstracted out into the config to allow for other formats, and in the future combining multiple formats into a single feed.
Remove hardcoded values and abstract out to customizable plugin options
Currently relative links in the content are left as is. Per gaearon/overreacted.io#65
I'm not convinced the hacky solution is the best, and it probably needs to be behind a setting for users that are using absolute links in their output.
Support should mirror gatsby's approach via pathPrefix
in gatsby-config, however it looks like withPrefix
will be deprecated in Gatsby v3, so allowing users to set custom prefixes for each feed to allow something like the following would be better: sitename.com/blog
, sitename.com/photos
, etc.
This can currently be achieved by prefixing the name of the feed in the config, so it may be better to document that instead of building out functionality before Gatsby makes changes.
Looks like there is an issue with expecting regeneratorRuntime/v2:
error Plugin gatsby-plugin-feed-generator returned an error
ReferenceError: regeneratorRuntime is not defined
I have multiple feeds being generated. but all of those links are added to header section automatically, how can i disable this?
Add functionality for links to be added directly to the head via the ssr file.
I'm suddenly seeing the feeds and feed links not being generated on gatsby 2.15.20 / gatsby-plugin-feed-generator 2.0.3, but I'm also not seeing any errors. My config looks like this:
{
resolve: "gatsby-plugin-feed-generator",
options: {
siteQuery: `
{
site {
siteMetadata {
title
description
siteUrl
author
}
}
}
`,
feeds: [
{
name: 'feed',
query: `
{
allMarkdownRemark(
filter: { frontmatter: { templateKey: { eq: "post" }, published: { eq: true } } },
sort: { order: DESC, fields: [frontmatter___date] }
) {
edges {
node {
html
id
frontmatter {
date
path
title
}
}
}
}
}
`,
normalize: ({ query: { site, allMarkdownRemark } }) => {
return allMarkdownRemark.edges.map(edge => {
return {
title: edge.node.frontmatter.title,
date: edge.node.frontmatter.date,
url: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
html: edge.node.html,
}
})
},
}
],
},
},
Is possible to add enclosure to the feed?
Testing on a simple query with frontmatter fields title
and slug
.
Trying to build produced the following error:
error Plugin gatsby-plugin-feed-generator returned an error
RangeError: Invalid time value
- Date.toISOString
- json.js:51
[gatsby-test]/[feed]/lib/json.js:51:48
- Array.map
- json.js:33 Object.exports.default
[gatsby-test]/[feed]/lib/json.js:33:24
- feed.js:19 Feed.json1
[gatsby-test]/[feed]/lib/feed.js:19:57
- gatsby-node.js:71 _loop$
[gatsby-test]/[gatsby-plugin-feed-generator]/gatsby-node.js:71:117
In a couple places in gatsby-node
this is employed:
path.join(siteUrl, slug),
If siteUrl
is a fully qualified URL with a schema, such as https://www.example.org/
, this has the undesirable effect of treating the schema-host separator as a path divider:
// output => https:/www.example.org/[slug]
There are some other “url join” libraries out there; I resolved by doing the following instead:
const url = {
join: (...parts) => {
let result = "" + parts.shift()
parts.forEach(part => {
const trailingSlashPresent = result.charAt(result.length - 1) == "/"
const preceedingSlashPresent = part.charAt(0) == "/"
if (trailingSlashPresent) {
if (preceedingSlashPresent) {
result = result + part.substr(1)
} else {
result = result + part
}
} else {
if (preceedingSlashPresent) {
result = result + part
} else {
result = result + "/" + part
}
}
})
return result;
}
}
Then when referencing URLs:
url.join(siteUrl, "something", "/something-else")
Is is possible to combine multiple queries into one generated feed?
Example below, pulling data from Contentful.
{
resolve: 'gatsby-plugin-feed-generator',
options: {
generator: `GatsbyJS`,
rss: false, // Set to true to enable rss generation
json: true, // Set to true to enable json feed generation
siteQuery: `
{
site {
siteMetadata {
title
description
siteUrl
author
}
}
}
`,
feeds: [
{
name: 'feed',
query: `
{
allContentfulPost(sort: { fields: [publishDate], order: DESC }, limit: 1) {
edges {
node {
title
id
slug
publishDate(formatString: "MMMM DD, YYYY")
}
}
}
},
{
allContentfulPhotography(sort: { fields: [publishDate], order: DESC }, limit: 1) {
edges {
node {
title
id
slug
publishDate(formatString: "MMMM DD, YYYY")
}
}
}
}
`,
normalize: ({ query: { site, allContentfulPost, allContentfulPhotography } }) => {
return [allContentfulPost, allContentfulPhotography].edges.map(edge => {
return {
title: edge.node.title,
url: site.siteMetadata.siteUrl + '/' + edge.node.slug,
date: edge.node.publishDate,
}
})
},
},
It works when running gatsby develop
, but it fails when running gatsby build
.
ERROR #11321 PLUGIN
"gatsby-plugin-feed-generator" threw an error while running the onPostBuild lifecycle:
Cannot read property 'edges' of undefined
55 | feedQuery = _context.sent;
56 | query = (0, _extends3.default)({}, siteQuery, feedQuery);
> 57 | feedItems = feed.normalize({ query: query });
| ^
58 | output = (0, _utils.buildFeed)((0, _extends3.default)({
59 | site: site,
60 | items: feedItems,
File: node_modules/gatsby-plugin-feed-generator/gatsby-node.js:57:40
TypeError: Cannot read property 'edges' of undefined
- gatsby-config.js:83 Object.normalize
/Users/iammatthias/Sites/gatsby/net/gatsby-config.js:83:31
- gatsby-node.js:57 _loop$
[net]/[gatsby-plugin-feed-generator]/gatsby-node.js:57:40
- runMicrotasks
- task_queues.js:97 processTicksAndRejections
internal/process/task_queues.js:97:5
not finished onPostBuild - 0.047s
I am currently generating multiple feeds in my Gatsby Config file: https://github.com/iammatthias/.com/blob/master/gatsby-config.js#L37 This works, but introduces the need to pull multiple feeds in a microblog project. If possible, I would like to combine the gatsby-plugin-feed-generator
output into a single feed that provides information across my entire site.
When gasby develop
'ing with this plugin, I'm seeing
Warning: Each child in an array or iterator should have a unique "key" prop.
Check the top-level render call using <head>. See https://fb.me/react-warning-keys for more information.
in link
in HTML
... in the terminal. A possible workaround might be to add data-react-helmet="true"
to the <link>
tags generated in gatsby-ssr.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.