-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: import nested categories #89
Conversation
Input:
I have limited skill. If anyone wants to help, the objective is to have following output for the above input. Output: WP describes the relationship like this: [
{ name: 'lorem', parent: '' },
{ name: 'ipsum', parent: 'lorem' },
{ name: 'dolor', parent: 'ipsum' },
{ name: 'foo', parent: '' },
{ name: 'bar', parent: 'foo' },
{ name: 'baz', parent: '' }
] Then converted to object for easier access, {
lorem: '',
ipsum: 'lorem',
dolor: 'ipsum',
foo: '',
bar: 'foo',
baz: '',
} The goal is to formats the object into that output. Each category can only have one parent (one-to-many). |
@curbengh Here is a code. It should support infinite nesting of categories:
Outputs:
|
@adnan360 Fantastic. Since this plugin requires Node 12+, const nest = (items, name = '', link = 'parent') => {
return items
.filter(item => item[link] === name)
.map(item => [item.name, nest(items, item.name)].flat(Infinity));
} |
This PR is ready for test, it now supports non-nested categories and >2 levels categories. |
Fixes #36 cc @jashsayani @adnan360
Example categories:
lorem and dolor are parent (top-level) categories, ipsum is child of lorem.
After import, the front-matter should have:
Equivalent to:
Next PR can add an option to skip
Uncategorized
category.