computational-thinking
computational-thinking copied to clipboard
Add the ability to search the website
@tlienart when I try this out locally, I cannot get any search results to render but I am not sure what is wrong. Any suggestions?
Closes #64
This is almost good to go, just in your head.html you need to include the other JS files, to make it simpler, copy paste:
<!-- LUNR -->
<script src="/libs/lunr/lunr.min.js"></script>
<script src="/libs/lunr/lunr_index.js"></script>
<script src="/libs/lunr/lunrclient.min.js"></script>
You might want to edit the deploy script to include a lunr step as well so that whenever the site gets updated the index does too; for this you'd need to replace this line https://github.com/mitmath/18S191/blob/e4dd66ebb41e442202633881a7f626aa6525dee1/.github/workflows/ExportNotebooks.yml#L55 by something like
run(`$(npm_cmd()) install lunr`);
run(`$(npm_cmd()) install cheerio`);
serve(single=true, cleanup=false); lunr(); optimize(minify=false);
Added those, however, it looks like things still don't work as expected, this is what I get:
And the actual links 404
this is on local side? (I've got this working on a local branch)
Yes, on the local side that is what the preview looks like
so on my side I also get that all links show as Introduction to computational thinking (will check how you can fix this) but the links don't error.
Just to make sure we're at the same point, can you search for "addition" and confirm there's two links? (locally)
Yes, I get two links total, but when I click one, it says: "404: file not found. Perhaps you made a typo in the URL, or the requested file has been deleted or renamed." and the URL is "http://localhost:8000/website/logistics/index.html".
I am running with regular serve(), could that be the issue?
no no this is fine; ok let me dig a bit
ok so the local fail is due to prepath, that's fine and is a known issue (locally for now you can comment out prepath in the config.md and you'll see that stuff works)
I'm looking into the link title thing
What additional stuff should work? It seems like the same results to me
Ok so what you need to fix is going to be a little bit annoying, you need to remove
@def title = ...
in the config.md, and add a @def title to every page that doesn't have a first # or already an explicitly specified #. so in particular all hw*.md will need a @def title = ...
If you do this then things will work fine (don't forget to eventually uncomment the prepath = ... in the config.md when you push here)
What additional stuff should work? It seems like the same results to me
you need to rebuild the index so, locally, after having commented out the prepath,
julia> serve(single=true, cleanup=false); lunr(); serve()
Okay cool. should be easy enough! Thanks for figuring this out, I will make these updates in the next few days and make sure all is good before pushing.
To make sure I'm completely clear here's what I'm suggesting
Locally
- comment out
prepathin config.md - comment out
titlein config.md - add a
titledef in all.mdpages except those that already have a top section#for which it's automatic (you can also specify atitlefor those, it will take precedence over the first top section); in particular this is needed for allhw*.md - rebuild, serve and test:
serve(single=true, cleanup=false); lunr(); serve()
If that looks fine then
- uncomment
prepathin config.md - add the following the
.gitignore(node stuff)
node_modules/
package-lock.json
- make sure that the same line
serve(single=true, cleanup=false); lunr(); optimize(minify=false)is in the deploy script - add, commit, push and merge
Is this able to search the contents of notebooks? That would be really cool! If not, I'd like to take a look at it sometime
I don't see why it couldn't, maybe you have to tell it to also process .ipynb files but otherwise I imagine it's doable (also maybe of interest: https://blog.ouseful.info/2018/05/10/initial-sketch-searching-jupyter-notebooks-using-lunr/ ?)
We use Pluto notebooks :)
hahaha of course, I think the comment holds though, Lunr should be able to index any readable file afaik
Superseded by #124