Skip to content

Commit

Permalink
Add posts/drafts _inputs for Jekyll, disable file actions for data co…
Browse files Browse the repository at this point in the history
…llections
  • Loading branch information
rphillips-cc committed Sep 11, 2024
1 parent 6d5af02 commit 4d4f23d
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/ssgs/eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export default class Eleventy extends Ssg {

if (path === '_data' || path.endsWith('/_data')) {
collectionConfig.disable_url = true;
collectionConfig.disable_add = true;
collectionConfig.disable_add_folder = true;
collectionConfig.disable_file_actions = true;
}

return collectionConfig;
Expand Down
3 changes: 3 additions & 0 deletions src/ssgs/hugo.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export default class Hugo extends Ssg {

if (path === dataPath || path.endsWith(`/${dataPath}`)) {
collectionConfig.disable_url = true;
collectionConfig.disable_add = true;
collectionConfig.disable_add_folder = true;
collectionConfig.disable_file_actions = true;
}

return collectionConfig;
Expand Down
40 changes: 38 additions & 2 deletions src/ssgs/jekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ function toPostsKey(key) {
return key.replace('drafts', 'posts');
}

/**
* Generates posts _inputs configuration.
*
* @param collectionKey {string} The posts key.
* @returns {Record<string, import('@cloudcannon/configuration-types').Input>}
*/
function generatePostsInputs(collectionKey) {
return {
categories: {
type: 'multiselect',
options: {
values: `collections.${collectionKey}[*].categories`,
allow_create: true,
},
},
tags: {
type: 'multiselect',
options: {
values: `collections.${collectionKey}[*].tags`,
allow_create: true,
},
},
};
}

/**
* Gets `collections` from Jekyll configuration in a standard format.
*
Expand Down Expand Up @@ -137,7 +162,12 @@ export default class Jekyll extends Ssg {
key === 'drafts' ||
key.endsWith('_drafts');

if (key === 'data' || (!options.collection?.output && !isKnownOutputCollection)) {
if (key === 'data') {
collectionConfig.disable_url = true;
collectionConfig.disable_add = true;
collectionConfig.disable_add_folder = true;
collectionConfig.disable_file_actions = true;
} else if (!options.collection?.output && !isKnownOutputCollection) {
collectionConfig.disable_url = true;
}

Expand All @@ -150,15 +180,21 @@ export default class Jekyll extends Ssg {
path: '[relative_base_path]/{date|year}-{date|month}-{date|day}-{title|slugify}.[ext]',
};

collectionConfig._inputs = generatePostsInputs(key);

collectionConfig.add_options ||= [
{ name: `Add ${collectionConfig.singular_name || 'Post'}` },
{ name: 'Add Draft', collection: toDraftsKey(key) },
];
} else if (isDraftsPath(collectionConfig.path)) {
const postsKey = toPostsKey(key);

collectionConfig.create ||= {
path: '', // TODO: this should not be required if publish_to is set
publish_to: toPostsKey(key),
publish_to: postsKey,
};

collectionConfig._inputs = generatePostsInputs(postsKey);
}

return collectionConfig;
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/eleventy/base.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ steps:
β•Ž "path": "_data",
β•Ž "name": "Data",
β•Ž "icon": "data_usage",
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/eleventy/subfolder-source.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ steps:
β•Ž "path": "_data",
β•Ž "name": "Data",
β•Ž "icon": "data_usage",
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/eleventy/templates-in-source.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ steps:
β•Ž "path": "_data",
β•Ž "name": "Data",
β•Ž "icon": "data_usage",
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/hugo/base.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ steps:
β•Ž "glob": [
β•Ž "!_index.md"
β•Ž ],
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/hugo/data-dir.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ steps:
β•Ž "glob": [
β•Ž "!_index.md"
β•Ž ],
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/hugo/data-only.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ steps:
β•Ž "glob": [
β•Ž "!_index.md"
β•Ž ],
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/hugo/example-site-only.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ steps:
β•Ž "glob": [
β•Ž "!_index.md"
β•Ž ],
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
5 changes: 4 additions & 1 deletion toolproof_tests/hugo/subfolder-source.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ steps:
β•Ž "glob": [
β•Ž "!_index.md"
β•Ž ],
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž }
β•Ž },
β•Ž "timezone": "Pacific/Auckland",
Expand Down
69 changes: 68 additions & 1 deletion toolproof_tests/jekyll/base.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ steps:
β•Ž "create": {
β•Ž "path": "",
β•Ž "publish_to": "posts"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž }
β•Ž },
β•Ž "news_drafts": {
Expand All @@ -99,6 +115,22 @@ steps:
β•Ž "create": {
β•Ž "path": "",
β•Ž "publish_to": "news_posts"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž }
β•Ž },
β•Ž "news_posts": {
Expand All @@ -108,6 +140,22 @@ steps:
β•Ž "create": {
β•Ž "path": "[relative_base_path]/{date|year}-{date|month}-{date|day}-{title|slugify}.[ext]"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž },
β•Ž "add_options": [
β•Ž {
β•Ž "name": "Add Post"
Expand All @@ -125,6 +173,22 @@ steps:
β•Ž "create": {
β•Ž "path": "[relative_base_path]/{date|year}-{date|month}-{date|day}-{title|slugify}.[ext]"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž },
β•Ž "add_options": [
β•Ž {
β•Ž "name": "Add Post"
Expand All @@ -145,7 +209,10 @@ steps:
β•Ž "path": "_data",
β•Ž "name": "Data",
β•Ž "icon": "data_usage",
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž },
β•Ž "data_animals": {
β•Ž "path": "_data/animals",
Expand Down
69 changes: 68 additions & 1 deletion toolproof_tests/jekyll/default-collections.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ steps:
β•Ž "create": {
β•Ž "path": "",
β•Ž "publish_to": "posts"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž }
β•Ž },
β•Ž "news_drafts": {
Expand All @@ -35,6 +51,22 @@ steps:
β•Ž "create": {
β•Ž "path": "",
β•Ž "publish_to": "news_posts"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž }
β•Ž },
β•Ž "news_posts": {
Expand All @@ -44,6 +76,22 @@ steps:
β•Ž "create": {
β•Ž "path": "[relative_base_path]/{date|year}-{date|month}-{date|day}-{title|slugify}.[ext]"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.news_posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž },
β•Ž "add_options": [
β•Ž {
β•Ž "name": "Add Post"
Expand All @@ -61,6 +109,22 @@ steps:
β•Ž "create": {
β•Ž "path": "[relative_base_path]/{date|year}-{date|month}-{date|day}-{title|slugify}.[ext]"
β•Ž },
β•Ž "_inputs": {
β•Ž "categories": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].categories",
β•Ž "allow_create": true
β•Ž }
β•Ž },
β•Ž "tags": {
β•Ž "type": "multiselect",
β•Ž "options": {
β•Ž "values": "collections.posts[*].tags",
β•Ž "allow_create": true
β•Ž }
β•Ž }
β•Ž },
β•Ž "add_options": [
β•Ž {
β•Ž "name": "Add Post"
Expand All @@ -75,7 +139,10 @@ steps:
β•Ž "path": "_data",
β•Ž "name": "Data",
β•Ž "icon": "data_usage",
β•Ž "disable_url": true
β•Ž "disable_url": true,
β•Ž "disable_add": true,
β•Ž "disable_add_folder": true,
β•Ž "disable_file_actions": true
β•Ž },
β•Ž "data_animals": {
β•Ž "path": "_data/animals",
Expand Down
Loading

0 comments on commit 4d4f23d

Please sign in to comment.