8000 feat: fields for attaching (html) meta tags in web form by NagariaHussain · Pull Request #19306 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: fields for attaching (html) meta tags in web form #19306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frappe/website/doctype/web_form/templates/web_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends "templates/web.html" %}

{% block meta_block %}
{% include "templates/includes/meta_block.html" %}
{% endblock %}

{% block breadcrumbs %}{% endblock %}

{% block header %}
Expand Down
3 changes: 3 additions & 0 deletions frappe/website/doctype/web_form/test_records.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"published": 1,
"success_url": "/manage-events",
"title": "Manage Events",
"meta_title": "Test Meta Form Title",
"meta_description": "Test Meta Form Description",
"meta_image": "https://frappe.io/files/frappe.png",
"web_form_fields": [
{
"doctype": "Web Form Field",
Expand Down
8 changes: 8 additions & 0 deletions frappe/website/doctype/web_form/test_web_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ def test_webform_render(self):
self.assertIn('data-doctype="Web Form"', content)
self.assertIn('data-path="manage-events/new"', content)
self.assertIn('source-type="Generator"', content)

def test_webform_html_meta_is_added(self):
set_request(method="GET", path="manage-events/new")
content = get_response_content("manage-events/new")

self.assertIn('<meta name="name" content="Test Meta Form Title">', content)
self.assertIn('<meta property="og:description" content="Test Meta Form Description">', content)
self.assertIn('<meta property="og:image" content="https://frappe.io/files/frappe.png">', content)
32 changes: 31 additions & 1 deletion frappe/website/doctype/web_form/web_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"success_url",
"column_break_4",
"success_message",
"meta_section",
"meta_title",
"meta_description",
"column_break_khxs",
"meta_image",
"section_break_6",
"client_script",
"custom_css"
Expand Down Expand Up @@ -328,13 +333,38 @@
"fieldname": "section_break_6",
"fieldtype": "Section Break",
"label": "Scripting / Style"
},
{
"collapsible": 1,
"fieldname": "meta_section",
"fieldtype": "Section Break",
"label": "Meta"
},
{
"fieldname": "meta_title",
"fieldtype": "Data",
"label": "Meta Title"
},
{
"fieldname": "meta_description",
"fieldtype": "Small Text",
"label": "Meta Description"
},
{
"fieldname": "column_break_khxs",
"fieldtype": "Column Break"
},
{
"fieldname": "meta_image",
"fieldtype": "Attach Image",
"label": "Meta Image"
}
],
"has_web_view": 1,
"icon": "icon-edit",
"is_published_field": "published",
"links": [],
"modified": "2022-08-17 18:58:49.451658",
"modified": "2022-12-15 17:14:44.939645",
"modified_by": "Administrator",
"module": "Website",
"name": "Web Form",
Expand Down
13 changes: 13 additions & 0 deletions frappe/website/doctype/web_form/web_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,23 @@ def get_context(self, context):

self.add_custom_context_and_script(context)
self.load_translations(context)
self.add_metatags(context)

context.boot = get_boot_data()
context.boot["link_title_doctypes"] = frappe.boot.get_link_title_doctypes()

def add_metatags(self, context):
description = self.meta_description

if not description and self.introduction_text:
description = self.introduction_text[:140]

context.metatags = {
"name": self.meta_title or self.title,
"description": description,
"image": self.meta_image
}

def load_translations(self, context):
translated_messages = frappe.translate.get_dict("doctype", self.doc_type)
# Sr is not added by default, had to be added manually
Expand Down
0