Updated meta-headers
authorThierry Florac <tflorac@ulthar.net>
Wed, 24 Oct 2018 16:18:01 +0200
changeset 191 1fc1adb8123d
parent 190 19774ff85770
child 192 39482eb2520f
Updated meta-headers
src/pyams_default_theme/shared/common/__init__.py
src/pyams_default_theme/shared/site/__init__.py
--- a/src/pyams_default_theme/shared/common/__init__.py	Tue Oct 23 12:16:08 2018 +0200
+++ b/src/pyams_default_theme/shared/common/__init__.py	Wed Oct 24 16:18:01 2018 +0200
@@ -16,17 +16,35 @@
 
 from pyams_content.interfaces import IBaseContent
 from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_default_theme.interfaces import IContentDate, IContentNavigationTitle, \
-    IContentTag
+from pyams_default_theme.interfaces import IContentDate, IContentNavigationTitle, IContentTag
 from pyams_i18n.interfaces import II18n
-from pyams_skin.layer import IPyAMSLayer
+from pyams_skin.interfaces.metas import IHTMLContentMetas
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_skin.metas import ContentMeta, HTMLTagMeta
 from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
 from pyams_utils.date import SH_DATE_FORMAT, format_date
 from pyams_utils.interfaces.tales import ITALESExtension
 from pyams_workflow.interfaces import IWorkflowPublicationInfo
 
 
-@adapter_config(context=(IBaseContent, IPyAMSLayer), provides=IContentNavigationTitle)
+@adapter_config(name='title', context=(IWfSharedContent, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas)
+class SharedContentTitleMetasAdapter(ContextRequestViewAdapter):
+    """Title metas adapter"""
+
+    order = 1
+
+    def get_metas(self):
+        i18n = II18n(self.context)
+        title = i18n.query_attribute('title', request=self.request)
+        yield HTMLTagMeta('title', title)
+        description = i18n.query_attribute('description', request=self.request)
+        if (not description) and self.context.handle_header:
+            description = i18n.query_attribute('header', request=self.request)
+        if description:
+            yield ContentMeta('description', description)
+
+
+@adapter_config(context=(IBaseContent, IPyAMSUserLayer), provides=IContentNavigationTitle)
 def shared_content_navigation_title(context, request):
     """Default content navigation title adapter"""
     return II18n(context).query_attribute('title', request=request)
@@ -44,7 +62,7 @@
         return self.request.registry.queryMultiAdapter((context, self.request), IContentNavigationTitle)
 
 
-@adapter_config(context=(IWfSharedContent, IPyAMSLayer), provides=IContentTag)
+@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IContentTag)
 def shared_content_tag_adapter(context, request):
     """Default shared content tag adapter"""
     translate = request.localizer.translate
@@ -63,7 +81,7 @@
         return self.request.registry.queryMultiAdapter((context, self.request), IContentTag)
 
 
-@adapter_config(context=(IWfSharedContent, IPyAMSLayer), provides=IContentDate)
+@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IContentDate)
 def shared_content_date_adapter(context, request):
     """Default shared content date adapter"""
     publication_info = IWorkflowPublicationInfo(context, None)
--- a/src/pyams_default_theme/shared/site/__init__.py	Tue Oct 23 12:16:08 2018 +0200
+++ b/src/pyams_default_theme/shared/site/__init__.py	Wed Oct 24 16:18:01 2018 +0200
@@ -12,4 +12,29 @@
 
 __docformat__ = 'restructuredtext'
 
+from zope.interface import Interface
 
+from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager
+from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces.metas import IHTMLContentMetas
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_skin.metas import ContentMeta, HTMLTagMeta
+from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
+
+
+@adapter_config(name='title', context=(ISiteManager, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas)
+@adapter_config(name='title', context=(ISiteFolder, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas)
+class SiteContainerTitleMetasAdapter(ContextRequestViewAdapter):
+    """Site container metas adapter"""
+
+    order = 1
+
+    def get_metas(self):
+        i18n = II18n(self.context)
+        title = i18n.query_attribute('title', request=self.request)
+        yield HTMLTagMeta('title', title)
+        description = i18n.query_attribute('description', request=self.request)
+        if (not description) and hasattr(self.context, 'header'):
+            description = i18n.query_attribute('header', request=self.reqeust)
+        if description:
+            yield ContentMeta('description', description)