def category_page(slug): """ Index for a category or a single page """ conf = current_app.config # If we don't recognize this as a category, # try a page if slug not in current_app.fm.categories(): try: page = Page(slug) except FileNotFoundError: abort(404) template = page.template if hasattr(page, 'template') else 'page.html' return render_template(template, page=page, site_data=Meta(request)) cat = Category(slug) posts = Post.for_category(slug) per_page = cat.per_page if hasattr(cat, 'per_page') else int(conf.get('PER_PAGE')) template = cat.template if hasattr(cat, 'template') else 'category.html' posts, page, last_page = _pagination(posts, per_page) return render_template(template, posts=posts, page=page+1, category=cat, last_page=last_page, site_data=Meta(request))
def category_page(slug): """ Index for a category or a single page """ conf = current_app.config # If we don't recognize this as a category, # try a page if slug not in current_app.fm.categories(): try: page = Page(slug) except FileNotFoundError: abort(404) template = page.template if hasattr(page, 'template') else 'page.html' return render_template(template, page=page, site_data=Meta(request)) cat = Category(slug) posts = Post.for_category(slug) per_page = cat.per_page if hasattr(cat, 'per_page') else int( conf.get('PER_PAGE')) template = cat.template if hasattr(cat, 'template') else 'category.html' posts, page, last_page = _pagination(posts, per_page) return render_template(template, posts=posts, page=page + 1, category=cat, last_page=last_page, site_data=Meta(request))
def search(): """ Search posts """ conf = current_app.config per_page = int(conf.get('PER_PAGE')) query = request.args.get('query', '') posts = [] ix = whoosh.index.open_dir(current_app.fm.index_dir) with ix.searcher() as searcher: q = QueryParser('content', ix.schema).parse(query) results = searcher.search(q, limit=None) results.fragmenter.charlimit = None results.fragmenter.surround = 100 results.formatter = whoosh.highlight.HtmlFormatter(tagname='span', classname='search-match') for r in results: post = Post.single(r['category'], r['slug']) post.search_highlight = r.highlights('content', text=post.plain) # If the result is only in the title, the highlight will be empty if not post.search_highlight: post.search_highlight = post.plain[:200] posts.append(post) posts, page, last_page = _pagination(posts, per_page) return render_template('search.html', posts=posts, page=page+1, last_page=last_page, site_data=Meta(request))
def search(): """ Search posts """ conf = current_app.config per_page = int(conf.get('PER_PAGE')) query = request.args.get('query', '') posts = [] ix = whoosh.index.open_dir(current_app.fm.index_dir) with ix.searcher() as searcher: q = QueryParser('content', ix.schema).parse(query) results = searcher.search(q, limit=None) results.fragmenter.charlimit = None results.fragmenter.surround = 100 results.formatter = whoosh.highlight.HtmlFormatter( tagname='span', classname='search-match') for r in results: post = Post.single(r['category'], r['slug']) post.search_highlight = r.highlights('content', text=post.plain) # If the result is only in the title, the highlight will be empty if not post.search_highlight: post.search_highlight = post.plain[:200] posts.append(post) posts, page, last_page = _pagination(posts, per_page) return render_template('search.html', posts=posts, page=page + 1, last_page=last_page, site_data=Meta(request))
def post(category, slug): """ Show a single post; The slug is the filename of the original markdown file """ post = Post.single(category, slug) if post is not None: return render_template('single.html', post=post, site_data=Meta(request)) abort(404)
def index(): """ Index for all categories """ conf = current_app.config per_page = int(conf.get('PER_PAGE')) posts = Post.all() posts, page, last_page = _pagination(posts, per_page) return render_template('index.html', posts=posts, page=page+1, last_page=last_page, site_data=Meta(request))
def index(): """ Index for all categories """ conf = current_app.config per_page = int(conf.get('PER_PAGE')) posts = Post.all() posts, page, last_page = _pagination(posts, per_page) return render_template('index.html', posts=posts, page=page + 1, last_page=last_page, site_data=Meta(request))