getgrav / grav-plugin-relatedpages

Grav RelatedPages Plugin
http://getgrav.org
MIT License
17 stars 7 forks source link

Editing Config from admin creates invalid yaml #17

Open paulmassen opened 7 years ago

paulmassen commented 7 years ago

So, after hours and hours of trying to find why I was not able to use relatedpages, I finally found what was the cause of the problem.

Step to replicate

Install relatedpages plugin. the default relatedpages.yaml looks like this:

enabled: true                   # set to false to disable this plugin completely
limit: 5                        # the number of related pages to display
show_score: true                # toggle to determine if scores should be displayed in output
score_threshold: 20 # minimum score needed to show up in the list
filter:                         # filter a configurable collection of pages to compare
    items:
        @page: /blog            # supports @self, @page, and @taxonomy collections
    order:
        by: date                # order type by default
        dir: desc               # order direction
page_in_filter: true            # true if the current page must be in the filtered collection
explicit_pages:
    process: true               # true|flase to enable this explicit page matching
    score: 100

Now, within the admin, when clicking on save, the yaml validation will generate this in user/config/relatedpages.yaml:

enabled: true
limit: 5
show_score: true
score_threshold: 20
filter:
  items: '''@page'': /blog'
  order:
    by: date
    dir: desc
page_in_filter: true
explicit_pages:
  process: true
  score: 100

Which simply does not work.

I was already feeling like something was wrong with this blueprint so I made this PR a while ago: https://github.com/getgrav/grav-plugin-relatedpages/pull/14

But I don't think this is the solution neither.

Let me know if more info is needed.

paulmassen commented 7 years ago

There are several problems actually: Example: Does not work:

items: '''@page'': /blog'
items: '@page': /blog
items: ''@page': /blog'

Does work:

items:
        '@page': /blog
items:
        @page: /blog
OleVik commented 7 years ago

The first three that don't work seem like pretty poor YAML, though apparently 1 is valid, the other two do not validate against YAML. The two that work are both valid YAML.

paulmassen commented 7 years ago

Maybe a solution would be to use something like this: https://github.com/getgrav/grav-plugin-admin/blob/develop/blueprints/admin/pages/modular_new.yaml#L41

paulmassen commented 7 years ago

Tested the one that is valid, but it does not work neither. I think the new line with the indent is required

andywimmer commented 6 years ago

Yes you need new line and proper spacing:

filter:
  items:
    @page: /home

Steps to reproduce

  1. Install & enable Related Pages plugin
  2. Navigate to Related Pages plugin settings via Grav Admin
  3. Click Save
  4. Navigate to user/config/plugins/relatedpages.yaml
  5. Observe invalid yaml

tested on Grav 1.3.8, Admin 1.6.6, Related Pages 1.1.4

paulmassen commented 6 years ago

I changed the text field to multilevel, and it seems to work. Some more information about how to properly fill this field might be needed, but the default value should give users a good hint about how to use it.

Let me know if it works for you too.