carpentries / lesson-example

Example lesson using The Carpentries lesson template.
https://carpentries.github.io/lesson-example/
Other
64 stars 173 forks source link

How to link to episode from setup? #367

Closed gcapes closed 2 years ago

gcapes commented 2 years ago

I'm struggling with this on one of my lessons. It works locally but not on GitHub.

My setup page uses a link "set up ssh keys". Page source.

Locally this resolves to http://127.0.0.1:4000/08-remote/index.html/#set-up-ssh-keys, but on GitHub it resolves to http://gcapes.github.io/08-remote/index.html/#set-up-ssh-keys i.e. it is missing the repo name (git-course). I need it to resolve to http://gcapes.github.io/git-course/08-remote/index.html/#set-up-ssh-keys

This repo gives instructions on how to link from an episode to another, but not from setup. I think page.root refers to the directory containing the current page which is not what I need here, but I can't figure out what I'm doing wrong.

My repo might well have some old stuff complicating the picture like the permalink in the yaml front matter.

Anyone able to put me out of my misery?

maxim-belkin commented 2 years ago

Does {{ page.root }}/{% link _episodes/08-remote.md %}/#set-up-ssh-keys work?

maxim-belkin commented 2 years ago

Try using {{ relative_root_path }} instead of {{ page.root }}. relative_root_path is defined in _includes/base_path.html.

gcapes commented 2 years ago

Thanks for the ideas @maxim-belkin. Unfortunately, neither worked. :(

Locally, page.root makes the link point to http://127.0.0.1:4000/setup/08-remote/index.html/#set-up-ssh-keys, so it looks like page.root is http://127.0.0.1:4000/setup/ relative_root_path results in http://127.0.0.1:4000/08-remote/index.html/#set-up-ssh-keys locally, but on GitHub it gives me http://gcapes.github.io/08-remote/index.html/#set-up-ssh-keys which is the same as when using page.root

So as before, page.root is resolving to http://gcapes.github.io/ instead of http://gcapes.github.io/git-course

Do you have any other ideas to resolve this?

tobyhodges commented 2 years ago

Hey @gcapes, I forked your repo and found that I could get the link to resolve correctly locally, on GitHub Pages, and in an "offline" build of the site (with make site) by using page.root and removing the slash before the anchor in the link i.e.

[set up SSH keys]: {{ page.root }}{% link _episodes/08-remote.md %}#set-up-ssh-keys

Check out my version at https://github.com/tobyhodges/git-course/blob/gh-pages/setup.md and https://tobyhodges.github.io/git-course/setup.html

gcapes commented 2 years ago

Thanks @tobyhodges and @maxim-belkin

This now works for me too. I have no idea why it didn't seem to before. I tried lots of stuff locally and remotely (hidden in force pushes). Must be some sort of new year related 'user error' on my part :)