Skip to content

Add a way to extend default metadata#147

Open
erral wants to merge 9 commits intomasterfrom
metadata-extension-point
Open

Add a way to extend default metadata#147
erral wants to merge 9 commits intomasterfrom
metadata-extension-point

Conversation

@erral
Copy link
Copy Markdown
Member

@erral erral commented Oct 4, 2017

I needed a way to extend the default metadata provided by the product, and implemented it using adapters.

To extend the default metadata, you need to provide an adapter for the given content type and return a dict with the extended metadata.

You can also override preexisting metadata (if you want to change for instance og:title or any other.

This idea of using an adapter comes from collective.opengraph a preexisting product that provides just opengraph metadata support.

Any comments are welcomed, of course!

Copy link
Copy Markdown
Member

@hvelarde hvelarde left a comment

Choose a reason for hiding this comment

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

overall I liked a lot this new feature; I just left some comment about names and other minor fixed that we can think about. I would love to read other people's opinions.

CC @keul @fredvd

Comment thread sc/social/like/browser/viewlets.py Outdated
tags['og:locale'] = self.language
tags['og:site_name'] = self.site_name

for _, adapter in getAdapters((self.context,), IAdditionalMetatags):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know that passing a tuple is more efficient, but is also less clear; can we change this for:

for _, adapter in getAdapters([self.context], IAdditionalMetatags):

Comment thread sc/social/like/interfaces.py Outdated


class IAdditionalMetatags(Interface):
""" Interface to provide additional metatags to those provided by default """
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

docstring should not include no trailing space and must end with a period "."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would adding flake8-extensions = flake8-docstrings to buildout.cfg avoid this manual review, @hvelarde? About trailing space and the period?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I removed it at some point because it was causing more issues than the ones solving; we can try it in a different PR.

Comment thread sc/social/like/interfaces.py Outdated
""" Interface to provide additional metatags to those provided by default """

def metatags():
""" a dict with additional metatags """
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

idem.

provideAdapter(NewsItemMetatagsAdapter)
viewlet = self.viewlet(self.obj)
html = viewlet.render()
self.assertIn('one_key', html)
Copy link
Copy Markdown
Member

@hvelarde hvelarde Oct 5, 2017

Choose a reason for hiding this comment

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

I would love to make this tests a little bit more resilient using lxml instead, but it's up to you.

Comment thread sc/social/like/interfaces.py Outdated
)


class IAdditionalMetatags(Interface):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I strongly dislike this name, what do you think about IOGProperties or something like that?

Copy link
Copy Markdown
Member Author

@erral erral Oct 6, 2017

Choose a reason for hiding this comment

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

I used a generic name because in some cases one may want to add some non-og metatags. I don't know whether now there is any disalignment between OpenGraph and Twitter Card metatags, but at some point there was the need to add some tags that were not specifically OpenGraph.

But anyway, it's just a naming issue, so I can rename it without any problem.

Copy link
Copy Markdown
Member

@idgserpro idgserpro left a comment

Choose a reason for hiding this comment

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

LGTM. Don't know if my suggestion in https://github.com/collective/sc.social.like/pull/147/files#r143023636 would avoid docstring problems, let's see if @hvelarde has an opinion about that.

Copy link
Copy Markdown
Member

@rodfersou rodfersou left a comment

Choose a reason for hiding this comment

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

Facebook and Twitter has some different meta tags https://github.com/collective/sc.social.like/blob/master/sc/social/like/plugins/facebook/templates/metadata.pt https://github.com/collective/sc.social.like/blob/master/sc/social/like/plugins/twitter/templates/metadata.pt and twitter uses the "name" instead of "property" in it's tags.

is it possible to use the same mechanism for these tags in these plugins?

Copy link
Copy Markdown
Member

@hvelarde hvelarde left a comment

Choose a reason for hiding this comment

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

I renamed again the interface and made some changes to the documentation.

in the process of reviewing the code I discovered a problem: OG tags can have multiple values as defined in the Array section of the documentation; that means we can't use a dictionary for describing the metadata or we'll be unable of implementing things like this:

<meta property="og:article:tag" content="foo" />
<meta property="og:article:tag" content="bar" />

we need to think a little bit more before merging this.

@hvelarde
Copy link
Copy Markdown
Member

hvelarde commented Oct 7, 2017

@rodfersou Twitter meta tags use the standard name attribute of HTML5, OG protocol uses the RDFa extension and that's why they use the property attribute instead; the scope of this PR is to be able to add/override OG metadata only. we can think later on how to do the same for Twitter.

BTW, @erral I would like to find a way to be able to dynamically add tabs to the control panel configlet (for third-party plugins, for instance); do you have any suggestion?

@rodfersou
Copy link
Copy Markdown
Member

BTW, @erral I would like to find a way to be able to dynamically add tabs to the control panel configlet (for third-party plugins, for instance); do you have any suggestion?

@hvelarde we can show or hide the tabs dynamically with some lines of javascript code.

@erral
Copy link
Copy Markdown
Member Author

erral commented Oct 9, 2017

Would it be acceptable to allow lists to be values of the dict and then when rendering the template check the type of the value and if it is a list, render it properly?

@hvelarde
Copy link
Copy Markdown
Member

hvelarde commented Oct 9, 2017

@erral sound doable, but we will need to make the documentation a little bit more explicit then.

@rodfersou I think that's not needed right now; what we need is a way to add dynamically tabs to the configlet.

@erral
Copy link
Copy Markdown
Member Author

erral commented Oct 10, 2017

@rodfersou I think that's not needed right now; what we need is a way to add dynamically tabs to the configlet.

collective.plonetruegallery has a similar usecase: plugins can have configuration and if enabled it is shown in the control panel config.

@hvelarde
Copy link
Copy Markdown
Member

@erral IMO that's way to complicated; we only need to do the same thing is done in behaviors to extend the configuration form.

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.

4 participants