GitHub Action
Tinysearch Action
tinysearch-action is a Github action to build a tinysearch engine from an index file. This action is meant to be combined with static site generators (Hugo, mdBook, ...).
This example takes a json index located in public/index.json
and outputs all wasm
and js
files to the public/wasm
directory.
- name: Build tinysearch
uses: leonhfr/tinysearch-action@v1
with:
index: public/index.json
output_dir: public/wasm
output_types: |
wasm
js
- uses: leonhfr/tinysearch-action@v1
with:
# Path to the json index.
# Optional.
index: public/index.json # default
# Path to the output directory.
# If the directory does not exist, it will be created.
# Required.
output_dir: public/wasm
# Extensions that will be copied from the tinysearch output to the output directory.
# This should be a multiline input using the pipe operator |, with one extension per line.
# Optional.
output_types: | # default
wasm
js
The tinysearch
command outputs those files:
$ ls wasm_output
demo.html # search demo
package.json # metadata
storage # no clue what this is but we don't use it
tinysearch_engine.d.ts # library typescript types
tinysearch_engine.js # library to initiate and call the tinysearch wasm
tinysearch_engine_bg.wasm # tinysearch engine asm
tinysearch_engine_bg.wasm.d.ts # wasm typescript types
Most of the time, we're only interested in the actual wasm engine (tinysearch_engine_bg.wasm
) and the Javascript glue library (tinysearch_engine.js
). By default, only those files will be copied to the output directory.
The demo.html
file is useful to have an implementation example for reference.
In addition to copying the specified file extensions to the output directory, the action outputs the list of copied files to be used in following steps. This is useful for example if some files have to be moved to other directories.
For example, the last step will echo file names:
- uses: actions/checkout@v3
- name: Build tinysearch
id: tinysearch
uses: leonhfr/tinysearch-action@v1
with:
output_dir: public/wasm
- name: List emitted files
run: |
echo ${{ steps.tinysearch.outputs.files }}
Only the scenario I'm using this action is listed at the moment, but any contributions with how you're using this action are welcome.
(Tutorial source in the tinysearch repository.)
With Hugo, the index can be built by adding a custom JSON layout. Create layouts/_default/list.json.json
:
[
{{ range $index , $e := .Site.RegularPages }}{{ if $index }}, {{end}}{{ dict "title" .Title "url" .Permalink "body" .Plain | jsonify }}{{end}}
]
Then, the config.toml
has to be updated to also output JSON:
# ...
[outputs]
home = ["html","rss","json"] # Add json to the list
# ...
The index file will be in public/index.json
(hence the action default).
Finally, use the action after building the hugo website and before publishing:
- uses: actions/checkout@v3
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.104.2'
- name: Build website
run: hugo
env:
HUGO_ENV: production
- name: Build tinysearch
uses: leonhfr/tinysearch-action@v1
with:
output_dir: public/wasm
output_types: |
wasm
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./public
The example index in fixtures/index.json
has been copied from the tinysearch repository.
To test this repository locally using act and the test.yaml
workflow, run:
# removing previous container to force rebuild test any changes
$ docker rmi act-dockeraction ; act -v
The scripts and documentation in this project are released under the MIT License.