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

Add filtering for AMP examples #2494

Merged
merged 4 commits into from
Jul 16, 2019
Merged

Add filtering for AMP examples #2494

merged 4 commits into from
Jul 16, 2019

Conversation

fstanis
Copy link
Collaborator

@fstanis fstanis commented Jul 15, 2019

  • Allows examples to use filters: frontmatter
  • Allows examples to filter sections using @format in the comments (context)
  • Updates docs for frontmatter and formats

Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please move to logic to extract the filter into the ABE docs parser to keep all things sample parsing in one place. Otherwise LGTM.

platform/lib/build/samplesBuilder.js Outdated Show resolved Hide resolved
@fstanis
Copy link
Collaborator Author

fstanis commented Jul 15, 2019

Moved @filter logic to ampproject/amp-by-example#2037

@sebastianbenz
Copy link
Collaborator

Thanks - changes are live @0.2.15

@@ -657,7 +662,7 @@ class SamplesBuilder {
'$localization': {
'path': `/{locale}${this._getPreviewRoute(sample)}`,
},
'formats': [this._getSampleFormat(parsedSample)],
'formats': this._getSampleFormats(parsedSample),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now redundant with filters. Can we somehow merge this with filters? //cc @matthiasrohmer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow? Filters (@filter) are section-level and formats are article-level. This makes it aligned (more or less) with non-example articles which have both.

While we could possibly guess the formats in a smarter way, I'd prefer the less-eager model where the example author is explicit in which format the example is useful for. E.g. just because an example works in emails doesn't make it a good example of something to use in an email.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, forgot that filters are on section level. We could even go as far as validating section filter against formats defined in the front matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense.

Looking at the code, seems we have two options:

  1. Move the call to _getSampleFormats into _parseSample, e.g. parsedSample.formats = this._getSampleFormats(parsedSample) and then verify when traversing the sections in _parseSample.

  2. Move the whole _getSampleFormats login into ampproject/amp-by-example.

Any preference?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 2. would be good, this avoids also that the method is being called twice in this file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fstanis good with merging this branch?

@fstanis fstanis merged commit 29a2462 into ampproject:future Jul 16, 2019
@fstanis fstanis deleted the filter branch July 16, 2019 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants