[website] add content to web page for search and add javascript globals via hooks
This commit is contained in:
parent
acc314d0ab
commit
c26769e6e7
4 changed files with 34 additions and 11 deletions
|
|
@ -37,6 +37,13 @@
|
|||
{%- endfor -%}
|
||||
{%- block head_include %}{{ head_include or "" }}{% endblock -%}
|
||||
{%- endblock -%}
|
||||
{%- if js_globals is defined %}
|
||||
<script>
|
||||
{%- for key, value in js_globals.iteritems() %}
|
||||
window.{{ key }} = "{{ value[0] }}";
|
||||
{%- endfor -%}
|
||||
</script>
|
||||
{% endif -%}
|
||||
</head>
|
||||
<body>
|
||||
<div class="offcanvas-container">
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@
|
|||
"icon": "icon-file-alt",
|
||||
"idx": 1,
|
||||
"max_attachments": 20,
|
||||
"modified": "2015-03-23 17:57:49.375385",
|
||||
"modified": "2015-03-24 11:22:36.357479",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Web Page",
|
||||
|
|
@ -219,6 +219,19 @@
|
|||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"create": 0,
|
||||
"delete": 0,
|
||||
"email": 0,
|
||||
"export": 0,
|
||||
"permlevel": 0,
|
||||
"print": 0,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "Guest",
|
||||
"share": 0,
|
||||
"write": 0
|
||||
}
|
||||
],
|
||||
"search_fields": "title,main_section",
|
||||
|
|
|
|||
|
|
@ -446,7 +446,8 @@ $.extend(frappe, {
|
|||
});
|
||||
},
|
||||
do_search: function(val) {
|
||||
var path = (frappe.search_path && frappe.search_path[location.pathname] || location.pathname);
|
||||
var path = (frappe.search_path && frappe.search_path[location.pathname]
|
||||
|| window.search_path || location.pathname);
|
||||
frappe.load_via_ajax(path + "?txt=" + encodeURIComponent(val));
|
||||
},
|
||||
set_search_path: function(path) {
|
||||
|
|
|
|||
|
|
@ -111,13 +111,18 @@ class sync(object):
|
|||
if (parent_web_page, page_name) in self.synced:
|
||||
return
|
||||
|
||||
title = self.get_title(template_path)
|
||||
|
||||
with open(template_path, "r") as f:
|
||||
content = unicode(f.read().strip(), "utf-8")
|
||||
|
||||
title = self.get_title(template_path, content)
|
||||
|
||||
if not frappe.db.get_value("Web Page", {"template_path":template_path}):
|
||||
web_page = frappe.new_doc("Web Page")
|
||||
web_page.page_name = page_name
|
||||
web_page.parent_web_page = parent_web_page
|
||||
web_page.template_path = template_path
|
||||
web_page.main_section = content
|
||||
web_page.title = title
|
||||
web_page.published = published
|
||||
web_page.idx = idx
|
||||
|
|
@ -140,21 +145,18 @@ class sync(object):
|
|||
|
||||
self.synced.append((parent_web_page, page_name))
|
||||
|
||||
def get_title(self, fpath):
|
||||
def get_title(self, fpath, content):
|
||||
title = os.path.basename(fpath).rsplit(".", 1)[0]
|
||||
if title =="index":
|
||||
title = os.path.basename(os.path.dirname(fpath))
|
||||
|
||||
title = title.replace("-", " ").replace("_", " ").title()
|
||||
|
||||
with open(fpath, "r") as f:
|
||||
content = unicode(f.read().strip(), "utf-8")
|
||||
if content.startswith("# "):
|
||||
title = content.splitlines()[0][2:]
|
||||
|
||||
if content.startswith("# "):
|
||||
title = content.splitlines()[0][2:]
|
||||
|
||||
if "<!-- title:" in content:
|
||||
title = content.split("<!-- title:", 1)[1].split("-->", 1)[0].strip()
|
||||
if "<!-- title:" in content:
|
||||
title = content.split("<!-- title:", 1)[1].split("-->", 1)[0].strip()
|
||||
|
||||
return title
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue