Skip to content

Commit

Permalink
Merge pull request #19 from CloudCannon/feat/jekyll-posts-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
georgephillips authored Sep 11, 2024
2 parents 6d5af02 + 4d4f23d commit eafa59c
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 eafa59c

Please sign in to comment.