-
Notifications
You must be signed in to change notification settings - Fork 16
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
Computed metadata fields #54
Comments
@rufuspollock I've advised @mohamedsalem401 to sketch out architecture design before implementing |
What do we want by implementing custom fields?We aim to provide users with a simple way to automate field generation based on a file's data. Examples:
How can we do this?We can achieve this by allowing users to define custom fields using JavaScript functions. Each function takes the following information as parameters:
The custom field generated by the function can then be added to the document scheme. Example Implementation: // User-defined function to generate keywords based on content
function generateKeywords(filePath, metadata, content, fileType) {
const keywords = ....
return { keywords };
}
// Document scheme with custom field added
const documentScheme = {
keywords: { value: generateKeywords}, // this will be excuted
}; In this example, the |
@rufuspollock i've posted a design approach in the description. let me know what you think. |
@mohamedsalem401 i think we probably want to operate on the ast ... (things are already parsed ...). at least in first pass i would try that ... |
@mohamedsalem401 can you draft your spec as a PR to README.md (for a new section called "Computed Fields" I think the function is something like: function computeSomething(fileObject, ast) { // either returns null and changes in place OR returns a duplicate of the object with the altered fields ...
// my guess is to KISS and just alter in place for now ...
} |
Computed fields (or just any operations on incoming records)
cf https://www.contentlayer.dev/docs/reference/source-files/define-document-type#computedfields
When loading a file i want to create new fields based on some computation so that i can have additional metadata
layout
based on the folder so i can change layouts based on folderMore Examples:
Acceptance
index.js
Tasks
Design
We can achieve this by allowing users to define custom fields using JavaScript functions. Each function takes the following information as parameters:
tags
,title
, ...)blog
, ...)The custom field generated by the function can then be added to the document scheme.
Example Implementation
In this example, the
generateKeywords
function is a placeholder for the user-defined function. Users can implement similar functions to automate the generation of custom fields based on their specific requirements. The custom field is then added to the document scheme for validation and type decleration.Notes
The text was updated successfully, but these errors were encountered: