Skip to content

Commit

Permalink
Merge pull request #10 from CloudCannon/jekyll/pages-in-subfolder
Browse files Browse the repository at this point in the history
Jekyll: handle when pages only in subfolder
  • Loading branch information
bglw authored Aug 28, 2024
2 parents 75a7768 + 258448f commit b1dbbeb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function findIcon(query) {

/** @type {Record<string, import('@cloudcannon/configuration-types').Icon>} */
const overrides = {
collection_pages: 'web_asset',
pages: 'wysiwyg',
posts: 'event_available',
post: 'event_available',
Expand Down
3 changes: 2 additions & 1 deletion src/ssgs/jekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default class Jekyll extends Ssg {
ignoredFolders() {
return super.ignoredFolders().concat([
'_site/', // build output
'assets/', // popular assets plugin folder
'.jekyll-cache/', // cache
'.jekyll-metadata/', // cache
]);
Expand Down Expand Up @@ -240,7 +241,7 @@ export default class Jekyll extends Ssg {
const path = stripTopPath(fullPath, options?.source);

const isDefaultCollection =
path === '' ||
path === sortedPaths[0] || // root folder, or a subfolder if no content files in root
path === '_data' ||
path.startsWith('_data/') ||
path === '_posts' ||
Expand Down
18 changes: 13 additions & 5 deletions src/ssgs/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ export default class Ssg {
'tsconfig.json',
'jsconfig.json',
'.prettierrc.json',
'docker-compose.yml',
'docker-compose.nginx.yml',
'package-lock.json',
'package.json',
'netlify.toml',
'vercel.json',
'manifest.json',
'.gitignore',
'README',
Expand Down Expand Up @@ -218,9 +222,13 @@ export default class Ssg {
*/
isIgnoredPath(filePath) {
return (
filePath.includes('.config.') ||
filePath.includes('/.') ||
filePath.startsWith('.') ||
this.ignoredFolders().some(
(folder) => filePath.startsWith(folder) || filePath.includes(`/${folder}`),
) || this.ignoredFiles().some((file) => filePath === file || filePath.endsWith(`/${file}`))
) ||
this.ignoredFiles().some((file) => filePath === file || filePath.endsWith(`/${file}`))
);
}

Expand Down Expand Up @@ -266,6 +274,10 @@ export default class Ssg {
* @returns {import('../types').FileType}
*/
getFileType(filePath) {
if (this.isConfigPath(filePath)) {
return 'config';
}

if (this.isIgnoredPath(filePath)) {
return 'ignored';
}
Expand All @@ -274,10 +286,6 @@ export default class Ssg {
return 'partial';
}

if (this.isConfigPath(filePath)) {
return 'config';
}

if (this.isContentPath(filePath)) {
return 'content';
}
Expand Down
4 changes: 4 additions & 0 deletions toolproof_tests/jekyll/base.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ steps:
collections:
- staff
- data
- step: I have a "src/.somethingconfig.yml" file with the content {yaml}
yaml: ''
- step: I have a "src/another/folder/something.config.yml" file with the content {yaml}
yaml: ''
- step: I have a "src/collections/_posts/1999-12-31-partying.md" file with the content {md}
md: |-
---
Expand Down
47 changes: 47 additions & 0 deletions toolproof_tests/jekyll/page-in-subfolder.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Jekyll with one page in a subfolder of root

steps:
- step: I have a "src/_config.yml" file with the content {yaml}
yaml: ''
- step: I have a "src/webpages/index.html" file with the content {html}
html: |-
---
permalink: /
---
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Home</h1>
<p>Hello.</p>
</body>
</html>
- ref: ./../core/run_gadget.toolproof.yml
- snapshot: stdout
snapshot_content: |-
╎{
╎ "ssg": "jekyll",
╎ "config": {
╎ "collections_config": {
╎ "webpages": {
╎ "path": "webpages",
╎ "name": "Webpages",
╎ "icon": "pages",
╎ "output": false
╎ }
╎ },
╎ "timezone": "Pacific/Auckland",
╎ "markdown": {
╎ "engine": "kramdown",
╎ "options": {
╎ "heading_ids": false,
╎ "gfm": false,
╎ "breaks": false,
╎ "typographer": false,
╎ "treat_indentation_as_code": true
╎ }
╎ }
╎ }
╎}

0 comments on commit b1dbbeb

Please sign in to comment.