{"id":21352058,"url":"https://github.com/static-dev/spike-datocms","last_synced_at":"2025-07-31T01:16:34.974Z","repository":{"id":57367471,"uuid":"87864287","full_name":"static-dev/spike-datocms","owner":"static-dev","description":"Spike plugin for easily consuming datocms data","archived":false,"fork":false,"pushed_at":"2018-07-27T16:44:11.000Z","size":169,"stargazers_count":15,"open_issues_count":2,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-01T12:52:44.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/static-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-10T22:43:11.000Z","updated_at":"2018-11-06T04:41:56.000Z","dependencies_parsed_at":"2022-08-23T20:10:17.495Z","dependency_job_id":null,"html_url":"https://github.com/static-dev/spike-datocms","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/static-dev/spike-datocms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fspike-datocms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fspike-datocms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fspike-datocms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fspike-datocms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/static-dev","download_url":"https://codeload.github.com/static-dev/spike-datocms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fspike-datocms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267972566,"owners_count":24174382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T03:12:25.897Z","updated_at":"2025-07-31T01:16:34.942Z","avatar_url":"https://github.com/static-dev.png","language":"JavaScript","readme":"# Spike DatoCMS Plugin\n\n[![npm](https://img.shields.io/npm/v/spike-datocms.svg?style=flat-square)](https://npmjs.com/package/spike-datocms)\n[![tests](https://img.shields.io/travis/static-dev/spike-datocms.svg?style=flat-square)](https://travis-ci.org/static-dev/spike-datocms?branch=master)\n[![dependencies](https://img.shields.io/david/static-dev/spike-datocms.svg?style=flat-square)](https://david-dm.org/static-dev/spike-datocms)\n[![coverage](https://img.shields.io/codecov/c/github/static-dev/spike-datocms.svg?style=flat-square)](https://codecov.io/gh/static-dev/spike-datocms)\n\nA quick and easy interface to DatoCMS content\n\n\u003e **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.\n\n### Installation\n\n`npm install spike-datocms -S`\n\n### Usage\n\nSometimes the best way to see how to use something is an example!\n\n```js\nconst htmlStandards = require('reshape-standard')\nconst SpikeDatoCMS = require('spike-datocms')\nconst locals = {}\n\nmodule.exports = {\n  reshape: htmlStandards({ locals }),\n  plugins: [\n    new SpikeDatoCMS({\n      addDataTo: locals,\n      token: 'xxx',\n      models: [\n        {\n          type: 'post', // if you leave this off, it will pull content from all models\n          ids: [10, 13], // (optional) only return specific records\n          query: 'foo', // (optional) text query for records\n          offset: 3, // (optional) offset results\n          limit: 10, // (optional) limit number of results returned\n          transform: record =\u003e {\n            // each record is passed through this function, if provided\n            // change it however you want and return the modified result!\n            return record\n          }\n        },\n        {\n          type: 'author'\n        }\n      ]\n    })\n  ]\n}\n```\n\nNow, in your views, you can see your records as such:\n\n```\np {{{ JSON.stringify(dato) }}}\n```\n\nOr, for example, loop through one of your models:\n\n```\nul\n  each(loop='post in dato.post')\n    li post.title\n```\n\nThis plugin will also automatically pull the meta information for the site, including the site title, SEO fields, etc. that you control via the \"Settings\" menu, and assign it as `dato._meta`. This makes it super easy to reflect CMS-controlled SEO fields in your layouts.\n\n### Single Template Render\n\nUsing the template option allows you to write records returned from Dato to single page templates. For example, if you are trying to render a blog as static, you might want each post returned from the API to be rendered as a single page by itself.\n\nThe `template` option is an object with `path` and `output` keys. The `path` is an absolute or relative path to a template to be used to render each item, and output is a function with the currently iterated item as a parameter, which should return a string representing a path relative to the project root where the single view should be rendered. For example:\n\n```js\nnew SpikeDatoCMS({\n  addDataTo: locals,\n  token: 'xxx',\n  models: [\n    {\n      name: 'posts',\n      template: {\n        path: 'templates/post.html',\n        output: post =\u003e {\n          return `posts/${post.slug}.html`\n        }\n      }\n    }\n  ]\n})\n```\n\nYour template must use the `item` variable as seen below.\n\n\u003e **Note:** Make sure your template is _not ignored_ by spike, or this functionality will not work\n\n```html\n\u003cp\u003e{{ item.title }}\u003c/p\u003e\n```\n\n### JSON Output\n\nFinally, if you'd like to have the output written locally to a JSON file so that it's cached locally, you can pass the name of the file, resolved relative to your project's output, as a `json` option to the plugin. For example:\n\n```js\nnew SpikeDatoCMS({\n  addDataTo: locals,\n  token: 'xxx',\n  models: [{ name: 'posts' }],\n  json: 'data.json'\n})\n```\n\nYou may also choose to have the output written specifically for any content type:\n\n```js\nnew SpikeDatoCMS({\n  addDataTo: locals,\n  token: 'xxx',\n  models: [\n    {\n      name: 'posts',\n\n      json: 'posts.json'\n    },\n    {\n      name: 'press',\n      id: '4Em9bQeIQxxxxxxxxx'\n      // No JSON output needed for this content type\n    }\n  ],\n  // Save all content types data in one file\n  json: 'alldata.json'\n})\n```\n\n### Aggressive Refresh\n\nBy default, this plugin will only fetch data once when you start your watcher, for development speed purposes. This means that if you change your data, you will have to restart the watcher to pick up the changes. If you are in a phase where you are making frequent data changes and would like a more aggressive updating strategy, you can set the `aggressiveRefresh` option to `true`, and your dreams will come true. However, note that this will slow down your local development, as it will fetch and link all entires every time you save a file, so it's only recommended for temporary use.\n\n### Drafts\n\nPassing `drafts: true` as an option to the plugin will make dato return the latest version of each post, rather than the published version. This is recommended in staging or development.\n\n### License \u0026 Contributing\n\n* Details on the license [can be found here](LICENSE.md)\n* Details on running tests and contributing [can be found here](contributing.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatic-dev%2Fspike-datocms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatic-dev%2Fspike-datocms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatic-dev%2Fspike-datocms/lists"}