Skip to content
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

Enhancement: Link a page folder to a content type #360

Closed
estruyf opened this issue Jun 14, 2022 · 12 comments
Closed

Enhancement: Link a page folder to a content type #360

estruyf opened this issue Jun 14, 2022 · 12 comments
Labels
enhancement New feature or request Project: v8.2.0

Comments

@estruyf
Copy link
Owner

estruyf commented Jun 14, 2022

In some cases, a content type will only be used for a specific page folder. For example: the blog content type will be used for posts page folders.

It would be helpful to link the page folder to the content type, that way, while creating new content, Front Matter will not require to ask where the content needs to be created.

@estruyf estruyf added the enhancement New feature or request label Jun 14, 2022
@bwklein
Copy link

bwklein commented Jun 14, 2022

I had this exact same setup thought yesterday. My instinct was to try to set a list of content types per location. One or more options for what kind of content would go into a particular folder.
Then when making new content, I would first choose the content location/path and from that choice which content type to put in there.

@estruyf
Copy link
Owner Author

estruyf commented Jun 14, 2022

@bwklein would you rather have the folder to define which content type to use in it? Or would you define the folder on content type?

Both are possible, maybe defining it on content type level is more straightforward.

@zivbk1
Copy link

zivbk1 commented Jun 14, 2022

I have a site where I have more than one content type in the same folder.
So as long as I can specify what I want to make and where it should be placed, it doesn't really make a difference which order I do it in.
Either way in terms of the configuration of the folders for a content type, or the content types for a folder, the entries will probably have to be an array. So that there can be more than one destination for a type or types for a destination.

@estruyf
Copy link
Owner Author

estruyf commented Jun 15, 2022

Just some use cases:

Setting the folder link to the content type

When the property would be set on the content type, the question to create content should be in the following order:

  1. What type of content do you wish to create?
  2. Where do you want to create it?

The second question is based on the property. If present, it will skip it, and create the content, if present, it will create it in the corresponding folder.

If you want to use the content type for multiple folders, you should not be setting the property on the content type. That way you have the same experience as to how it is right now.

Disadvantage: This might limit the content type. If you have multiple folders with similar content types. You'll have to recreate the content type for each folder or unset the value. Another solution would be to specify multiple folders.

Setting the content type for a page folder

When the property would be set on the page folder level, the order of questions stays the same as they are right now.

  1. Where do you want to create the content?
  2. Which type of content do you want to create?

In this case, the second question is yet again based on what is defined in the location setting of the previous question. If a content type link is set, the type of content does not need to be defined anymore.

When setting it on the folder level, you are still able to use the content type for any folder that is not using the content type link.

Disadvantage: Limits one type of content per folder. Although, this limitation is less impactful than setting it on the content type level. We could also allow setting one or more content types on the page folder level. That way, if one is defined, the type of content will not have to be asked. If multiple are present, the second question will be based on these values.

Advantage: As every content type already has an ID/name, they are easier to be mapped.

@gerwitz
Copy link

gerwitz commented Sep 19, 2022

I really want this, as I have an existing site without explicit type fields because most files are typed via their path.

I'd prefer to set one default content type per path, because I have some file types that "float" across this structure. (Though, really, those are more data than post files, in the style of #406)

@estruyf
Copy link
Owner Author

estruyf commented Sep 26, 2022

Thanks @gerwitz, so you would go for option two. Setting a content type for a page folder.

@gerwitz
Copy link

gerwitz commented Sep 26, 2022

Thanks @gerwitz, so you would go for option two. Setting a content type for a page folder.

Yes, but also allow it to be overridden.

Respecting metadata per file would be great, but FYI my ideal would be an ordered list of path matching patterns. E.g. (with pseudo patterns)

  • blog/yyyy/yyyy-mm-dd/slug.md: article
  • */photos/slug.md: photo

Probably this is better handled via page bundles, so feel free to ignore my rambling 😆

@estruyf
Copy link
Owner Author

estruyf commented Sep 26, 2022

Yes, but also allow it to be overridden.

There will always be the type property that can be set in your article's front matter, defining the content type to use. That property will allow you to override it per file.

Respecting metadata per file would be great, but FYI my ideal would be an ordered list of path matching patterns. E.g. (with pseudo patterns)

That would be option one. There are PRO's and CON's for both approaches. At the moment, I'm more in favor of implementing option two but wanted to hear the feedback first.

@estruyf
Copy link
Owner Author

estruyf commented Nov 9, 2022

Good news, you are now able to give it a try!

On the folder defined in the frontMatter.content.pageFolders setting, you can now set the content type(s) you want to use.

"frontMatter.content.pageFolders": [
  {
    "title": "blog",
    "path": "[[workspace]]/blog",
    "filePrefix": "yyyy-MM-dd",
    "contentTypes": ["blog"]
  },
  {
    "title": "docs",
    "path": "[[workspace]]/docs",
    "filePrefix": "",
    "contentTypes": ["doc", "page"]
  }
]

@michaeltlombardi
Copy link

@estruyf This works great! One thing I noticed while trying to define a content type mapping - there doesn't seem to be a way around requiring each page in the folder from setting the type metadata key to take advantage of non-default content type definitions.

This can be a problem for Hugo sites, where type carries its own semantics that may not be desirable for end users.

Thinking through this for a bit, I'm wondering if any of these ideas make sense:

  1. If contentTypes is declared for a folder, use only the listed content types. This behavior could be opt-in, possibly with an exclusiveContentTypes key or similar? Or we could document that if you want the default content type applied, you need to specify it.

  2. Use an additional metadata field that's always Front Matter specific. Instead of only checking type, it could check FrontMatter.type or similar. This would avoid munging a metadata key that has semantics specific to the static site generator.

    One advantage of pursuing this in general for page-specific Front Matter settings is we could schematize those settings and provide them as another entry in the side panel for pages, separate from the site-specific metadata, which might make them more discoverable and avoid requiring users to define those entries for themselves. Because FM is aware of all of the content types/etc available to it, those items could always present up-to-date options for the user.

@estruyf
Copy link
Owner Author

estruyf commented Nov 22, 2022

@michaeltlombardi, thanks for the feedback. You might be right about the type mapping, but this is how the content types have worked for a while in FM. If we want to change this, it would be best to do it in another issue/implementation as it would not be related to this enhancement.

@michaeltlombardi
Copy link

I'll file an issue for that as well! Just wanted to be sure there wasn't a way to work around option 2 in this implementation, since it's doing specific mapping for content types.

michaeltlombardi added a commit to michaeltlombardi/platen that referenced this issue Nov 24, 2022
This change adds the `toroidal` and `toroidal/admin` content types to
the Front Matter configuration so that site maintainers can edit the
metadata for those pages in a friendly UI.

For member pages and the admin page, this is fully functional. For the
webring index, this is limited currently by the implementation of
estruyf/vscode-front-matter#362, which introduces `where` logic for the
fields but doesn't yet support using that logic to control behavior
based on the file name, which would allow us to handle section pages
(which are always named `_index.md`) separately from member pages.

This change also updates the archetypes for Toroidal to set the
`type` to `toroidal` for the index and member pages, ensuring that
Front Matter picks up the type correctly for selecting the metadata to
display. Due to a limitation outlined in estruyf/vscode-front-matter#360
(see [this comment for more information][01]), we have to use `type` to
identify files. This has some implications for Hugo sites which don't
_directly_ impact this change.

[01]: estruyf/vscode-front-matter#360 (comment)
@estruyf estruyf closed this as completed Dec 8, 2022
@estruyf estruyf mentioned this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Project: v8.2.0
Projects
None yet
Development

No branches or pull requests

5 participants