def get_summary(title): try: title, text = get(datafile, indexfile, title, raw=True) wikicode = mwparserfromhell.parse(text) summary = wikicode.get_sections()[0].strip_code() except Exception: print('Exception caught in get_summary(): {}'.format(title)) summary = get_remote_summary(title) return summary
def get_links(title): try: title, text = get(datafile, indexfile, title, raw=True) wikicode = mwparserfromhell.parse(text) links = [ x.title.strip_code().strip() for x in wikicode.filter_wikilinks() ] except Exception: print('Exception caught in get_links(): {}'.format(title)) links = get_remote_links(title) return links
def related(macro, environ, predicate, obj): """Gets links to related items.""" import wiki links = [] predicate = to_slug(predicate) obj = to_slug(obj) for slug in wiki.ask("*", predicate, obj): node = wiki.get(slug) if node: links.append( HTML(render_template(["plate/%s.html" % node.get('type', 'default'), "plate/default.html"], node=node)) ) else: links.append( tag.a(slug, href=slug) ) return tag.div(links, class_="related")
def get_node_or_shell(slug): node = wiki.get(slug) if node is not None: return node if slug.startswith('type:'): return { 'slug': slug, 'type': 'type', '_html': '<p><em>No content yet.</em></p>', '_empty': True } return { 'slug': slug, 'type': 'document', 'name': slug, 'content': '', '_html': '<p><em>No content yet.</em></p>', '_empty': True }