eleventy-plugin-cloudcannon
Advanced tools
Comparing version 0.0.10 to 0.0.11
const pkginfo = require('pkginfo')(module, 'version'); | ||
const version = module.exports.version; | ||
module.exports = function (eleventyConfig, config = {}) { | ||
const paths = { | ||
data: '_data', | ||
includes: '_includes', | ||
layouts: '_includes', | ||
...config.dir | ||
}; | ||
// defaultConfig should match the return value from https://www.11ty.dev/docs/config/ | ||
module.exports = function (eleventyConfig, defaultConfig = {}) { | ||
const config = { | ||
pathPrefix: defaultConfig.pathPrefix ?? '/', | ||
markdownItOptions: defaultConfig.markdownOptions ?? { html: true }, | ||
dir: { | ||
input: defaultConfig.dir?.input ?? '.', | ||
data: defaultConfig.dir?.data ?? '_data', // relative to input | ||
includes: defaultConfig.dir?.includes ?? '_includes', // relative to input | ||
layouts: defaultConfig.dir?.layouts ?? '_includes', // relative to input | ||
} | ||
} | ||
eleventyConfig.addFilter('ccJsonify', (obj) => obj ? JSON.stringify(obj) : null); | ||
eleventyConfig.addNunjucksShortcode('ccConfigPath', (key) => paths[key] ?? ''); | ||
eleventyConfig.addNunjucksShortcode('ccPathPrefix', () => config.pathPrefix ?? ''); | ||
eleventyConfig.addNunjucksShortcode('ccInput', () => config.input ?? ''); | ||
eleventyConfig.addNunjucksShortcode('ccPath', (key) => (config.dir[key] ?? '').replace(/^\.\/?/, '')); | ||
eleventyConfig.addNunjucksShortcode('ccConfig', (key) => JSON.stringify(config[key] ?? '')); | ||
eleventyConfig.addNunjucksShortcode('ccVersion', () => version); | ||
eleventyConfig.addFilter('ccJsonify', (obj) => { | ||
try { | ||
return JSON.stringify(obj); | ||
} catch { | ||
console.warn('eleventy-plugin-cloudcannon: failed to JSON.stringify'); | ||
} | ||
return null; | ||
}); | ||
}; |
@@ -77,11 +77,19 @@ const { dirname, basename } = require('path'); | ||
return { | ||
const processed = { | ||
...combinedData, | ||
path: item.inputPath.replace('./', ''), | ||
path: item.inputPath.replace(/^\.\//, ''), | ||
url: item.url || '', | ||
collection: tag, | ||
layout: item.template._layoutKey, | ||
_unlisted: isUnlisted(item), | ||
output: item.url !== false | ||
}; | ||
if (item.template?._layoutKey) { | ||
processed.layout = item.template._layoutKey; | ||
} | ||
if (isUnlisted(item)) { | ||
processed._unlisted = true; | ||
} | ||
return processed; | ||
}, | ||
@@ -88,0 +96,0 @@ |
@@ -5,3 +5,3 @@ const pluginCloudCannon = require('eleventy-plugin-cloudcannon'); | ||
// Adds the cloudcannon plugin after running the renamed default config file | ||
module.exports = function (eleventyConfig, config = {}) { | ||
module.exports = function (eleventyConfig) { | ||
let defaultConfig; | ||
@@ -15,12 +15,4 @@ | ||
defaultConfig?.apply(this, arguments); | ||
const paths = { | ||
data: '_data', | ||
includes: '_includes', | ||
layouts: '_includes', | ||
...(config.dir ?? {}) | ||
}; | ||
eleventyConfig.addPlugin(pluginCloudCannon); | ||
const config = defaultConfig?.apply(this, arguments); | ||
eleventyConfig.addPlugin(pluginCloudCannon, eleventyConfig.cloudcannonOptions ?? config); | ||
}; |
{ | ||
"name": "eleventy-plugin-cloudcannon", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Eleventy plugin to create CloudCannon editor details", | ||
@@ -5,0 +5,0 @@ "main": ".eleventy.js", |
@@ -10,2 +10,37 @@ # Eleventy Plugin CloudCannon | ||
### CloudCannon | ||
By default, CloudCannon automatically injects this plugin before your site is built. You can | ||
disable this if you want to maintain the plugin versioning yourself or you experience issues. | ||
Disabling the automatic injection prevents the templates being copied. In order to retain this, | ||
you may wish to add the following to your `_cloudcannon-prebuild.sh`: | ||
``` | ||
rm -rf cloudcannon | ||
cp -R node_modules/eleventy-plugin-cloudcannon/cloudcannon . | ||
``` | ||
If you use custom paths for your site, pass them to the plugin in the `cloudcannonOptions` key | ||
within your `.eleventy.js` file: | ||
``` | ||
module.exports = function (eleventyConfig) { | ||
const config = { | ||
pathPrefix: '/', | ||
dir: { | ||
input: '.', | ||
data: '_my-custom-data', | ||
layouts: '_layouts', | ||
includes: '_my-includes' | ||
} | ||
}; | ||
eleventyConfig.cloudcannonOptions = config; | ||
return config; | ||
}; | ||
``` | ||
### Manual | ||
Available on [npm](https://www.npmjs.com/package/eleventy-plugin-cloudcannon). | ||
@@ -17,4 +52,3 @@ | ||
Add the following `addPlugin` call to your `module.exports` function in the Eleventy config file | ||
(`.eleventy.js` by default): | ||
Add the following `addPlugin` call to the `module.exports` function in your `.eleventy.js` file: | ||
@@ -25,7 +59,7 @@ ``` | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(pluginCloudCannon, options); | ||
eleventyConfig.addPlugin(pluginCloudCannon); | ||
}; | ||
``` | ||
If you set custom `dir` values for your site, pass them to the plugin as well: | ||
If you use custom paths for your site, pass them to the plugin as well: | ||
@@ -37,3 +71,5 @@ ``` | ||
const config = { | ||
pathPrefix: '/', | ||
dir: { | ||
input: '.', | ||
data: '_my-custom-data', | ||
@@ -46,3 +82,2 @@ layouts: '_layouts', | ||
eleventyConfig.addPlugin(pluginCloudCannon, config); | ||
return config; | ||
@@ -52,25 +87,21 @@ }; | ||
To ensure your site stays up to date with future plugin versions, add the following to your `_cloudcannon-prebuild.sh`: | ||
## Options | ||
``` | ||
nvm use 14 | ||
npm update eleventy-plugin-cloudcannon | ||
npm install | ||
rm -rf cloudcannon | ||
cp -R node_modules/eleventy-plugin-cloudcannon/cloudcannon . | ||
``` | ||
The options are either set on the `eleventyConfig.cloudcannonOptions` key within your | ||
`.eleventy.js` file, or passed to the `addPlugin` call as a second argument if you are adding the | ||
plugin manually. | ||
## Options | ||
Should match the return value from your `.eleventy.js` (https://www.11ty.dev/docs/config/) file. | ||
All optional, including the argument itself. | ||
Matches what you set or return in your main config. All optional, including the parameter itself. | ||
| Key | Type | Default | Description | | ||
| ------------------- | ------ | ---------------------------------------------------------------------------- | ----------------------------------- | | ||
| `pathPrefix` | string | `'/'` | `pathPrefix` setting your site uses | | ||
| `dir` | object | `{ input: '.', data: '_data', includes: '_includes', layouts: '_includes' }` | Custom paths your site uses | | ||
| `markdownItOptions` | object | `{ html: true }` | Options passed to markdown-it | | ||
| Key | Type | Default | Description | | ||
| ------------ | ------ | ---------------------------------------------------------------- | ---------------------------------------- | | ||
| `pathPrefix` | string | `''` | Custom pathPrefix setting your site uses | | ||
| `input` | string | `'.'` | Custom input path your site uses | | ||
| `dir` | object | `{ data: '_data', includes: '_includes', layouts: '_includes' }` | Custom paths your site uses (if any) | | ||
## Data | ||
This plugin reads data from `cloudcannon` if available (defaults to `_data/cloudcannon.json` or `_data/cloudcannon.js`). | ||
This plugin reads data from `cloudcannon` if available (defaults to `_data/cloudcannon.json` or | ||
`_data/cloudcannon.js`). | ||
@@ -106,2 +137,3 @@ Details on each property here are listed in the relevant parts of the | ||
"_editor": {}, | ||
"_collection_groups": null, | ||
"_source_editor": {}, | ||
@@ -108,0 +140,0 @@ "_array_structures": {}, |
Sorry, the diff of this file is not supported yet
14304
150
142