Closed noxify closed 1 month ago
I originally had a getTitle
method on collection sources, but removed it since it wasn't exactly the same as what happens with file and export sources so wanted to keep it consistent and missed removing the title
option from createCollection
.
The original intention was to be able to iterate over multiple collections and use the title to build index pages, but I'm not sure how practical that is since those would be mostly one-off situations so you could render the title yourself pretty easily. I have thought about using the term of label
for use in navigational items so it seems to make sense to bring that back for collections so you can generate navigations. Difference between title and label being title is used for pages and label is meant to be the shorter version used in navigations.
Curious what you'd like to use it for? 🙂
Hi,
The original intention was to be able to iterate over multiple collections
That's exactly what I'm currently doing. I created an export which contains all available collections: https://github.com/noxify/omnidoc-docs-template/blob/main/src/collections.ts#L34
The collections
are iterated in the ui to provide the values for the switcher:
Currently I'm using Object.keys(collections)
to generate the values, but it would be good to have a method on collection level to make it more "human readable".
The switcher is inspired based on the nextjs docs where you can choose between "app" and "pages". Want to show something similar.
Real world example could be Omnidoc ;) One collection for the "core" and one for the "plugins" ( or for each plugin? ).
...and use the title to build index pages...
I solved this by adding the collection keys also to the slugs array in generateStaticParams
:
https://github.com/noxify/omnidoc-docs-template/blob/main/src/app/docs/%5B...slug%5D/page.tsx#L50-L58
and checking the slug length and load the /docs/<product>/index.mdx
if needed:
https://github.com/noxify/omnidoc-docs-template/blob/main/src/app/docs/%5B...slug%5D/page.tsx#L82-L84
since those would be mostly one-off situations so you could render the title yourself pretty easily
I agree, having static props ( like title
or label
) are very limited.
What do you think about an meta
object? Have seen this at tanstack/table for the column definitions.
There I use the meta to specify custom class names and other stuff.
Since meta
is just an object, I can specify whatever I want and I'm not "limited" to just some static props.
And I think it would be a "low brainer" to implement it, since we already have everything - so we just have to rename some props and provide a getter to expose the meta data.
As always, if you need help, let me know and I can give it a try ✌️
based on the discord chat, i will close this.
Solution is to have a named export metadata
in the docs/<collection-name/index.mdx
.
Here we can specify the relevant information.
Ref: https://discord.com/channels/1276665813906096159/1282243655146405899/1286721049689591808
Forgot to link, but I also wrote up a recipe here. I'll do an expanded guide on metadata in general in the future.
Hi,
while creating a new collection via
createCollection
, I can specify atitle
in the options. Is there currently a an option/method to get this title?Example:
I see currently only
getPath
,getSource
andgetSources
forOmnidocDocsCollection
.Did a quick check and it seems it could be enough to extend the
CollectionSource
type: https://github.com/souporserious/omnidoc/blob/main/packages/omnidoc/src/collections/index.tsx#L176-L179If you want, I can give it a try and provide a PR.