def get_context(context): """generate the sitemap XML""" # the site might be accessible from multiple host_names # for e.g gadgets.erpnext.com and gadgetsinternational.com # so it should be picked from the request host = frappe.utils.get_host_name_from_request() links = [] for route, page in iteritems(get_pages()): if not page.sitemap: links.append({ "loc": urljoin(host, quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in iteritems(get_public_pages_from_doctypes()): links.append({ "loc": urljoin(host, quote((route or "").encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links": links}
def get_full_index(route=None, extn=False): """Returns full index of the website for www upto the n-th level""" if not frappe.local.flags.children_map: from frappe.website.router import get_pages children_map = {} pages = get_pages() # make children map for route, page_info in pages.iteritems(): parent_route = os.path.dirname(route) children_map.setdefault(parent_route, []).append(page_info) # order as per index if present for route, children in children_map.items(): page_info = pages[route] if page_info.index: new_children = [] for name in page_info.index: child_route = page_info.route + '/' + name if child_route in pages: new_children.append(pages[child_route]) # add remaining pages not in index.txt for c in children: if c not in new_children: new_children.append(c) children_map[route] = new_children frappe.local.flags.children_map = children_map return frappe.local.flags.children_map
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for page in get_pages(): if not page.no_sitemap: links.append({ "loc": urllib.basejoin(host, urllib.quote(page.name.encode("utf-8"))), "lastmod": "2014-01-01" }) def add_links(doctype, condition_field, order_by): meta = frappe.get_meta(doctype) page_name = "page_name" condition = "" if meta.get_field("parent_website_route"): page_name = """concat(ifnull(parent_website_route, ""), if(ifnull(parent_website_route, "")="", "", "/"), page_name)""" if condition_field: condition ="where ifnull({0}, 0)=1".format(condition_field) for route in frappe.db.sql("select {0}, modified from `tab{1}` {2}".format(page_name, doctype, condition)): if route[0]: links.append({ "loc": urllib.basejoin(host, urllib.quote(route[0].encode("utf-8"))), "lastmod": get_datetime(route[1]).strftime("%Y-%m-%d") }) process_generators(add_links) return {"links":links}
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for route, page in iteritems(get_pages()): if not page.no_sitemap: links.append({ <<<<<<< HEAD "loc": urllib.basejoin(host, quote(page.name.encode("utf-8"))), ======= "loc": urljoin(host, quote(page.name.encode("utf-8"))), >>>>>>> 176d241496ede1357a309fa44a037b757a252581 "lastmod": nowdate() }) for route, data in iteritems(get_all_page_context_from_doctypes()): links.append({ <<<<<<< HEAD "loc": urllib.basejoin(host, quote((route or "").encode("utf-8"))), ======= "loc": urljoin(host, quote((route or "").encode("utf-8"))), >>>>>>> 176d241496ede1357a309fa44a037b757a252581 "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links":links}
def _build(): children_map = {} added = [] pages = get_pages(app=app) # make children map for route, page_info in iteritems(pages): parent_route = os.path.dirname(route) if parent_route not in added: children_map.setdefault(parent_route, []).append(page_info) # order as per index if present for route, children in children_map.items(): if not route in pages: # no parent (?) continue page_info = pages[route] if page_info.index or ("index" in page_info.template): new_children = [] page_info.extn = "" for name in page_info.index or []: child_route = page_info.route + "/" + name if child_route in pages: if child_route not in added: new_children.append(pages[child_route]) added.append(child_route) # add remaining pages not in index.txt _children = sorted( children, key=functools.cmp_to_key( lambda a, b: cmp(os.path.basename(a.route), os.path.basename(b.route))), ) for child_route in _children: if child_route not in new_children: if child_route not in added: new_children.append(child_route) added.append(child_route) children_map[route] = new_children return children_map
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for route, page in iteritems(get_pages()): if page.sitemap: links.append({ "loc": urljoin(host, quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in iteritems(get_public_pages_from_doctypes()): links.append({ "loc": urljoin(host, quote((route or "").encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links":links}
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for route, page in iteritems(get_pages()): if not page.no_sitemap: links.append({ "loc": urljoin(host, quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in iteritems(get_all_page_context_from_doctypes()): links.append({ "loc": urljoin(host, quote((route or "").encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links":links}
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for page in get_pages(): if not page.no_sitemap: links.append({ "loc": urllib.basejoin(host, urllib.quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in get_generator_routes().iteritems(): links.append({ "loc": urllib.basejoin(host, urllib.quote(route.encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links":links}
def _build(): children_map = {} added = [] pages = get_pages(app=app) # make children map for route, page_info in pages.items(): parent_route = os.path.dirname(route) if parent_route not in added: children_map.setdefault(parent_route, []).append(page_info) # order as per index if present for route, children in children_map.items(): if not route in pages: # no parent (?) continue page_info = pages[route] if page_info.index or ('index' in page_info.template): new_children = [] page_info.extn = '' for name in (page_info.index or []): child_route = page_info.route + '/' + name if child_route in pages: if child_route not in added: new_children.append(pages[child_route]) added.append(child_route) # add remaining pages not in index.txt _children = sorted(children, key=lambda x: os.path.basename(x.route)) for child_route in _children: if child_route not in new_children: if child_route not in added: new_children.append(child_route) added.append(child_route) children_map[route] = new_children return children_map
def _build(): children_map = {} added = [] pages = get_pages(app=app) # make children map for route, page_info in iteritems(pages): parent_route = os.path.dirname(route) if parent_route not in added: children_map.setdefault(parent_route, []).append(page_info) # order as per index if present for route, children in children_map.items(): if not route in pages: # no parent (?) continue page_info = pages[route] if page_info.index or ('index' in page_info.template): new_children = [] page_info.extn = '' for name in (page_info.index or []): child_route = page_info.route + '/' + name if child_route in pages: if child_route not in added: new_children.append(pages[child_route]) added.append(child_route) # add remaining pages not in index.txt _children = sorted(children, lambda a, b: cmp( os.path.basename(a.route), os.path.basename(b.route))) for child_route in _children: if child_route not in new_children: if child_route not in added: new_children.append(child_route) added.append(child_route) children_map[route] = new_children return children_map
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] robots = frappe.db.get_single_value("Website Settings", 'robots_txt').replace( 'Disallow: /', '').split('\n') for route, page in iteritems(get_pages()): flag = route not in robots if '/' in route: route_1 = route.split('/')[0] rb = [d.split('/')[0] for d in robots if '/*' in d] flag = route_1 not in rb if not page.no_sitemap and flag: links.append({ "loc": urljoin(host, quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in iteritems(get_all_page_context_from_doctypes()): flag = route not in robots if '/' in route: route_1 = route.split('/')[0] rb = [d.split('/')[0] for d in robots if '/*' in d] flag = route_1 not in rb if flag: links.append({ "loc": urljoin(host, quote((route or "").encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links": links}
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for page in get_pages(): if not page.no_sitemap: links.append({ "loc": urllib.basejoin(host, urllib.quote(page.name.encode("utf-8"))), "lastmod": nowdate() }) for route, data in get_generator_routes().iteritems(): links.append({ "loc": urllib.basejoin(host, urllib.quote(route.encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d") }) return {"links": links}
def get_full_index(route=None, app=None): """Returns full index of the website for www upto the n-th level""" if not frappe.local.flags.children_map: from frappe.website.router import get_pages children_map = {} pages = get_pages(app=app) # make children map for route, page_info in pages.iteritems(): parent_route = os.path.dirname(route) children_map.setdefault(parent_route, []).append(page_info) if frappe.flags.local_docs: page_info.extn = '.html' # order as per index if present for route, children in children_map.items(): page_info = pages[route] if page_info.index: new_children = [] page_info.extn = '' for name in page_info.index: child_route = page_info.route + '/' + name if child_route in pages: new_children.append(pages[child_route]) # add remaining pages not in index.txt for c in children: if c not in new_children: new_children.append(c) children_map[route] = new_children frappe.local.flags.children_map = children_map return frappe.local.flags.children_map
def write_files(self): """render templates and write files to target folder""" frappe.flags.home_page = "index" from frappe.website.router import get_pages, make_toc pages = get_pages(self.app) # clear the user, current folder in target shutil.rmtree(os.path.join(self.target, "user"), ignore_errors=True) shutil.rmtree(os.path.join(self.target, "current"), ignore_errors=True) def raw_replacer(matchobj): if '{% raw %}' in matchobj.group(0): return matchobj.group(0) else: return '{% raw %}' + matchobj.group(0) + '{% endraw %}' cnt = 0 for path, context in pages.iteritems(): print "Writing {0}".format(path) # set this for get_context / website libs frappe.local.path = path context.update({ "page_links_with_extn": True, "relative_links": True, "docs_base_url": self.docs_base_url, "url_prefix": self.docs_base_url, }) context.update(self.app_context) context = get_context(path, context) if context.basename: target_path_fragment = context.route + '.html' else: # index.html target_path_fragment = context.route + '/index.html' target_filename = os.path.join(self.target, target_path_fragment.strip('/')) context.brand_html = context.app.brand_html context.top_bar_items = context.favicon = None self.docs_config.get_context(context) if not context.brand_html: if context.docs_icon: context.brand_html = '<i class="{0}"></i> {1}'.format(context.docs_icon, context.app.title) else: context.brand_html = context.app.title if not context.top_bar_items: context.top_bar_items = [ # {"label": "Contents", "url": self.docs_base_url + "/contents.html", "right": 1}, {"label": "User Guide", "url": self.docs_base_url + "/user", "right": 1}, {"label": "Developer Docs", "url": self.docs_base_url + "/current", "right": 1}, ] context.top_bar_items = [{"label": '<i class="octicon octicon-search"></i>', "url": "#", "right": 1}] + context.top_bar_items context.parents = [] parent_route = os.path.dirname(context.route) if pages[parent_route]: context.parents = [pages[parent_route]] context.only_static = True context.base_template_path = "templates/autodoc/base_template.html" if '<code>' in context.source: context.source = re.sub('\<code\>(.*)\</code\>', raw_replacer, context.source) html = frappe.render_template(context.source, context) html = make_toc(context, html, self.app) if not "<!-- autodoc -->" in html: html = html.replace('<!-- edit-link -->', edit_link.format(\ source_link = self.docs_config.source_link, app_name = self.app, branch = context.app.branch, target = context.template)) if not os.path.exists(os.path.dirname(target_filename)): os.makedirs(os.path.dirname(target_filename)) with open(target_filename, "w") as htmlfile: htmlfile.write(html.encode("utf-8")) cnt += 1 print "Wrote {0} files".format(cnt)
def get_context(context): """generate the sitemap XML""" host = frappe.utils.get_host_name_from_request() links = [] robots = frappe.db.get_single_value("Website Settings", 'robots_txt').replace( 'Disallow: /', '').replace('\r', '').split('\n') for route, page in iteritems(get_pages()): print(route) flag = route not in robots if '/' in route: route_1 = route.split('/')[0] rb = [d.split('/')[0] for d in robots if '/*' in d] flag = route_1 not in rb print(flag) if flag: priority = 0.4 if page.route in ("company", "contact", "home"): priority = 0.9 elif page.route == "clients": priority = 0.6 else: priority = 0.4 links.append({ "loc": urljoin(host, quote(page.name.encode("utf-8"))), "lastmod": nowdate(), "priority": priority }) for route, data in iteritems(get_all_page_context_from_doctypes()): flag = route not in robots if '/' in route: route_1 = route.split('/')[0] rb = [d.split('/')[0] for d in robots if '/*' in d] flag = route_1 not in rb if flag: priority = 0.5 if data.get("doctype") == "Web Page": priority = 0.9 elif data.get("doctype") == "Job Opening": priority = 0.7 elif data.get("doctype") == "Blog Post": priority = 0.8 else: priority = 0.5 links.append({ "loc": urljoin(host, quote((route or "").encode("utf-8"))), "lastmod": get_datetime(data.get("modified")).strftime("%Y-%m-%d"), "priority": priority }) return {"links": links}