feat: Introduce Website Meta Tag
- Child Table to store meta tags with key and value - Used in Web Page - Remove redundant description field in Web Page and patch it into Website Meta Tag
This commit is contained in:
parent
133cd544c5
commit
8e55ecccb7
8 changed files with 186 additions and 73 deletions
|
|
@ -236,3 +236,4 @@ frappe.patches.v11_0.fix_order_by_in_reports_json
|
|||
execute:frappe.delete_doc('Page', 'applications', ignore_missing=True)
|
||||
frappe.patches.v11_0.set_missing_creation_and_modified_value_for_user_permissions
|
||||
frappe.patches.v12_0.set_primary_key_in_series
|
||||
frappe.patches.v12_0.webpage_migrate_description_to_meta_tag
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import frappe
|
||||
|
||||
def execute():
|
||||
web_pages = frappe.get_all('Web Page', ['name', 'description'])
|
||||
|
||||
for web_page in web_pages:
|
||||
if web_page.description:
|
||||
doc = frappe.get_doc('Web Page', web_page.name)
|
||||
doc.append('meta_tags', {
|
||||
'key': 'description',
|
||||
'value': web_page.description
|
||||
})
|
||||
doc.save()
|
||||
|
|
@ -224,6 +224,9 @@ def add_metatags(context):
|
|||
if tags.get("name"):
|
||||
tags["og:title"] = tags["twitter:title"] = tags["name"]
|
||||
|
||||
if tags.get("title"):
|
||||
tags["og:title"] = tags["twitter:title"] = tags["title"]
|
||||
|
||||
if tags.get("description"):
|
||||
tags["og:description"] = tags["twitter:description"] = tags["description"]
|
||||
|
||||
|
|
@ -232,7 +235,7 @@ def add_metatags(context):
|
|||
tags["og:image"] = tags["twitter:image:src"] = tags["image"] = frappe.utils.get_url(image)
|
||||
|
||||
if context.path:
|
||||
tags['og:url'] = frappe.utils.get_url(context.path)
|
||||
tags['og:url'] = tags['url'] = frappe.utils.get_url(context.path)
|
||||
|
||||
if context.published_on:
|
||||
tags['datePublished'] = context.published_on
|
||||
|
|
@ -242,3 +245,5 @@ def add_metatags(context):
|
|||
|
||||
if context.description:
|
||||
tags['description'] = context.description
|
||||
|
||||
tags['language'] = frappe.local.lang or 'en'
|
||||
|
|
|
|||
|
|
@ -875,71 +875,6 @@
|
|||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "Add description for SEO. Max character length is 160.",
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Description",
|
||||
"length": 160,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "Add comma separated keywords for SEO",
|
||||
"fieldname": "keywords",
|
||||
"fieldtype": "Code",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Keywords",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
|
|
@ -973,6 +908,39 @@
|
|||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "meta_tags",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Meta Tags",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Website Meta Tag",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 1,
|
||||
|
|
@ -987,7 +955,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 20,
|
||||
"modified": "2018-12-14 10:53:41.077915",
|
||||
"modified": "2019-02-14 00:25:01.562419",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Web Page",
|
||||
|
|
|
|||
|
|
@ -45,9 +45,6 @@ class WebPage(WebsiteGenerator):
|
|||
"text_align": self.text_align,
|
||||
})
|
||||
|
||||
if self.description:
|
||||
context.setdefault("metatags", {})["description"] = self.description
|
||||
|
||||
if not self.show_title:
|
||||
context["no_header"] = 1
|
||||
|
||||
|
|
@ -121,12 +118,14 @@ class WebPage(WebsiteGenerator):
|
|||
raise frappe.Redirect
|
||||
|
||||
def set_metatags(self, context):
|
||||
from frappe.website.doctype.website_meta_tag.website_meta_tag import set_metatags
|
||||
context.metatags = {
|
||||
"name": context.title,
|
||||
"description": (context.description or "").replace("\n", " ")[:500],
|
||||
"keywords": (self.keywords or "").replace("\n", ", ")
|
||||
"name": context.title
|
||||
}
|
||||
|
||||
# set meta tags from Website Meta Tag child table
|
||||
context = set_metatags(self.meta_tags, context)
|
||||
|
||||
image = find_first_image(context.main_section or "")
|
||||
if image:
|
||||
context.metatags["image"] = image
|
||||
|
|
|
|||
0
frappe/website/doctype/website_meta_tag/__init__.py
Normal file
0
frappe/website/doctype/website_meta_tag/__init__.py
Normal file
107
frappe/website/doctype/website_meta_tag/website_meta_tag.json
Normal file
107
frappe/website/doctype/website_meta_tag/website_meta_tag.json
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2019-02-13 23:39:12.802543",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "key",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Key",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "value",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Value",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-02-13 23:39:12.802543",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Website Meta Tag",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
}
|
||||
20
frappe/website/doctype/website_meta_tag/website_meta_tag.py
Normal file
20
frappe/website/doctype/website_meta_tag/website_meta_tag.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class WebsiteMetaTag(Document):
|
||||
def get_content(self):
|
||||
# can't have new lines in meta content
|
||||
return (self.value or '').replace('\n', ' ')
|
||||
|
||||
def set_metatags(meta_tags, context):
|
||||
context.setdefault('metatags', frappe._dict({}))
|
||||
|
||||
for row in meta_tags:
|
||||
context.metatags[row.key] = row.get_content()
|
||||
|
||||
return context
|
||||
Loading…
Add table
Reference in a new issue