-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: content in sub folders #2897
Conversation
Question: do we need the |
That would make it a breaking change I think |
Would a site structure like the following also be handled by this?
|
I think you'll need to set up two collections, one for the |
Uhh, that's so not nice TBH. Creating a site hierarchy is part of the editors' work (not developers) and should not depend on changing the cms config. |
Actually this might be possible with a single collection if you use a field with the slug template. Another improvement will be to preview the destination path in the UI (like suggested in the issue thread). |
Ok, I will give it a try. Thank you. :) |
@erezrokah path preview: And of course would need some UI improvements. |
984a745
to
d4e71ee
Compare
@@ -55,6 +56,7 @@ export default class ControlPane extends React.Component { | |||
|
|||
return ( | |||
<ControlPaneContainer> | |||
{collection.has('path') && <PathPreview collection={collection} entry={entry} />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if the path preview can come immediately before the identifier
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea I'll update it
try { | ||
// slugFormatter throws in case an identifier is missing from the entry | ||
// we can safely ignore this error as this is just a preview path value | ||
return slugFormatter(collection, entry.get('data'), config.get('slug')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to add the file extension.
@@ -186,6 +186,22 @@ export default class GraphQLAPI extends API { | |||
} | |||
} | |||
|
|||
addFiles(allFiles, entries, path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array reduce would be more cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking something like so:
function addFiles(entries, path) {
return entries.reduce((acc, item) => {
if (item.type === 'tree') {
return [...acc, ...addFiles(item.object.entries, `${path}/${item.name}`)];
}
return [
...acc,
{
...item,
path: `${path}/${item.name}`,
size: item.blob && item.blob.size
}
];
}, []);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool
36eceaf
to
9f0dd4e
Compare
@@ -92,17 +93,47 @@ export const statues = gql` | |||
${fragments.object} | |||
`; | |||
|
|||
const buildFilesQuery = (depth = 10) => { | |||
const PLACE_HOLDER = 'PLACE_HOLDER'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking with the PLACE_HOLDER
👍
BREAKING CHANGE: non template parts of the slug will not be sanitized
451661f
to
10ad13d
Compare
Two issues with displaying the path:
What’s more likely to be sought by an editor is the resulting URL path. We could handle this in a separate issue/PR and make some product decisions there. What do you all think, agree/disagree? Sent with GitHawk |
I agree the preview is very raw atm. Having the resulting URL path sounds much better |
Removed the path preview completely for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Killer work, Erez 💪 - let's test for the possible breaking change you mentioned, but I'm good with merging and publishing to beta as is.
Actually, second thought, I'm going to hold off on releasing since we're going into holiday, and many have come to depend on our long lived beta channel not breaking. If folks here really want to play with it over the next couple of days, make some noise. |
I think many people, including me, are waiting for this feature. So please publish it 😊💪🏻🔥🚀 |
Yes please, would like to test it |
Can this be turned off? It sort of broke my content organization. |
Edit: rephrased I have a repo structured like this:
etc... and the following collection configuration (irrelevant fields not listed): - folder: "/"
slug: "{{slug}}"
path: "{{slug}}/index"
media_folder: ""
public_folder: "" Is it the intended way to use this feature? If not, how should I author on netlify cms with this structure? I tried using the feature without success of course. Description of what happened below if you're interested. ------- Here is the experiment results ---------- Expected behavior: Lists entries like "blog 1", "blog 2", etc. Actual behavior: Produced something like this: Before going any further though, I do understand the empty entries are media files. I probably need to filter them. The problem is: every time I scrolled to the bottom, all entries with text updated to the same name it happened to load from the last request. Such entries all have the link `https://example.com/#/collections/bites/entries/index My uneducated guess was the "/index" I wrote in Thank you! |
Hi @huguestennier, I would suggest moving your content into a dedicated directory, e.g. - folder: "content"
slug: "{{slug}}"
path: "{{slug}}/index"
media_folder: ""
public_folder: "" If that doesn't work I suggest opening a new issue for it. |
Thank you @erezrokah ! It works if I put contents in a subfolder :) I don't even have to filter media files! Amazing work! |
Fixes: #513
Still work in progress, though I tested with github/gitlab/bitbucket.Enable it by addingcontent_in_sub_folders: true
to your folder collection (still need to write the documentation).By enabling the flag slashes will not be sanitized and will be used for directory structure.
e.g doing:
The
slug
option remains the same.You can add a
path
template for a collection similar to the slug generation template:Will result in the file saved in
posts/2019/11-19-title.md
for example.TODO:
path
config instead ofcontent_in_sub_folders
and keep slug behaviourThings to consider:
Further improvements (I think they should be done in another PR):
internally we should not use
slug
in our redux store (and everywhere else for that matter). We should use the entry full path and just URI encode it to make sure it doesn't break the routing.We should also not reference the term slug in the backends (specifically the GitHub one).