fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.93k stars 488 forks source link

Default sidebar links broken #219

Closed omlnaut closed 4 years ago

omlnaut commented 4 years ago

Issue: The links in a newly generated "default sidebar" point to .html Since "pretty links" are the default for the jekyll page generation, this does not work (404 on following the link from the index page).

Steps to reproduce:

  1. Generate a new project via the template, enable github pages
  2. Build lib, build docs, push to github
  3. Access the generated documentation on github, try to click the link to the core notebook

Possible fixes: The breaking commit seems to be da400c3572a944e23d569a6017bc0884335e1d36 (20.08.). It replaced "f.stem" by "f.name", therefore making it "core.html" instead of "core". I don't know why this change was made, so one fix would be to:

  1. Undo this particular change (not sure what this would break further down the line) or
  2. Turn of jekyll "pretty links" in the _config.yml.

UPDATE: I just realized that in the same commit Jeremy changed the _config.yml for the nbdev documentation to essentially implement solution 2 from above. If this is intended to be the solution then we should adjust the nbdev template to generate such a _config.yml by default. I would prefer this solution, as it allows to have the documentation generated in a static way that doesn't require a running jekyll server to view it.

koenvanderveen commented 4 years ago

I think I have a similar issue. I have a repo called "integrators" and a nb that exports to basic.py and basic.html. My navigation has an item called "title" and when I click it, it says: `/integratorsbasic.html' not found. When i go to /integrators/basic (without the html and + a "/") it does work

simonasantamaria commented 4 years ago

Thanks, your suggestion "2. Turn of jekyll "pretty links" in the _config.yml." worked for me!

coffeedjimmy commented 4 years ago

It works for me either!

please erase out if there is "pretty links" in the _config.yml file.

koenvanderveen commented 4 years ago

that does not solve it for me. I am using the gitlab template from https://gitlab.com/thomas.capelle/nbdev_template/. By "pretty links" you mean the "permalink: pretty" line?

koenvanderveen commented 4 years ago

When I manually change that f.name to f.stem, I am still missing the slash. Any idea where that should be added?

omlnaut commented 4 years ago

If I am manually chaning that f.name to f.stem, I am still missing the slash. Any idea where that should be added?

Without looking at your config I don't know what's causing this.

koenvanderveen commented 4 years ago

My config looks like this

repository: https://gitlab.memri.io/memri/pyintegrators
output: web
topnav_title: integrators
site_title: memri integrators
company_name: memri
description: memri integrators, integrating your information
# Set to false to disable KaTeX math
use_math: true
# Add Google analytics id if you have one and want to use it here
google_analytics:
# See http://nbdev.fast.ai/search for help with adding Search
google_search:

host: 127.0.0.1
# the preview server used. Leave as is.
port: 4000
# the port where the preview is rendered.

exclude:
  - .idea/
  - .gitignore
  - vendor

exclude: [vendor]

highlighter: rouge
markdown: kramdown
kramdown:
 input: GFM
 auto_ids: true
 hard_wrap: false
 syntax_highlighter: rouge

collections:
  tooltips:
    output: false

defaults:
  -
    scope:
      path: ""
      type: "pages"
    values:
      layout: "page"
      comments: true
      search: true
      sidebar: home_sidebar
      topnav: topnav
  -
    scope:
      path: ""
      type: "tooltips"
    values:
      layout: "page"
      comments: true
      search: true
      tooltip: true

sidebars:
- home_sidebar

theme: jekyll-theme-cayman
baseurl: /integrators
permalink: pretty
omlnaut commented 4 years ago

My config looks like this

repository: https://gitlab.memri.io/memri/pyintegrators
output: web
topnav_title: integrators
site_title: memri integrators
company_name: memri
description: memri integrators, integrating your information
# Set to false to disable KaTeX math
use_math: true
# Add Google analytics id if you have one and want to use it here
google_analytics:
# See http://nbdev.fast.ai/search for help with adding Search
google_search:

host: 127.0.0.1
# the preview server used. Leave as is.
port: 4000
# the port where the preview is rendered.

exclude:
  - .idea/
  - .gitignore
  - vendor

exclude: [vendor]

highlighter: rouge
markdown: kramdown
kramdown:
 input: GFM
 auto_ids: true
 hard_wrap: false
 syntax_highlighter: rouge

collections:
  tooltips:
    output: false

defaults:
  -
    scope:
      path: ""
      type: "pages"
    values:
      layout: "page"
      comments: true
      search: true
      sidebar: home_sidebar
      topnav: topnav
  -
    scope:
      path: ""
      type: "tooltips"
    values:
      layout: "page"
      comments: true
      search: true
      tooltip: true

sidebars:
- home_sidebar

theme: jekyll-theme-cayman
baseurl: /integrators
permalink: pretty

Have you tried adding the slash to the end of your base URL? Making it "/integrators/"?

At this point I have no clue if this is the intended way to use nbdev though. GitHub issues are not really the place to discuss this, you might want to try the fast.ai forums for that (I'm on there too)

koenvanderveen commented 4 years ago

Yeah could be a stopgap solution for now. Thanks for looking into it. Will make a post on the forum.

jph00 commented 4 years ago

Yeah I'll take out pretty in the yaml. And IIRC you do want a / at the end of your baseurl.

koenvanderveen commented 4 years ago

Thanks, the extra slash + removing the pretty line fixed it. It does result in a "//" ending of my url on the landing page

danielpcox commented 3 years ago

I actually solved this problem for myself a different way: Before running it through Jekyll, I remove the .html from both docs/sidebar.json and docs/_data/sidebars/home_sidebar.yml like so (in my Makefile):

    perl -pi -e 's/\.html//g' docs/sidebar.json
    perl -pi -e 's/\.html//g' docs/_data/sidebars/home_sidebar.yml

Not recommending this exactly, but it does let you keep pretty urls.

Here're the relevant chunks of my Makefile in case it helps:

docs: # $(SRC)
    nbdev_build_docs
    touch docs
    perl -pi -e 's/\.html//g' docs/sidebar.json
    perl -pi -e 's/\.html//g' docs/_data/sidebars/home_sidebar.yml
    sudo docker run --rm -it -v ${PWD}/docs:/srv/jekyll jekyll/jekyll jekyll build

docs_serve:
    perl -pi -e 's/\.html//g' docs/sidebar.json
    perl -pi -e 's/\.html//g' docs/_data/sidebars/home_sidebar.yml
    sudo docker run --rm -it -p 4000:4000 -v ${PWD}/docs:/srv/jekyll jekyll/jekyll jekyll serve