rainlab/sitemap-plugin

Easier way to implement custom itemTypes

CptMeatball opened this issue · 4 comments

I find it very tedious to implement the logic for generating custom itemTypes like blog-post and all-blog-posts. I keep copying the logic again and again for each project/plugin.

I'm looking at ways to make this proces easier/less tedious. It might be an idea to add custom behaviours to this plugin, so we only need to define the parameters necessary to output custom post types.

My suggested approach:

  • Use a behavior to define the standard functions like resolveMenuItem etc
  • User has to add fields to the model for the needed input that varies for each itemType.
$itemType = 'blog-post';
$componentName = 'blogPost';
$scope = `isVisible`;

Hurdles I can think of:

  • Combining singular and multiple item logic (blog-post vs all-blog-posts)
  • Combining multiple itemtypes in 1 model (blog-post / category etc)

Does anyone have any input into this matter?

What would the API for this behavior look like?

What exactly do you mean with API?

The more I think about it, the more I think the types should be the declared inside a yaml file. 🤔It would read from the YAML file, which is added to the model (e.g. $itemTypeConfig = '/path/to/file.yaml') which houses all necessary information.

blogPost:
    name: blog-post
    component: blogPost
    scope: isVisible
    multiple: false
    slug: slug
blogPosts:
    name: all-blog-posts
    component: blogPost
    scope: isVisible
    slug: slug
    multiple: true

In existing functions we iterate over the YAML and fill the $items array accordingly. In this way the methods and outcome would remain the same, so it still sticks to the same principle.

I'm not sure how exactly that would work, but feel free to submit a PR with your ideas

@CptMeatball why'd you close this?