Closed nicolabovolato closed 1 month ago
I believe I actually just ran into this as well. I'm trying to build a content collection for a software library that includes versioned URLs (so I can have docs for all versions). A pkg
collection with content files like src/content/pkg/v0.0.1/sub/index.mdoc
will have its slug returned as v001/sub
. I can of course override that slug back to its "true" form of v0.0.1/sub
, but I'll have to do that for every single file—definitely not ideal!
I would love to be able to opt out of sanitizing actually-supported characters out of my slugs in some fashion.
You can set your own custom slug on individual entries: https://docs.astro.build/en/guides/content-collections/#defining-custom-slugs
I don't think we want to change our default slugging algorithm.
Wasn’t suggesting altering any defaults, and yes I’m aware that the slug can be customized (I mentioned above that I understood this). The problem is in my case I have to do that for every single file, all to work around a slug algorithm that really isn’t documented and certainly isn’t customizable.
Ideally I would be able to customize this behavior globally or within a collection so that I don’t need to override the frontmatter in every single file (which I’m having to do in a script due to my content being autogenerated).
A global config way of doing it could work. Do you have any suggestions as to what that would look like?
Conceptually it seems like the slug transformer takes a file path string as input, and returns a transformed string as output. If the current logic can be easily wrapped into a function of that form, then a collection level slugTransform
or slugTransformer
or slugNormalize
setting of that form would work. I am not too opinionated about the naming here, you would probably have better ideas about how to fit it in!
slugTransform
probably fits with how we tend to name things. Any chance you'd be able to contribute this change?
I wish I could, but I have a new baby coming any day now and I’m spread very thin atm 😅 If things settle down during my leave I may be able to pick it up in a month or two.
I think the proposal sounds great though. This would really make the content collections a lot more flexible for different use cases imo.
cc @ascorbic how does content layer treat slugs? Is it still a special thing? Is this type of request something that could be incorporated there?
It's already handled. The glob
loader provide a generatedId
function that allows to customise the slug of the content collections
It uses IDs instead of slugs, but you can provide a generateID
function to glob
to take over generating the ID, which would let you handle that kind of thing.
https://github.com/withastro/astro/blob/content-layer/packages/astro/src/content/loaders/glob.ts#L30
Ok, in that case we probably won't add an option for the v1 CC and encourage people to switch to the new API.
Amazing! I'll be eagerly awaiting the new content layer / #11360 🚀 :pray:
Going to close as there's nothing actionable to do here at this time.
@nicolabovolato
Content layer solves this problem. The current content collections we will slowly be phased out
@ematipico
I'm guessing that it truly is experimental then 😄
@nicolabovolato you need to move your files out of src/content
. Right now they're being processed using the old content collections.
Thanks @ascorbic, working fine now 🙌🏼
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
On my personal website there's among others a basic tutorial for C and one for C++.
I'm currently migrating from pages to content collections, but il looks like the
+
sign gets stripped in the slug.What's the expected result?
From what I found in the docs, there's no mention of any character stripping when generating the slug. I think these character should be kept as it also provides better compatibility with Astro pages.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ywpupp
Participation