Bladeren bron

minor

version-14
Rushabh Mehta 11 jaren geleden
bovenliggende
commit
bc9f78f72f
2 gewijzigde bestanden met toevoegingen van 28 en 14 verwijderingen
  1. +3
    -2
      webnotes/website/doctype/post/post.py
  2. +25
    -12
      webnotes/website/doctype/web_page/web_page.py

+ 3
- 2
webnotes/website/doctype/post/post.py Bestand weergeven

@@ -9,8 +9,6 @@ import webnotes
from webnotes.utils import get_fullname from webnotes.utils import get_fullname
from webnotes.utils.email_lib.bulk import send from webnotes.utils.email_lib.bulk import send
from webnotes.utils.email_lib import sendmail from webnotes.utils.email_lib import sendmail
from webnotes.templates.generators.website_group import clear_cache
from webnotes.templates.website_group.post import clear_post_cache


class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
@@ -39,6 +37,9 @@ class DocType:
self.doc.event_datetime = None self.doc.event_datetime = None
def on_update(self): def on_update(self):
from webnotes.templates.website_group.post import clear_post_cache
from webnotes.templates.generators.website_group import clear_cache

clear_cache(website_group=self.doc.website_group) clear_cache(website_group=self.doc.website_group)
clear_post_cache(self.doc.parent_post or self.doc.name) clear_post_cache(self.doc.parent_post or self.doc.name)




+ 25
- 12
webnotes/website/doctype/web_page/web_page.py Bestand weergeven

@@ -2,7 +2,7 @@
# MIT License. See license.txt # MIT License. See license.txt


from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes, os
import webnotes, os, time
from webnotes.webutils import WebsiteGenerator from webnotes.webutils import WebsiteGenerator
from webnotes import _ from webnotes import _
from webnotes.utils import cint from webnotes.utils import cint
@@ -35,8 +35,14 @@ class DocType(WebsiteGenerator):
if self.doclist.get({"parentfield": "toc"}): if self.doclist.get({"parentfield": "toc"}):
from webnotes.webutils import clear_cache from webnotes.webutils import clear_cache
clear_cache() clear_cache()
def sync_statics(): def sync_statics():
while True:
_sync_statics()
webnotes.conn.commit()
time.sleep(2)

def _sync_statics():
synced = [] synced = []
to_insert = [] to_insert = []
@@ -56,8 +62,9 @@ def sync_statics():
page = webnotes.bean("Web Page", sitemap.doc.docname) page = webnotes.bean("Web Page", sitemap.doc.docname)
title, content = get_static_content(fpath) title, content = get_static_content(fpath)
page.doc.main_section = content page.doc.main_section = content
if title:
page.doc.title = title
if not title:
title = page_name.replace("-", " ").replace("_", " ").title()
page.doc.title = title
page.save() page.save()


sitemap = webnotes.bean("Website Sitemap", url) sitemap = webnotes.bean("Website Sitemap", url)
@@ -88,6 +95,7 @@ def sync_statics():
for basepath, folders, files in os.walk(statics_path): for basepath, folders, files in os.walk(statics_path):
# index file first! # index file first!
index = [] index = []
has_index = False
if "index.txt" in files: if "index.txt" in files:
with open(os.path.join(basepath, "index.txt"), "r") as indexfile: with open(os.path.join(basepath, "index.txt"), "r") as indexfile:
index = indexfile.read().splitlines() index = indexfile.read().splitlines()
@@ -96,11 +104,15 @@ def sync_statics():
page_name = fname.rsplit(".", 1)[0] page_name = fname.rsplit(".", 1)[0]
if page_name=="index" and fname!="index.txt": if page_name=="index" and fname!="index.txt":
sync_file(fname, os.path.join(basepath, fname), statics_path) sync_file(fname, os.path.join(basepath, fname), statics_path)
has_index = True
break break
if not has_index:
continue
# other files # other files
for fname in files: for fname in files:
page_name = fname.rsplit(".", 1)[0]
page_name = fname.rsplit(".", 1)[0]
if page_name!="index": if page_name!="index":
sync_file(fname, os.path.join(basepath, fname), statics_path, sync_file(fname, os.path.join(basepath, fname), statics_path,
index.index(page_name) if page_name in index else 0) index.index(page_name) if page_name in index else 0)
@@ -132,14 +144,15 @@ def get_static_content(fpath):
content = unicode(contentfile.read(), 'utf-8') content = unicode(contentfile.read(), 'utf-8')


if fpath.endswith(".md"): if fpath.endswith(".md"):
lines = content.splitlines()
first_line = lines[0].strip()
if content:
lines = content.splitlines()
first_line = lines[0].strip()


if first_line.startswith("# "):
title = first_line[2:]
content = "\n".join(lines[1:])
if first_line.startswith("# "):
title = first_line[2:]
content = "\n".join(lines[1:])


content = markdown(content)
content = markdown(content)
content = unicode(content.encode("utf-8"), 'utf-8') content = unicode(content.encode("utf-8"), 'utf-8')


Laden…
Annuleren
Opslaan