static-dev / spike-contentful Goto Github PK
View Code? Open in Web Editor NEW:paperclip: Plugin to consume content from the CMS Contentful's API
License: Other
:paperclip: Plugin to consume content from the CMS Contentful's API
License: Other
This is because the template needs to be added to webpack. #23 aims to solve this but is having issues testing locally.
2.6.2
to 2.6.3
.This version is covered by your current version range and after updating it in your project the build failed.
rimraf is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 6 commits.
9442819
2.6.3
42fe369
autopublish scripts
21fd3df
bin test
8f1d3a1
update tap and glob for security stuff
f0bc3a1
update tap, add package-lock
692022b
travis node version updates
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Spike version: 2.2.1
Node version: 9.11.1
using NVM (have also tried 9.3.0
Demo: https://github.com/craigmdennis/example-spike-contentful
spike new example.com
? What is the name of your project? example
? Describe your project Example
? What is your github username? craigmdennis
? Would you like to use whitespace-sensitive syntax? No
? Would you like a production config file? No
spike compile
npm i spike-contentful -S
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('spike-js-standards')
const pageId = require('spike-page-id')
const env = process.env.SPIKE_ENV
const Contentful = require('spike-contentful')
const locals = {}
module.exports = {
plugins: [
new Contentful({
addDataTo: locals,
accessToken: '1e1dd64d5385d015b2e8f622f622b67c4147a812d7ab3f8146e583416009f31b',
spaceId: 'noiekra805sy',
contentTypes: [
{
name: 'posts',
id: '2wKn6yEnZewu2SCCkus4as',
template: {
path: 'templates/post.html',
output: post => {
return `posts/${post.id}.html`
}
}
}
]
})
],
devtool: 'source-map',
ignore: ['**/layout.html', '**/_*', '**/.*', 'readme.md', 'yarn.lock', 'package-lock.json'],
reshape: htmlStandards({
locals: () => locals,
minify: env === 'production'
}),
postcss: cssStandards({
minify: env === 'production',
warnForDuplicates: env !== 'production'
}),
babel: jsStandards()
}
spike compile
Instead of rendering post pages, Spike outputs a single templates/post.html
file, as if it were a normal page.
{{ item.title }}
required in the README, there is an undefined
error for item
:{ ModuleBuildError: Module build failed: TypeError: Cannot read property 'title' of undefined
at eval (eval at module.exports (/Users/craigmdennis/Sites/example.com/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:156)
at eval (eval at module.exports (/Users/craigmdennis/Sites/example.com/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:170)
at evalNode (/Users/craigmdennis/Sites/example.com/node_modules/reshape-eval-code/lib/index.js:27:70)
at util.modifyNodes (/Users/craigmdennis/Sites/example.com/node_modules/reshape-eval-code/lib/index.js:21:40)
at when.resolve.then (/Users/craigmdennis/Sites/example.com/node_modules/reshape-plugin-util/lib/index.js:26:29)
at tryCatchReject (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:592:4)
at ContinuationTask.run (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:702:24)
at Scheduler._drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:62:19)
at runLoaders (/Users/craigmdennis/Sites/example.com/node_modules/webpack/lib/NormalModule.js:195:19)
at /Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at tryCatchReject (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:804:4)
at Rejected.when (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:625:4)
at Pending.run (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:483:13)
at Scheduler._drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:62:19)
at Scheduler.drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:27:9) id: '6647cf5f' }
This is the contents of the post.html
template:
<extends src='../layout.html'>
<block name='content'>
<h1>{{ item.title }}</h1>
</block>
</extends>
JSON.stringify(post)
also causes a Module build failed: TypeError: Converting circular structure to JSON
with the default Contentful 'Blog' app. When simply referencing parts of the JSON it works fine:
<ul>
<each loop="post of contentful.posts">
<li>{{ post.fields.title }}</li>
</each>
</ul>
so getting data from Contentful is not the issue.
Let me know if I'm doing something obviously wrong. If so, I can submit a PR to update the README to clarify. Otherwise, suggestions?
The current implementation will not accept a host
value, so the preview API key will not work.
So the contentful client resolves links and references is using proxies. So if you have a circular dependency of any length (ex. post1
references post2
references post3
references post1
), the transform function, which is recursive and causes getters to resolve by walking properties directly, will end in an infinite loop.
This is something of an edge case, but it has been reported twice already, and in addition to all the other drawbacks associated with the transform function leads me to believe that it should not be true by default, and instead should be false by default, or even extracted to a separate library entirely.
Contentful used to have long confusing IDs, which made adding a name
param necessary for sanity. However, they now use camelCase slugified field names as their IDs, so I am finding myself passing an exact repetition as the name and ID. For example:
contentTypes: [
{ name: 'blogPosts', id: 'blogPosts' }
{ name: 'authors', id: 'authors' }
]
This would represent contentful's default. So I'd say if no id
is provided, it should be set equal to name
😁
Is there a way to get a total count of the entries that my page receives from contentful, and paste it into the HTML?
Hi there!
Just playing with Spike and I like the cleanliness so far. I'm trying to get a basic blog setup through contentful and I'm trying the template
option configured like so:
new Contentful({
addDataTo: locals,
accessToken: 'xxxxx',
spaceId: 'xxxxx',
contentTypes: [
{
name: 'podcasts',
id: 'podcast',
filters: {
order: 'fields.number'
},
template: {
path: 'views/_podcast.html',
output: (podcast) => `podcasts/${podcast.number}-${slug(podcast.guestName)}.html`
}
},
{
name: 'notes',
id: 'notes'
}
]
})
I have a basic template using item
as a variable in views/_podcast.html
(same directory as my index) but the output
function never runs.
I dig a little bit of digging and it keeps hitting https://github.com/static-dev/spike-contentful/blob/master/lib/index.js#L53 instead of going ahead.
templatePairs
is correct (= { 'views/_podcast.html': 0 }
) but p
is pointing to the index.html
(my only template) so it never runs the past L53. If I don't ignore my _podcast.html
template it causes an error because item
, if I ignore it ctx.resourcePath
never points to the _podcast.html
template and therefore never goes further.
Am I doing something wrong or is this broken?
Because we should have tests for every param!
Edit: Also should have docs for this in the readme. Doesn't look like there's a central spot where all the options are documented.
/cc @elvingm
What's the best way to grab more than the default locale from Contentful? https://www.contentful.com/developers/docs/concepts/locales/
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
This is probably the most edge case of edge cases, but I was trying to automatically generate multiple pages from a single content type and ran into a problem. The set up is this:
I took a wild guess and just copied the templates so each content type used its own layout and that fixed it.
Not sure if this is something that needs changed or documented, but I wanted to put this out there for thoughts.
7.0.5
to 7.0.6
.This version is covered by your current version range and after updating it in your project the build failed.
contentful is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 2 commits.
27e22f0
fix(sdk-core): Bump sdk version
4d543db
fix(docs) Add proper (absolute) links to README.md file (#286)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Right now, if you have the wrong path to a single page template, the error will be that item
doesn't exist, since the template will try to be compiled normally. The plugin should throw when it can't resolve a template path instead ✨
Trying to add this content type in the settings:
new Contentful({
addDataTo: locals,
accessToken: 'xxx',
spaceId: 'xxx',
contentTypes: [{
name: 'blogs',
id: 'blogPost'
filters: {
order: '-fields.date',
limit: 1000
}
}]
})
Throws this error:
Error: ValidationError: [spike-contentful constructor] option "contentTypes" at position 1 fails because [spike-contentful constructor] option [spike-contentful constructor] option "limit" must be less than or equal to 100
Since the Contentful API allows for up to 1000 entries (link), is there a reason this plugin limits it to 100?
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.