Ver a proveniência

statics will now read js/css and other fixes

version-14
Rushabh Mehta há 11 anos
ascendente
cometimento
9161542779
3 ficheiros alterados com 28 adições e 22 eliminações
  1. +1
    -1
      frappe/templates/includes/blog.js
  2. +5
    -3
      frappe/website/sitemap.py
  3. +22
    -18
      frappe/website/statics.py

+ 1
- 1
frappe/templates/includes/blog.js Ver ficheiro

@@ -53,7 +53,7 @@ var blog = {
</div>\
</div>\
<div class="col-md-11">\
<h4><a href="/%(page_name)s">%(title)s</a></h4>\
<a href="/%(page_name)s"><h4>%(title)s</h4></a>\
<p>%(content)s</p>\
<p style="color: #aaa; font-size: 90%">\
<a href="/blog?by=%(blogger)s&by_name=%(full_name)s">\


+ 5
- 3
frappe/website/sitemap.py Ver ficheiro

@@ -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

+ 22
- 18
frappe/website/statics.py Ver ficheiro

@@ -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

Carregando…
Cancelar
Guardar