~zenomat/tinywiki

ffd20b8e45f35928dab52ff03820ecba01659f15 — Adrian 8 months ago 754276a master
fix search, by also cleaning description and title
3 files changed, 9 insertions(+), 7 deletions(-)

M build.sh
M extract_markdown.py -rwxr-xr-x => -rw-r--r--
M search.html
M build.sh => build.sh +8 -6
@@ 61,7 61,7 @@ cat << EOF >> "$outdir/filetree.html"
</html>
EOF

echo -n "data = '[" > "$outdir/search.json"
echo -n "data = '[" > "$outdir/search.js"
find . -type f -not -name ".gitignore" -not -path "./public_html/*" -not -path "./.git/*" | while read -r file; do
	echo "Working on $file"
	file=$(echo $file | cut -c 3-)


@@ 104,12 104,14 @@ find . -type f -not -name ".gitignore" -not -path "./public_html/*" -not -path "
		sed -i "s/https:\/\/cdn.jsdelivr.net\/npm\/katex@[0-9]*\.[0-9]*\.[0-9]*\/dist\/katex.min.js/$escaped_path_to_root\/assets\/js\/katex.min.js/g" "$outdir/$path/$name.html"

		# build search index
		title="$(echo ${yml_data[0]} | tr -d "'" | tr -d '"' | tr -d '\\')";
		body="$(cat "$path/$name.md" | tr -d "'" | tr -d '"' | tr -d '\\')";
		cat << EOF | tr -d '\n' | tr -d '\t' >> "$outdir/search.json"
		description="$(echo ${yml_data[1]} | tr -d "'" | tr -d '"' | tr -d '\\')";
		cat << EOF | tr -d '\n' | tr -d '\t' >> "$outdir/search.js"
{
	"title": "${yml_data[0]}",
	"title": "$title",
	"url":  "$path/$name.html",
	"description": "${yml_data[1]}",
	"description": "$description",
	"body": "${body}"
},
EOF


@@ 117,8 119,8 @@ EOF
		cp "$file" "$outdir/$path/$(basename $file)"
	fi
done
sed -i '$ s/.$//' "$outdir/search.json"
echo "]';" >> "$outdir/search.json"
sed -i '$ s/.$//' "$outdir/search.js"
echo "]';" >> "$outdir/search.js"

# build search site
cp "$HOME/.local/share/tinywiki/search.html" "$outdir"

M extract_markdown.py => extract_markdown.py +0 -0
M search.html => search.html +1 -1
@@ 14,7 14,7 @@
		<link rel="apple-touch-icon" href="/apple-touch-icon.png">

		<link rel="stylesheet" href="assets/css/style.css">
		<script type="text/javascript" src="search.json"></script>
		<script type="text/javascript" src="search.js"></script>
		<script type="text/javascript" src="assets/js/search.js"></script>

	</head>