Merge pull request #11646 from netchampfaris/context-enhancments
fix: Website context enhancements
This commit is contained in:
commit
ed69130c9c
2 changed files with 38 additions and 22 deletions
|
|
@ -124,6 +124,13 @@ def build_context(context):
|
|||
if context.title_prefix and context.title and not context.title.startswith(context.title_prefix):
|
||||
context.title = '{0} - {1}'.format(context.title_prefix, context.title)
|
||||
|
||||
# apply context from hooks
|
||||
update_website_context = frappe.get_hooks('update_website_context')
|
||||
for method in update_website_context:
|
||||
values = frappe.get_attr(method)(context)
|
||||
if values:
|
||||
context.update(values)
|
||||
|
||||
return context
|
||||
|
||||
def load_sidebar(context, sidebar_json_path):
|
||||
|
|
@ -225,33 +232,45 @@ def add_sidebar_data(context):
|
|||
def add_metatags(context):
|
||||
tags = frappe._dict(context.get("metatags") or {})
|
||||
|
||||
if tags:
|
||||
if "og:type" not in tags:
|
||||
tags["og:type"] = "article"
|
||||
if "og:type" not in tags:
|
||||
tags["og:type"] = "article"
|
||||
|
||||
name = tags.get('name') or tags.get('title')
|
||||
if name:
|
||||
tags["og:title"] = tags["twitter:title"] = name
|
||||
if "title" not in tags and context.title:
|
||||
tags["title"] = context.title
|
||||
|
||||
description = tags.get("description") or context.description
|
||||
if description:
|
||||
tags['description'] = tags["og:description"] = tags["twitter:description"] = description
|
||||
title = tags.get("name") or tags.get("title")
|
||||
if title:
|
||||
tags["og:title"] = tags["twitter:title"] = title
|
||||
tags["twitter:card"] = "summary"
|
||||
|
||||
image = tags.get('image', context.image or None)
|
||||
if image:
|
||||
tags["og:image"] = tags["twitter:image"] = tags["image"] = frappe.utils.get_url(image)
|
||||
tags['twitter:card'] = "summary_large_image"
|
||||
if "description" not in tags and context.description:
|
||||
tags["description"] = context.description
|
||||
|
||||
if context.author or tags.get('author'):
|
||||
tags['author'] = context.author or tags.get('author')
|
||||
description = tags.get("description")
|
||||
if description:
|
||||
tags["og:description"] = tags["twitter:description"] = description
|
||||
|
||||
tags['og:url'] = tags['url'] = frappe.utils.get_url(context.path)
|
||||
if "image" not in tags and context.image:
|
||||
tags["image"] = context.image
|
||||
|
||||
if context.published_on:
|
||||
tags['datePublished'] = context.published_on
|
||||
image = tags.get("image")
|
||||
if image:
|
||||
tags["og:image"] = tags["twitter:image"] = tags["image"] = frappe.utils.get_url(image)
|
||||
tags['twitter:card'] = "summary_large_image"
|
||||
|
||||
if "author" not in tags and context.author:
|
||||
tags["author"] = context.author
|
||||
|
||||
tags['language'] = frappe.local.lang or 'en'
|
||||
tags["og:url"] = tags["url"] = frappe.utils.get_url(context.path)
|
||||
|
||||
if "published_on" not in tags and context.published_on:
|
||||
tags["published_on"] = context.published_on
|
||||
|
||||
if "published_on" in tags:
|
||||
tags["datePublished"] = tags["published_on"]
|
||||
del tags["published_on"]
|
||||
|
||||
tags["language"] = frappe.local.lang or "en"
|
||||
|
||||
# Get meta tags from Website Route meta
|
||||
# they can override the defaults set above
|
||||
|
|
|
|||
|
|
@ -136,9 +136,6 @@ def get_website_settings(context=None):
|
|||
|
||||
context.encoded_title = quote(encode(context.title or ""), str(""))
|
||||
|
||||
for update_website_context in hooks.update_website_context or []:
|
||||
frappe.get_attr(update_website_context)(context)
|
||||
|
||||
context.web_include_js = hooks.web_include_js or []
|
||||
|
||||
context.web_include_css = hooks.web_include_css or []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue