refactor: Website Meta Tag
Meta Tags are now decoupled from docs and are maintained per route basis They will be tracked in Website Route Meta doctype where the `name` is the `route`, it keeps track of a list of `key` and `value` in a table Remove Meta Tag table from Web Page, add Set Meta Tag button helper.
This commit is contained in:
parent
8e55ecccb7
commit
7bd2d9e9dc
12 changed files with 179 additions and 16 deletions
|
|
@ -295,7 +295,8 @@
|
|||
"public/js/frappe/form/footer/timeline.js",
|
||||
"public/js/frappe/form/footer/assign_to.js",
|
||||
"public/js/frappe/form/quick_entry.js",
|
||||
"public/js/frappe/form/success_action.js"
|
||||
"public/js/frappe/form/success_action.js",
|
||||
"public/js/frappe/meta_tag.js"
|
||||
],
|
||||
"css/list.min.css": [
|
||||
"public/less/list.less",
|
||||
|
|
|
|||
20
frappe/public/js/frappe/meta_tag.js
Normal file
20
frappe/public/js/frappe/meta_tag.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
frappe.provide('frappe.model');
|
||||
frappe.provide('frappe.utils');
|
||||
|
||||
/**
|
||||
* Opens the Website Meta Tag form if it exists for {route}
|
||||
* or creates a new doc and opens the form
|
||||
*/
|
||||
frappe.utils.set_meta_tag = function(route) {
|
||||
frappe.db.exists('Website Route Meta', route)
|
||||
.then(exists => {
|
||||
if (exists) {
|
||||
frappe.set_route('Form', 'Website Route Meta', route)
|
||||
} else {
|
||||
// new doc
|
||||
const doc = frappe.model.get_new_doc('Website Route Meta');
|
||||
doc.__newname = route;
|
||||
frappe.set_route('Form', doc.doctype, doc.name)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -247,3 +247,19 @@ def add_metatags(context):
|
|||
tags['description'] = context.description
|
||||
|
||||
tags['language'] = frappe.local.lang or 'en'
|
||||
|
||||
# Get meta tags from Website Route meta
|
||||
# they can override the defaults set above
|
||||
|
||||
route = context.route
|
||||
if route == '':
|
||||
# homepage
|
||||
route = frappe.db.get_single_value('Website Settings', 'home_page')
|
||||
|
||||
is_not_file = not route.endswith(('.js', '.css'))
|
||||
if is_not_file and frappe.db.exists('Website Route Meta', route):
|
||||
context.setdefault('metatags', frappe._dict({}))
|
||||
website_route_meta = frappe.get_doc('Website Route Meta', route)
|
||||
for meta_tag in website_route_meta.meta_tags:
|
||||
d = meta_tag.get_meta_dict()
|
||||
context.metatags.update(d)
|
||||
|
|
|
|||
|
|
@ -39,5 +39,9 @@ frappe.ui.form.on("Web Page", {
|
|||
|
||||
frm.set_value("end_date", end_date);
|
||||
}
|
||||
},
|
||||
|
||||
set_meta_tags(frm) {
|
||||
frappe.utils.set_meta_tag(frm.doc.route);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -916,8 +916,8 @@
|
|||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "meta_tags",
|
||||
"fieldtype": "Table",
|
||||
"fieldname": "set_meta_tags",
|
||||
"fieldtype": "Button",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
|
|
@ -925,10 +925,9 @@
|
|||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Meta Tags",
|
||||
"label": "Set Meta Tags",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Website Meta Tag",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
|
|
@ -955,7 +954,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 20,
|
||||
"modified": "2019-02-14 00:25:01.562419",
|
||||
"modified": "2019-02-16 18:27:56.561370",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Web Page",
|
||||
|
|
|
|||
|
|
@ -118,14 +118,10 @@ 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
|
||||
}
|
||||
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ class WebsiteMetaTag(Document):
|
|||
# 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({}))
|
||||
def get_meta_dict(self):
|
||||
return {
|
||||
self.key: self.get_content()
|
||||
}
|
||||
|
||||
for row in meta_tags:
|
||||
context.metatags[row.key] = row.get_content()
|
||||
|
||||
return context
|
||||
def set_in_context(self, context):
|
||||
context.setdefault('metatags', frappe._dict({}))
|
||||
context.metatags[self.key] = self.get_content()
|
||||
return context
|
||||
|
|
|
|||
0
frappe/website/doctype/website_route_meta/__init__.py
Normal file
0
frappe/website/doctype/website_route_meta/__init__.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
class TestWebsiteRouteMeta(unittest.TestCase):
|
||||
pass
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2019, Frappe Technologies and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Website Route Meta', {
|
||||
refresh: function(frm) {
|
||||
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"autoname": "Prompt",
|
||||
"beta": 0,
|
||||
"creation": "2019-02-16 17:37:27.918909",
|
||||
"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": "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": 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": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-02-16 17:37:27.918909",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Website Route Meta",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# -*- 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 WebsiteRouteMeta(Document):
|
||||
pass
|
||||
Loading…
Add table
Reference in a new issue