computational-thinking icon indicating copy to clipboard operation
computational-thinking copied to clipboard

Add the ability to search the website

Open logankilpatrick opened this issue 4 years ago • 19 comments

@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?

logankilpatrick avatar Aug 22 '21 01:08 logankilpatrick

Closes #64

logankilpatrick avatar Aug 22 '21 01:08 logankilpatrick

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);

tlienart avatar Aug 23 '21 07:08 tlienart

Added those, however, it looks like things still don't work as expected, this is what I get:

Screen Shot 2021-08-24 at 6 59 26 AM

And the actual links 404

logankilpatrick avatar Aug 24 '21 14:08 logankilpatrick

this is on local side? (I've got this working on a local branch)

tlienart avatar Aug 24 '21 14:08 tlienart

Yes, on the local side that is what the preview looks like

logankilpatrick avatar Aug 24 '21 14:08 logankilpatrick

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)

tlienart avatar Aug 24 '21 14:08 tlienart

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".

logankilpatrick avatar Aug 24 '21 14:08 logankilpatrick

I am running with regular serve(), could that be the issue?

logankilpatrick avatar Aug 24 '21 14:08 logankilpatrick

no no this is fine; ok let me dig a bit

tlienart avatar Aug 24 '21 14:08 tlienart

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

tlienart avatar Aug 24 '21 14:08 tlienart

What additional stuff should work? It seems like the same results to me

logankilpatrick avatar Aug 24 '21 14:08 logankilpatrick

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)

Screenshot 2021-08-24 at 17 00 38

tlienart avatar Aug 24 '21 14:08 tlienart

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()

tlienart avatar Aug 24 '21 15:08 tlienart

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.

logankilpatrick avatar Aug 24 '21 15:08 logankilpatrick

To make sure I'm completely clear here's what I'm suggesting

Locally

  • comment out prepath in config.md
  • comment out title in config.md
  • add a title def in all .md pages except those that already have a top section # for which it's automatic (you can also specify a title for those, it will take precedence over the first top section); in particular this is needed for all hw*.md
  • rebuild, serve and test: serve(single=true, cleanup=false); lunr(); serve()

If that looks fine then

  • uncomment prepath in 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

tlienart avatar Aug 24 '21 15:08 tlienart

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

fonsp avatar Sep 14 '21 12:09 fonsp

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/ ?)

tlienart avatar Sep 14 '21 13:09 tlienart

We use Pluto notebooks :)

fonsp avatar Sep 14 '21 16:09 fonsp

hahaha of course, I think the comment holds though, Lunr should be able to index any readable file afaik

tlienart avatar Sep 14 '21 18:09 tlienart

Superseded by #124

fonsp avatar Nov 01 '22 19:11 fonsp