sudovanilla-website/search-sh.sh
2024-05-13 23:34:06 -04:00

39 lines
No EOL
1.4 KiB
Bash

# If the docs were updated, this script can update
# the databases for Meilisearch.
# JSON is used in Astro to create these databases.
# For whatever reason, Astro does not generate a
# valid JSON response, so the commands below `wget`
# will modify the file to remove "'" at the start
# and end, along with "\" at each part.
# So, this scripts helps generates a valid JSON file
# for Meiliseach to use.
# Meilisearch requires each item to have an ID, I don't
# setup my stuff like this. So Astro will just assign
# a random number to each item using the Math.random()
# function. I do not care for assigning the correct number.
# Example
## Script will download:
### "[{\"id\":26,\"title\":\"Introduction\"},{\"id\":88,\"title\":\"Self-Hosting\"}]" <-- This is NOT a valid JSON format
## Script will output:
### [{"id":26,"title":"Introduction"},{"id":88,"title":"Self-Hosting"}] <-- This is a valid JSON format
wget "http://localhost:2014/docs/json/minpluto.json"
mv minpluto.json minpluto-search.json
sed -i '$ s/.$//' minpluto-search.json
sed -i '0,/./s/^.//' minpluto-search.json
sed -i 's|[\]||g' minpluto-search.json
wget "http://localhost:2014/docs/json/zorn.json"
mv zorn.json zorn-search.json
sed -i '$ s/.$//' zorn-search.json
sed -i '0,/./s/^.//' zorn-search.json
sed -i 's|[\]||g' zorn-search.json
# Update Meilisearch
# Using "node" does not work, use "bun"
bun ./search.js