Publish icon indicating copy to clipboard operation
Publish copied to clipboard

Don’t force section on addItem

Open alexito4 opened this issue 5 years ago • 0 comments

This allows the configure closure to set an entire new item, including changing it’s section.

I guess the big question is, is there a reason to force the section?

The scenario for this is the following: In my website I have a section for all the articles of the blog and I want to have another section that displays only specific articles based on some criteria. This doesn't seem straightforward so what I'm doing is the following:

  1. Add a section case in the enum.
  2. Make an empty folder so Publish doesn't error. (the folder doesn't need any md, we will add them with a step)
  3. Make a step that adds the items to the section:
            let items = context.items...
            for item in items {
                context.sections[.section].addItem(
                    at: item.path,
                    withMetadata: item.metadata
                ) { newItem in
                    newItem = item
                }
            }

Without this patch the path of the new items will be pointing to the new section we're creating, but what I really want is that their path points to their original location.

Is there a better approach to build something like this?

alexito4 avatar Mar 09 '20 20:03 alexito4