Skip to content

Templates not working on fresh Spike install #91

Open
@craigmdennis

Description

@craigmdennis

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

  1. 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
  1. spike compile
  2. npm i spike-contentful -S
  3. Add configuration from the README using the demo Contentful app
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()
}
  1. spike compile

Instead of rendering post pages, Spike outputs a single templates/post.html file, as if it were a normal page.

  1. When trying to use {{ 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions