Closed majorminors closed 4 years ago
Interesting, I don't know if we've ever come across this use case before. It should be a straightforward fix, we're already filtering out files that start with _
so just checking for .
too will probably do it. I'll take a closer look this week.
Oh fabulous. I looked myself to see if I could fix it, but I'm not super familiar with PHP, so I couldn't make much out of the CollectionDataLoader.php
file. Apologies.
Actually, can you try filtering out .git
directly? Something like this:
'filter' => function ($item) {
return $item->filename != '.git';
}
Same error.
Although, just noticing how I'm dealing with the filename parameter for path:
'path' => '{collection}/{filename}',
Do I need to wrap it?
I'm trying to reproduce this locally and when there's a .git
directory everything works fine, but if I make a file called .git
I get your error. Can you make sure the specific path causing that error is in fact a valid Git directory?
If it is can you post your whole config for that collection so I can keep troubleshooting?
Thanks.
It's not a directory. I believe newer versions of git collate submodule git directories at the root under /.git/modules
. The .git
file in the submodule directory just contains a reference to that location e.g.:
#/source/_articles/.git
gitdir: ../../.git/modules/source/_articles
Here's my config:
<?php
return [
'baseUrl' => '',
'production' => false,
'siteName' => 'The Armchair Collective',
'siteDescription' => 'Turning scholarship into wisdom we can use',
'siteAuthor' => 'Dorian Minors',
// collections
'collections' => [
'articles' => [ // this is a submodule
'author' => 'Dorian Minors', // Default author, if not provided in an article
'sort' => '-date',
'path' => '{collection}/{filename}',
'description' => 'excerpt',
],
'missives' => [ // this is also a submodule
'sort' => '-date',
'path' => '{collection}/{filename}',
],
//'authors' => [
// 'path' => '{collection}/{filename}', // author article collation on author template page
//],
'series' => [
'path' => '{collection}/{filename}',
'articles' => function ($page, $allArticles) {
return $allArticles->filter(function ($article) use ($page) {
return $article->series ? in_array($page->getFilename(), $article->series, true) : false;
});
},
],
'themes' => [
'path' => '{collection}/{filename}',
'articles' => function ($page, $allArticles) {
return $allArticles->filter(function ($article) use ($page) {
return $article->themes ? in_array($page->getFilename(), $article->themes, true) : false;
});
},
],
'projects' => [
'path' => '{collection}/{filename}',
'articles' => function ($page, $allArticles) {
return $allArticles->filter(function ($article) use ($page) {
return $article->projects ? in_array($page->getFilename(), $article->projects, true) : false;
});
},
],
],
// helpers
'getDate' => function ($page) {
return Datetime::createFromFormat('U', $page->date);
},
'getExcerpt' => function ($page, $length = 255) {
if ($page->excerpt) {
return $page->excerpt;
}
$content = preg_split('/<!-- more -->/m', $page->getContent(), 2);
$cleaned = trim(
strip_tags(
preg_replace(['/<pre>[\w\W]*?<\/pre>/', '/<h\d>[\w\W]*?<\/h\d>/'], '', $content[0]),
'<code>'
)
);
if (count($content) > 1) {
return $content[0];
}
$truncated = substr($cleaned, 0, $length);
if (substr_count($truncated, '<code>') > substr_count($truncated, '</code>')) {
$truncated .= '</code>';
}
return strlen($cleaned) > $length
? preg_replace('/\s+?(\S+)?$/', '', $truncated) . '...'
: $cleaned;
},
'isActive' => function ($page, $path) {
return ends_with(trimPath($page->getPath()), trimPath($path));
},
];
Thanks a lot! I didn't realize submodules worked that way and I assumed it was supposed to be a directory. The .git
file is definitely the issue.
I'll look at adding a check to ignore files starting with .
(or maybe just named .git
), I just want to make sure there's no way it'll break existing sites. @damiani thoughts?
expected behaviour
If
.git
is present in a collection folder, the build process ignores it.actual behaviour
If
.git
is present in a collection folder, the build process does not finish.detail and notes
I've abstracted my articles to a separate git repo, and pulled them into the jigsaw project as a git submodule. I just noticed that the local build seems to error and I am assuming this is because it doesn't like the
.git
in thesource/_articles
directory. See the printout from npm run watch:Assuming this isn't something I've broken, let me know if there's anything I can do to help troubleshoot.
Warm regards,
Dorian