def _make_doc(self, pages, path, root, block, text): attrs = block.get("attrs", {}) blocktype = block.get("type") body = block.get("body") is_root = blocktype == "root" # If a title was not passed in: if this is the root, look for a title # block, otherwise use the block text title = self._get_title(block) or paths.basename(path) container = False path = paths.basepath(path) if is_root: # Store a boolean if this page has subtopics subtopics = functions.subblock_by_id(block, "subtopics") container = subtopics and bool(subtopics.get("body")) else: blockid = functions.block_id(block) path = "%s#%s" % (path, blockid) # Look for a summary block summary = self._get_block_text(body, "summary") # Look for tags in the page attributes tags = attrs.get("tags", "").strip().replace(",", "") # Find outgoing links outgoing = [] for link in functions.find_links(block): val = link.get("value") if val: outgoing.append(pages.full_path(path, val)) outgoing = " ".join(outgoing) doctype = attrs.get("type") d = { "path": path, "status": attrs.get("status"), "category": "_", "content": functions.string(text), "title": title, "sortkey": attrs.get("sortkey") or title.lower(), "summary": summary, "grams": title, "type": doctype, "tags": tags, "icon": attrs.get("icon"), "links": outgoing, "container": container, "parent": self._get_path_attr(block, path, attrs, "parent"), "bestbet": attrs.get("bestbet"), } return d
def _index_usages(pages, logger, prefix="/examples/nodes/"): from houdinihelp.hsearch import usages_for_otl # Find all .otl files under the given prefix changed = False store = pages.store for path in store.list_all(prefix): if not pages.is_wiki_source(path): continue # Look for an hda or otl file with the same name as this wiki file bp = paths.basepath(path) exts = (".hda", ".otl") for ext in exts: p = bp + ext if store.exists(p): otlpath = p break else: continue # Check if there's a usages file already and if it's newer than the otl usagespath = bp + ".usages" if store.exists(usagespath): otlmod = store.last_modified(otlpath) usagesmod = store.last_modified(usagespath) if otlmod <= usagesmod: continue # Get the real file path corresponding to the OTL's virtual path filepath = pages.file_path(otlpath) if filepath: print("Generating usages for %s" % filepath) # Find all node usages in the OTL usages = usages_for_otl(filepath) # Write the usages to a file alongside the otl file basename = paths.basename(usagespath) parentdir = os.path.dirname(filepath) usagesfile = os.path.join(parentdir, basename) with open(usagesfile, "wb") as outfile: output = "\n".join(usages) + "\n" outfile.write(output.encode("utf8")) changed = True return changed
def _hits_to_blocks(cls, hits): for hit in hits: if paths.basename(hit["path"]) != "_index": yield cls._make_load_example(hit)
def test_basename(): assert paths.basename("") == "" assert paths.basename("/") == "" assert paths.basename("/a") == "a" assert paths.basename("/a/") == "" assert paths.basename("/a/b") == "b"