Skip to content
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

GScan will complain about {{author}} usage when passed as data property from routes.yaml #170

Open
kirrg001 opened this issue Nov 6, 2018 · 3 comments
Labels

Comments

@kirrg001
Copy link
Contributor

kirrg001 commented Nov 6, 2018

Ghost API V2 will allow in the near future:

routes.yaml

routes:
  /route/:
    data: author.{slug}

Then you need to use {{author.slug}} in your theme. GScan will complain about this usage.
Not 100% sure how to differentiate single author usages and this use case.

Workaround:

routes:
  /route/:
    data: 
      someone: author.{slug}

{{someone.slug}}


Copied error:

Error ID:
    53f5dd40-4fa9-11e9-9df5-e9882a363da1

Details:
    fatal:    false
    level:    error
    rule:     Replace the <code>{{author.slug}}</code> helper with <code>{{primary_author.slug}}</code> or <code>{{authors.[#].slug}}</code>
    details: 
      """
        The usage of <code>{{author.slug}}</code> is deprecated and should be replaced with either <code>{{primary_author.slug}}</code>
                or <code>{{authors.[#].slug}}</code>.<br>
                Find more information about the <code>{{authors}}</code> helper <a href="https://themes.ghost.org/docs/authors" target=_blank>here</a>.
      """
    regex: 
    helper:   {{author.slug}}
    failures: 
      - 
        ref:     profile.hbs
        message: Please remove or replace {{author.slug}} from this template
    code:     GS001-DEPR-AUTH-SLUG

Related reports:

@kirrg001 kirrg001 added the bug label Nov 6, 2018
@naz naz self-assigned this Mar 26, 2019
@naz
Copy link
Member

naz commented Mar 27, 2019

@kirrg001 after investigating this bug and looking into how gscan handles checks internally have following thoughts:

GS001-DEPR-AUTH* set of rules: (except GS001-DEPR-AUTH-MAIL) is obsolete as of Content API introduction in Ghost and data: author.{slug} being available in Dynamic Routing (defined in routes.yaml).

The most straight forward solution would be just removing these rules. But seems like a bad idea because when there's no custom route defined with author.{slug} this syntax is invalid.

A better solution I think would be redefining these rules as warnings and change the messaging to point to usecase when using {{author}} helper is valid. This keeps the user informed when importing a new theme and no errors are thrown.

An ideal solution would be somehow checking routes.yaml file and adjusting errors accordingly. But as it's not a part of the theme it's an impossible thing to check.

As a sidenote around gscan error detection for specific versions. We are only checking latest version for any theme imported/used in Ghost (ghost call, gscan handling) There is no distinction between major or minor versions during gscan checks. This is problematic because {{author}} change was introduced as part of the minor release and there's no way to distinguish theme that only uses Ghost 2.0 from the one that uses Ghost after Content API was introduced. Think it would need more investigation if more cases like this pop up.

@kevinansfield
Copy link
Contributor

This is potentially something using the handlebars AST could help with. If we see usage of {{author.slug}} we can look up the tree to see if it's in a post/page context and only warn if that's the case.

@naz
Copy link
Member

naz commented Mar 27, 2019

@kevinansfield yes, having the context narrowed down to post/page would be the best option. In this case, we could set this bug to be an example use-case that should be solved with AST 👍

@naz naz removed their assignment Apr 25, 2019
@ErisDS ErisDS mentioned this issue Aug 29, 2019
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants