Plume/templates/macros.html.tera
fdb-hiroshima 449641d158
Add a search engine into Plume (#324)
* Add search engine to the model

Add a Tantivy based search engine to the model
Implement most required functions for it

* Implement indexing and plm subcommands

Implement indexation on insert, update and delete
Modify func args to get the indexer where required
Add subcommand to initialize, refill and unlock search db

* Move to a new threadpool engine allowing scheduling

* Autocommit search index every half an hour

* Implement front part of search

Add default fields for search
Add new routes and templates for search and result
Implement FromFormValue for Page to reuse it on search result pagination
Add optional query parameters to paginate template's macro
Update to newer rocket_csrf, don't get csrf token on GET forms

* Handle process termination to release lock

Handle process termination
Add tests to search

* Add proper support for advanced search

Add an advanced search form to /search, in template and route
Modify Tantivy schema, add new tokenizer for some properties
Create new String query parser
Create Tantivy query AST from our own

* Split search.rs, add comment and tests

Split search.rs into multiple submodules
Add comments and tests for Query
Make user@domain be treated as one could assume
2018-12-02 17:37:51 +01:00

113 lines
4.4 KiB
Plaintext

{% macro post_card(article) %}
<div class="card">
{% if article.cover %}
<div class="cover" style="background-image: url('{{ article.cover.url }}')"></div>
{% endif %}
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
<main>
<p>
{% if article.post.subtitle | length > 0 %}
{{ article.post.subtitle }}
{% else %}
{{ article.post.content | safe | striptags | truncate(length=200) }}
{% endif %}
</p>
</main>
<p class="author">
{{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" | _(
link_1='<a href="/@/',
link_2=article.author.fqn,
link_3='/">',
name=article.author.name,
link_4="</a>")
}}
{% if article.post.published %}⋅ {{ article.date | date(format="%B %e") }}{% endif %}
⋅ <a href="/~/{{ article.blog.fqn }}/">{{ article.blog.title }}</a>
{% if not article.post.published %}⋅ {{ "Draft" | _ }}{% endif %}
</p>
</div>
{% endmacro post_card %}
{% macro input(name, label, errors="", form="", type="text", props="", optional=false, default='', details=' ') %}
<label for="{{ name }}">
{{ label | _ }}
{% if optional %}
<small>{{ "Optional" | _ }}</small>
{% endif %}
<small>{{ details | _ }}</small>
</label>
{% if errors is defined and errors[name] %}
{% for err in errors[name] %}
<p class="error">{{ err.message | default(value="Unknown error") | _ }}</p>
{% endfor %}
{% endif %}
{% set default = default[name] | default(value="") %}
<input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value=default) }}" {{ props | safe }}/>
{% endmacro input %}
{% macro paginate(page, total, previous="Previous page", next="Next page", query="") %}
{% if query %}
{% set query = query ~ "&" %}
{% endif %}
<div class="pagination">
{% if page != 1 %}
<a href="?{{ query }}page={{ page - 1 }}">{{ previous | _ }}</a>
{% endif %}
{% if page < total %}
<a href="?{{ query }}page={{ page + 1 }}">{{ next | _ }}</a>
{% endif %}
</div>
{% endmacro %}
{% macro comment(comm) %}
<div class="comment" id="comment-{{ comm.id }}">
<a class="author" href="/@/{{ comm.author.fqn }}/">
{{ macros::avatar(user=comm.author, pad=true) }}
<span class="display-name">{{ comm.author.name }}</span>
<small>@{{ comm.author.fqn }}</small>
</a>
<div class="text">
{% if comm.sensitive %}
<details>
<summary>{{ comm.spoiler_text }}</summary>
{% endif %}
{{ comm.content | safe }}
{% if comm.sensitive %}
</details>
{% endif %}
</div>
<a class="button icon icon-message-circle" href="?responding_to={{ comm.id }}">{{ "Respond" | _ }}</a>
{% for res in comm.responses %}
{{ self::comment(comm=res) }}
{% endfor %}
</div>
{% endmacro %}
{% macro tabs(links, titles, selected) %}
<div class="tabs">
{% for link in links %}
{% set idx = loop.index0 %}
<a href="{{ link }}" {% if loop.index == selected %}class="selected"{% endif %}>{{ titles[idx] | _ }}</a>
{% endfor %}
</div>
{% endmacro %}
{% macro feather(name) %}
<svg class="feather">
<use xlink:href="/static/images/feather-sprite.svg#{{ name }}"/>
</svg>
{% endmacro %}
{% macro home_feed(title, link, articles) %}
{% if articles | length > 0 %}
<h2>{{ title | _ }} &mdash; <a href="{{ link }}">{{ "View all" | _ }}</a></h2>
<div class="cards spaced">
{% for article in articles %}
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
{% endif %}
{% endmacro %}
{% macro avatar(user, size="small", pad=true) %}
<div
class="avatar {{ size }} {% if pad %}padded{% endif %}"
style="background-image: url('{{ user.avatar }}');"
title="{{ "{{ name }}'s avatar" | _(name=user.name) }}"
aria-label="{{ "{{ name }}'s avatar" | _(name=user.name) }}"
></div>
{% endmacro %}