[Content] Add generateId
option for file
loader
#1045
marceloverdijk
started this conversation in
Proposal
Replies: 1 comment
-
I've created a PR (withastro/astro#12308) which adds a I hope the idea is clear, and that you will see the benefit of this proposed change. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Body
Summary
Add a
generateId
(oridAccessor
) option for thefile
loader, similar as theglob
loader already has.This to handle JSON files which do not have
id
field.Background & Motivation
Some JSON files do not have a
id
field, or a alternative field that is unique.These files cannot be used as content collections without altering them, which is not always possible (think about externally provided JSON files).
A
generateId
oridAccessor
option (similar as theglob
loader already has) could provide this flexibility:Goals
A concise, bulleted-list outlining the intended goals of this RFC.
id
field (but e.g. ayear
field that is the unique key).Example
Using a
idAccessor?: string | ((data: any) => string);
the file loader could look like:Simply expects a
id
field (as-is):Use a field other than
id
representing the unique key:Generate a customized
id
based on multiple fields:Beta Was this translation helpful? Give feedback.
All reactions