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

Amp skimlinks exclude selector #18

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

slocka
Copy link

@slocka slocka commented Dec 2, 2019

  • Add "exclude-selector" extension option to prevent the affiliation of links in some HTML blocks.
  • Add class "noskimlinks" for a "ready to use" solution to prevent the affiliation of links in some HTML blocks.
  • Add "include-selector" extension option to replace existing "link-selector" option. The two options are the same, we are just renaming for consistency with "exclude-selector".

const excludedAnchors = nodeListToArray(
this.rootNode_.querySelectorAll(this.excludeSelector_)
);
anchors = anchors.filter(a => excludedAnchors.indexOf(a) === -1);
Copy link
Member

Choose a reason for hiding this comment

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

not sure how big of a deal it is, but you are not forcing the exludeSelector / linkSelector to match an actual anchor.

Copy link
Author

Choose a reason for hiding this comment

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

It is a bit of a concern, I put a WARNING in the documentation https://amp.dev/documentation/components/amp-skimlinks/ to tell the publisher to use this option carefully. I can't think of a reliable way to validate that a CSS selector is matching an a element. Maybe some regex but not sure if we want to go down that road.

For now we need to rely on the publisher being careful.

Copy link
Member

Choose a reason for hiding this comment

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

when you are filtering anchors you can check for .tagname but it will add some processing time (+ you will have to do the filter even if there are no excludeSelectors

it('Should have both the noskimlinks exclude selector and the custom exclude selector when defined', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
'exclude-selector': '.taboola a',
Copy link
Member

Choose a reason for hiding this comment

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

probably not the best idea to reference other companies here

Copy link

@mayankamencherla mayankamencherla left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants