Last active
April 18, 2023 04:25
-
-
Save hamelsmu/977e82a23dcd8dcff9058079cb4a8f18 to your computer and use it in GitHub Desktop.
Helper Script to use nbdev remote theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
from fastcore.all import * | |
from shutil import rmtree | |
import yaml | |
rm=['_includes','_layouts','css','fonts','js','licenses','tooltips.json','Gemfile','Gemfile.lock'] | |
raw='https://raw.githubusercontent.com/fastai/nbdev_template/master/docs/' | |
def rm_files(pth:Path): | |
"Removes files controlled by theme" | |
for f in rm: | |
p = pth/f'{f}' | |
if p.is_dir(): rmtree(p, ignore_errors=True) | |
elif p.is_file() and p.exists(): p.unlink() | |
urlsave(f'{raw}Gemfile', dest=str((pth/'Gemfile'))) | |
urlsave(f'{raw}Gemfile.lock', dest=str((pth/'Gemfile.lock'))) | |
def config(pth:Path): | |
"""Edit config file to include remote theme.""" | |
p = pth/'_config.yml' | |
cfg = yaml.safe_load(p.read_text()) | |
cfg.pop('theme', None) | |
cfg['plugins'] = ['jekyll-remote-theme'] | |
cfg['remote_theme']= 'fastai/nbdev-jekyll-theme' | |
p.write_text(yaml.safe_dump(cfg)) | |
@call_parse | |
def use_theme(docs_dir:Param('nbdev docs directory', str)='docs'): | |
pth = Path(docs_dir) | |
assert pth.exists(), f'Could not find directory: {pth.absolute()}' | |
rm_files(pth) | |
config(pth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @hamelsmu! Maybe the config file needs to be updated in the current nbdev template?
Starting from the current template at fastai/nbdev_template@521d57f and trying to serve docs locally, I get a very similar error to https://forums.fast.ai/t/docs-rendering-as-raw-html-unsure-how-to-debug/90625 (
Build Warning: Layout 'page' requested in *.html does not exist.
)Running this gist solved the issue (after commenting out
rm_files
line due to fastai/nbdev_template#75 (comment)).