From 916154277916d87b6e502dd572a97774c0930c40 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 27 Feb 2014 12:32:46 +0530 Subject: [PATCH] statics will now read js/css and other fixes --- frappe/templates/includes/blog.js | 2 +- frappe/website/sitemap.py | 8 ++++--- frappe/website/statics.py | 40 +++++++++++++++++-------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/frappe/templates/includes/blog.js b/frappe/templates/includes/blog.js index ea75a698ba..69eb248a4a 100644 --- a/frappe/templates/includes/blog.js +++ b/frappe/templates/includes/blog.js @@ -53,7 +53,7 @@ var blog = { \ \
\ -

%(title)s

\ +

%(title)s

\

%(content)s

\

\ \ diff --git a/frappe/website/sitemap.py b/frappe/website/sitemap.py index 38c2a32494..5b1efb829f 100644 --- a/frappe/website/sitemap.py +++ b/frappe/website/sitemap.py @@ -59,12 +59,13 @@ def set_sidebar_items(sitemap_options, pathname, home_page): else: sitemap_options.children = frappe.db.sql("""select * from `tabWebsite Route` where ifnull(parent_website_route,'')=%s - and public_read=1 order by -idx desc, page_title asc""", pathname, as_dict=True) + and public_read=1 + order by idx, page_title asc""", pathname, as_dict=True) if sitemap_options.children: # if children are from generator and sort order is specified, then get that condition website_template = frappe.doc("Website Template", sitemap_options.children[0].website_template) - if website_template.sort_by: + if website_template.sort_by!="name": sitemap_options.children = frappe.db.sql("""select t1.* from `tabWebsite Route` t1, `tab{ref_doctype}` t2 where ifnull(t1.parent_website_route,'')=%s @@ -72,4 +73,5 @@ def set_sidebar_items(sitemap_options, pathname, home_page): and t1.docname = t2.name order by t2.{sort_by} {sort_order}""".format(**website_template.fields), pathname, as_dict=True) - + + print sitemap_options.children diff --git a/frappe/website/statics.py b/frappe/website/statics.py index d48b70b47e..7649c59eb7 100644 --- a/frappe/website/statics.py +++ b/frappe/website/statics.py @@ -107,24 +107,21 @@ class sync(object): ["name", "idx", "static_file_timestamp", "docname"], as_dict=True) if route_details: - self.update_web_page(route_details, fpath, priority) + self.update_web_page(route_details, fpath, priority, parent_website_route) else: # Route does not exist, new page self.insert_web_page(route, fpath, page_name, priority, parent_website_route) def insert_web_page(self, route, fpath, page_name, priority, parent_website_route): - title, content = get_static_content(fpath) - if not title: - title = page_name.replace("-", " ").replace("_", " ").title() page = frappe.bean({ "doctype":"Web Page", "idx": priority, - "title": title, "page_name": page_name, - "main_section": content, "published": 1, "parent_website_route": parent_website_route }) + + page.doc.fields.update(get_static_content(fpath, page_name)) try: page.insert() @@ -149,17 +146,13 @@ class sync(object): print route_bean.doc.name + " inserted" self.synced.append(route) - def update_web_page(self, route_details, fpath, priority): + def update_web_page(self, route_details, fpath, priority, parent_website_route): if str(cint(os.path.getmtime(fpath)))!= route_details.static_file_timestamp \ or (cint(route_details.idx) != cint(priority) and (priority is not None)): page = frappe.bean("Web Page", route_details.docname) - title, content = get_static_content(fpath) - page.doc.main_section = content + page.doc.fields.update(get_static_content(fpath, route_details.docname)) page.doc.idx = priority - if not title: - title = route_details.docname.replace("-", " ").replace("_", " ").title() - page.doc.title = title page.save() route_bean = frappe.bean("Website Route", route_details.name) @@ -185,9 +178,9 @@ class sync(object): order by (rgt-lft) asc""")) -def get_static_content(fpath): +def get_static_content(fpath, docname): + d = frappe._dict({}) with open(fpath, "r") as contentfile: - title = None content = unicode(contentfile.read(), 'utf-8') if fpath.endswith(".md"): @@ -196,11 +189,22 @@ def get_static_content(fpath): first_line = lines[0].strip() if first_line.startswith("# "): - title = first_line[2:] + d.title = first_line[2:] content = "\n".join(lines[1:]) content = markdown(content) - content = unicode(content.encode("utf-8"), 'utf-8') - - return title, content + d.main_section = unicode(content.encode("utf-8"), 'utf-8') + if not d.title: + d.title = docname.replace("-", " ").replace("_", " ").title() + + for extn in ("js", "css"): + fpath = fpath.rsplit(".", 1)[0] + "." + extn + if os.path.exists(fpath): + with open(fpath, "r") as f: + d[extn] = f.read() + + d.insert_style = 1 if d.css else 0 + d.insert_code = 1 if d.js else 0 + + return d