-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at unified search, /-/beta - refs #21
Using new feature from dogsheep/dogsheep-beta#29
- Loading branch information
Showing
5 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
docs-index.db: | ||
sections: | ||
sql: |- | ||
select | ||
id as key, | ||
title as title, | ||
content as search_1, | ||
null as timestamp, | ||
1 as is_public | ||
from | ||
sections | ||
display_sql: |- | ||
select | ||
page, | ||
ref, | ||
snippet( | ||
sections_fts, | ||
-1, | ||
'b4de2a49c8', | ||
'8c94a2ed4b', | ||
'...', | ||
60 | ||
) as snippet | ||
from | ||
sections | ||
join sections_fts on sections.rowid = sections_fts.rowid | ||
where | ||
sections_fts match escape_fts(:q) | ||
and id = :key | ||
display: |- | ||
<h3>Docs: <a href="https://docs.datasette.io/en/latest/{{ display.page }}.html#{{ display.ref }}">{{ title }}</a></h3> | ||
<p>{{ display.snippet.replace('b4de2a49c8', '<strong style="background-color: yellow">').replace('8c94a2ed4b', '</strong>')|safe }}</p> | ||
content.db: | ||
plugins: | ||
sql: |- | ||
select | ||
plugins.name as key, | ||
plugins.name as title, | ||
plugins.latest_release_at as timestamp, | ||
plugins.description as search_1, | ||
1 as is_public | ||
from plugins | ||
display: |- | ||
<h3>Plugin: <a href="/plugins/{{ title }}">{{ title }}</a></h3> | ||
<p>{{ search_1 }}</p> | ||
releases: | ||
sql: |- | ||
select | ||
releases.id as key, | ||
repos.name || ' ' || releases.tag_name as title, | ||
releases.published_at as timestamp, | ||
releases.body as search_1, | ||
1 as is_public | ||
from | ||
releases | ||
join repos on releases.repo = repos.id | ||
display_sql: |- | ||
select | ||
render_markdown(releases.body) as rendered_markdown, | ||
html_url | ||
from releases where id = :key | ||
display: |- | ||
<h3>Release: <a href="{{ display.html_url }}">{{ title }}</a></h3> | ||
<p>{{ display.rendered_markdown|safe }}</p> | ||
<p><small>Released {{ timestamp }}</small></p> | ||
news: | ||
sql: |- | ||
select | ||
date as key, | ||
'Datasette News: ' || date as title, | ||
date || 'T00:00:00-08:00' as timestamp, | ||
group_concat(body, ' | ||
') as search_1, | ||
1 as is_public | ||
from | ||
news | ||
group by | ||
date | ||
order by | ||
date desc | ||
display_sql: |- | ||
select | ||
render_markdown(group_concat(body, ' | ||
')) as rendered_markdown | ||
from news where date = :key | ||
display: |- | ||
<h3><a href="/news/{{ key }}">{{ title }}</a></h3> | ||
<p>{{ display.rendered_markdown|safe }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{% extends "page_base.html" %} | ||
|
||
{% block title %}Datasette search{% if q %}: {{ q }}{% endif %}{% endblock %} | ||
|
||
{% block content %} | ||
<style> | ||
.result { | ||
padding: 1em 0; | ||
border-bottom: 1px solid #666; | ||
} | ||
.result img { | ||
max-width: 100%; | ||
} | ||
.facet h2 { | ||
font-size: 1em; | ||
} | ||
.facet .x:link, | ||
.facet .x:visited, | ||
.facet .x:hover, | ||
.facet .x:focus, | ||
.facet .x:active { | ||
text-decoration: none; | ||
} | ||
.facet .label { | ||
word-wrap: break-word; | ||
} | ||
aside { | ||
float: right; | ||
width: 30%; | ||
} | ||
section.results { | ||
margin-right: 30%; | ||
padding-right: 2em; | ||
} | ||
pre, blockquote { | ||
white-space: pre-wrap; | ||
} | ||
|
||
.beta-search input { | ||
border: 1px solid #ccc; | ||
border-radius: 3px; | ||
padding: 9px 4px; | ||
margin-right: 1em; | ||
} | ||
.beta-search input[type="submit"] { | ||
color: #fff; | ||
background-color: #8484f4; | ||
border-color: #0e0c82; | ||
-webkit-appearance: button; | ||
font-weight: 400; | ||
cursor: pointer; | ||
text-align: center; | ||
vertical-align: middle; | ||
border-width: 1px; | ||
border-style: solid; | ||
padding: .4em 0.8em; | ||
font-size: 0.9rem; | ||
line-height: 1; | ||
border-radius: .25rem; | ||
} | ||
</style> | ||
<h1>Search{% if q %}: {{ q }}{% endif %}</h1> | ||
|
||
<form action="/-/beta" method="get" class="beta-search"><div> | ||
<input type="search" name="q" value="{{ q }}" id="q" style="min-width: 50%"> | ||
{% if sorted_by != "newest" %} | ||
<input type="hidden" name="sort" value="{{ sorted_by }}"> | ||
{% endif %} | ||
<input type="submit" value="Search"> | ||
{% for hidden in hiddens %} | ||
<input type="hidden" name="{{ hidden.name }}" value="{{ hidden.value }}"> | ||
{% endfor %} | ||
</div></form> | ||
|
||
<p>Got {{ intcomma(count) }} result{% if count != 1 %}s{% endif %}, sorted by | ||
<strong>{{ sorted_by }}</strong> / | ||
{% for other_sort_order in other_sort_orders %} | ||
<a href="{{ other_sort_order.url }}">{{ other_sort_order.label }}</a>{% if not loop.last %} / {% endif %} | ||
{% endfor %} | ||
</p> | ||
|
||
<aside> | ||
{% if facets %} | ||
{% for facet in facets %} | ||
{% if facet.results %} | ||
<div class="facet"> | ||
<h2>{{ facet.name }}</h2> | ||
<ul> | ||
{% for item in facet.results %} | ||
<li{% if item.selected %} class="selected"{% endif %}> | ||
{% if item.selected %} | ||
<span class="label">{{ item.label }}</span> <a href="{{ item.toggle_url }}" class="x">✖</a> | ||
{% else %} | ||
<a href="{{ item.toggle_url }}" class="label">{{ item.label }}</a> | ||
{% endif %} | ||
- <span class="count">{{ intcomma(item.count) }}</span> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
</aside> | ||
|
||
<section class="results"> | ||
{% for result in results %} | ||
<div class="result" data-table-key="{{ result.type }}:{{ result.key }}"> | ||
{{ result.output|safe }} | ||
</div> | ||
{% endfor %} | ||
</section> | ||
{% endblock %} |