diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4f4991c..c1b219d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,15 +43,20 @@ jobs: run: | sqlite-utils content.db 'drop table if exists news' yaml-to-sqlite content.db news news.yaml + - name: Fetch documentation database for search index + run: curl -o docs-index.db https://latest-docs.datasette.io/docs.db - name: Import stats.json run: | curl -O https://raw.githubusercontent.com/simonw/package-stats/main/stats.json python build_stats.py content.db stats.json + - name: Build search index + run: dogsheep-beta index dogsheep-index.db dogsheep-beta.yml - name: Soundness check run: | datasette . --get "/" datasette . --get "/plugins" datasette . --get "/news" + datasette . --get "/-/beta" - name: Set up Cloud Run uses: google-github-actions/setup-gcloud@master with: @@ -62,7 +67,7 @@ jobs: run: |- gcloud config set run/region us-central1 gcloud config set project datasette-222320 - datasette publish cloudrun content.db \ + datasette publish cloudrun content.db docs-index.db dogsheep-index.db \ --service datasette-io \ --template-dir=templates \ --metadata=metadata.yml \ @@ -73,4 +78,5 @@ jobs: --install=python-dateutil \ --install=datasette-vega \ --install=datasette-atom \ - --install=datasette-graphql + --install=datasette-graphql \ + --install 'dogsheep-beta>=0.10' diff --git a/dogsheep-beta.yml b/dogsheep-beta.yml new file mode 100644 index 0000000..26db3f7 --- /dev/null +++ b/dogsheep-beta.yml @@ -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: |- +

Docs: {{ title }}

+

{{ display.snippet.replace('b4de2a49c8', '').replace('8c94a2ed4b', '')|safe }}

+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: |- +

Plugin: {{ title }}

+

{{ search_1 }}

+ 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: |- +

Release: {{ title }}

+

{{ display.rendered_markdown|safe }}

+

Released {{ timestamp }}

+ 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: |- +

{{ title }}

+

{{ display.rendered_markdown|safe }}

\ No newline at end of file diff --git a/metadata.yml b/metadata.yml index e145d44..77b25ad 100644 --- a/metadata.yml +++ b/metadata.yml @@ -25,3 +25,8 @@ databases: date desc limit 20 +plugins: + dogsheep-beta: + database: dogsheep-index + config_file: dogsheep-beta.yml + template_debug: true diff --git a/requirements.txt b/requirements.txt index af478fd..d7e7f7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ datasette-template-sql datasette-render-markdown datasette-vega datasette-atom +dogsheep-beta>=0.10 datasette-graphql sqlite-utils yaml-to-sqlite diff --git a/templates/beta.html b/templates/beta.html new file mode 100644 index 0000000..a6cfbb1 --- /dev/null +++ b/templates/beta.html @@ -0,0 +1,113 @@ +{% extends "page_base.html" %} + +{% block title %}Datasette search{% if q %}: {{ q }}{% endif %}{% endblock %} + +{% block content %} + +

Search{% if q %}: {{ q }}{% endif %}

+ + + +

Got {{ intcomma(count) }} result{% if count != 1 %}s{% endif %}, sorted by + {{ sorted_by }} / + {% for other_sort_order in other_sort_orders %} + {{ other_sort_order.label }}{% if not loop.last %} / {% endif %} + {% endfor %} +

+ + + +
+{% for result in results %} +
+ {{ result.output|safe }} +
+{% endfor %} +
+{% endblock %}