gscan icon indicating copy to clipboard operation
gscan copied to clipboard

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

Open kirrg001 opened this issue 7 years ago • 3 comments

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:

  • https://github.com/TryGhost/gscan/issues/165

kirrg001 avatar Nov 06 '18 13:11 kirrg001

@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.

naz avatar Mar 27 '19 07:03 naz

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.

kevinansfield avatar Mar 27 '19 10:03 kevinansfield

@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 :+1:

naz avatar Mar 27 '19 10:03 naz