summaryrefslogtreecommitdiffstats
path: root/front_end/templates/serp.rs.html
blob: c5087243e82ef81579f5094898dd4ea38cab895e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
@use crate::templates::base;
@use crate::Urler;
@use crate::limit_text_len;
@use crate::SearchPage;
@use crate::SearchKind;
@use rich_crate::Origin;

@(p: &SearchPage, url: &Urler)

@:base(&p.page(), {

<header id="serp">
    <div class="inner-col">
        <div class="breadcrumbs">
            <h1><a href="/">Lib.rs</a></h1>
            <span class="categories has-keywords"> ›
            @if let SearchKind::Keyword(_) = p.query {
                Keywords
            }
            @if let SearchKind::Query(_) = p.query {
                Search
            }
            </span>
            @if let Some(k) = Some(p.top_keywords()) {
                @if k.len() > 1 {
                <span class="keywords">
                  <span>
                    @for key in k.iter().take(3) {
                      <a href="@url.keyword(key)" class=keyword><span>#</span>@key</a>
                    }
                  </span>
                  @for key in k.iter().skip(3).take(3) {
                    <a href="@url.keyword(key)" class=keyword><span>#</span>@key</a>
                  }
                </span>
                }
            }
        </div>
        @if let SearchKind::Query(query) = p.query {
            <form role="search" id=search method="get" action="/search">
                <input placeholder="name, keywords, description" autocapitalize="off" autocorrect="off" autocomplete="off" tabindex="1" type=search value="@query" name=q><button type=submit>Search</button>
            </form>
            <nav>
                <ul>
                    @if !p.good_results.is_empty() {
                        <li class=active>Sorted by relevance</li>
                    }
                    <li><a href="@url.search_ddg(query)">I'm feeling ducky</a></li>
                </ul>
            </nav>
        }
        @if let SearchKind::Keyword(k) = p.query {
            <h2>#@k</h2>
            <nav>
                <ul>
                    @if !p.good_results.is_empty() {
                        <li class=active>Keyword</li>
                    }
                    <li><a href="@url.search_crates_rs(k)">Search</a></li>
                </ul>
            </nav>
        }
    </div>
</header>
<main id="results">
    <div class="inner-col">
        @if p.good_results.is_empty() {
            <p class=notfound>Nothing found :(</p>
            @if let SearchKind::Query(query) = p.query {
                <p class=tryalso>Try <a href="@url.search_ddg(query)">searching with DuckDuckGo</a> or <a href="@url.search_crates_io(query)">on crates.io</a>.</p>
            }
        } else {
            <ol>
            @for (i, c) in p.good_results.iter().chain(p.bad_results).enumerate() {
                <li>
                    <a href="@url.crate_by_origin(&c.origin)"><div class=h>
                        <h4>@if let Some((repo, _)) = c.origin.repo() {@repo.owner/}@c.crate_name</h4>
                        <p class=desc>@p.render_markdown_str(&limit_text_len(&c.description, 180, 220))</p>
                    </div>
                    <div class=meta>
                        <span class="version @p.version_class(&c.version)"><span>@if let Origin::GitHub{..} = c.origin {GitHub } else {v}</span>@c.version</span>
                        @if c.monthly_downloads >= 100 {
                            <span class=downloads title="@c.monthly_downloads recent downloads">@if let Some((num,unit)) = Some(p.downloads(c.monthly_downloads)) {@num<b>@unit</b>}</span>
                        }
                        @for k in c.keywords.split(", ").filter(|k| !k.is_empty()) {
                            <span class=k><span>#</span>@k</span>
                        }
                    </div></a>
                </li>
                @if i == p.good_results.len() {
                    @if let SearchKind::Query(query) = p.query {
                        <p class=tryalso><a href="https://forms.gle/HfbvBSryNk19exUm7">Report poor search results</a>. Try <a href="@url.search_ddg(query)">searching with DuckDuckGo</a> or <a href="@url.search_crates_io(query)">on crates.io</a>.</p>
                    }
                }
            }
            @if let SearchKind::Keyword(_) = p.query {
                <p class=tryalso><a href="https://forms.gle/SFntxLhGJB7xzFy19">Feedback on crate ranking</a></p>
            }
            </ol>
        }
    </div>
</main>

<footer>
    <div class="inner-col">
        <p>Search powered by <a href="https://lib.rs/crates/tantivy">tantivy</a>.</p>
        <p>Browse <a href="/">all categories</a>.
    </div>
</footer>
})