[Design issues] Edit frontmatter could be complicated #521
-
Editing frontmatter may be complicated with current APIs. Though we are providing a Just as an example, I would want "plugin A" to autocomplete export default {
extendsPageData: ({ frontmatter}) => {
if(frontmatter.home && !frontmatter.title) {
// here I want to set `frontmatter,titlte` as 'home'
}
}
} (This is just an example, and it could be done And in the current API, there is no way to safely achieve this: We can only delete frontmatter or editing using the below way export default {
extendsPageData: ({ frontmatter}) => {
if(frontmatter.home) {
frontmatter.title = frontmatter.title || 'home'
// convert v1 format
if(frontmatter.actionText && frontmatter.actionLink) {
frontmatter.actions = [{ text: frontmatter.actionText, link: frontmatter.actionLink}]
delete frontmatter.actionText
delete frontmatter.actionLink
}
}
return {};
}
} All plugins must edit frontmatter as above way to not effect others. if theme or other plugins excuted later are setting a new frontmatter like this, all fronter edits will be lost as export default {
extendsPageData: ({ frontmatter}) => ({
frontmatter: {
...frontmatter,
// new data here
}
}}
} So that // original frontmatter is `{ user: 'content' }`
// pluginA
export default {
extendsPageData: ({ frontmatter}) => ({
frontmatter: {
...frontmatter,
plugin: 'a'
}
}}
}
// theme
export default {
extendsPageData: ({ frontmatter}) => ({
frontmatter: {
...frontmatter,
theme: 'b'
}
}}
}
// finally frontmatter is `{ user: 'content', theme: 'b' } And if a plugin developer write something like this. user frontmatter will be fully erased. // original frontmatter is `{ user: 'content' }`
// pluginA
export default {
extendsPageData: () => ({
frontmatter: {
plugin: 'a'
}
}}
}
// finally frontmatter is `{ plugin: 'a' } Since the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Any feedback here? @meteorlxy I already have someone reporting such issues. |
Beta Was this translation helpful? Give feedback.
-
This is fixed by changes of |
Beta Was this translation helpful? Give feedback.
This is fixed by changes of
extendsPage