~zenomat/tinywiki

6b854962dc29e66d3bbe3622cc1df6628977bfae — Adrian 1 year, 1 month ago ee346f2 search
basic, not functional yet
3 files changed, 56 insertions(+), 0 deletions(-)

M build.sh
A search.html
A search.js
M build.sh => build.sh +12 -0
@@ 47,6 47,7 @@ tree --filesfirst -f --prune -I public_html | cut -d "." -f 2- | tail -n +2 | he
	fi
done

echo -n "data = '[" > "$outdir/search.json"
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-)


@@ 89,10 90,21 @@ 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.css/$escaped_path_to_root\/assets\/css\/katex.min.css/g" "$outdir/$path/$name.html"
		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
		cat << EOF | tr -d '\n' >> "$outdir/search.json"
{ "title": "${yml_data[0]}", "url":  "$outdir/$path/$name.html", "description": "${yml_data[1]}" },
EOF
	else
		cp "$file" "$outdir/$path/$(basename $file)"
	fi
done
sed -i '$ s/.$//' "$outdir/search.json"
echo "]';" >> "$outdir/search.json"

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

rm -rf "$workdir/filetree.md"
rm -rf "$outdir/tmp"

A search.html => search.html +28 -0
@@ 0,0 1,28 @@
<!doctype html>

<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<title>Search</title>

		<meta property="og:title" content="Search">

		<link rel="icon" href="/favicon.ico">
		<link rel="icon" href="/favicon.svg" type="image/svg+xml">
		<link rel="apple-touch-icon" href="/apple-touch-icon.png">

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

	</head>

	<body>
		<div id="search-container">
			<input type="text" id="search-input" placeholder="Type your search here..." autofocus onchange = "searchChange();" onkeypress = "this.onchange();" onpaste = "this.onchange();" oninput = "this.onchange();">
			<ul id="results-container"></ul>
		</div>
	</body>
</html>

A search.js => search.js +16 -0
@@ 0,0 1,16 @@
var index;
function searchChange() {
	var term = document.getElementById("search-input").value;
	index.forEach(
		post => console.log(post.title)
	);
	console.log(term);
}

function readIndex() {
	console.log("Reading index")
	index = JSON.parse(data);
	console.log(index);
}

readIndex()