コード例 #1
0
ファイル: nb2post.py プロジェクト: Hunu/Archive_ghpage1
"""Converts Jupyter Notebooks to Jekyll compliant blog posts"""
from datetime import datetime
import re, os, logging
from nbdev import export2html
from nbdev.export2html import Config, Path, _re_digits
from fast_template import rename_for_jekyll

warnings = set()


# Modify the naming process such that destination files get named properly for Jekyll _posts
def _nb2htmlfname(nb_path, dest=None):
    fname = rename_for_jekyll(nb_path, warnings=warnings)
    if dest is None: dest = Config().doc_path
    return Path(dest) / fname


# td: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(
        f'{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n'
    )

## apply monkey patch
export2html._nb2htmlfname = _nb2htmlfname

export2html.notebook2html(fname='_notebooks/*.ipynb', dest='_posts/')
コード例 #2
0
<<<<<<< HEAD
# Add embedded links for youtube and twitter
def add_embedded_links(cell):
    "Convert block quotes to embedded links in `cell`"
    _styles = ['youtube', 'twitter']
    def _inner(m):
        title,text = m.groups()
        if title.lower() not in _styles: return f"> {m.groups()[0]}: {m.groups()[1]}"
        return '{% include '+title.lower()+".html content=\'`"+_to_html(text)+"`\' %}"
    if cell['cell_type'] == 'markdown':
        cell['source'] = _re_block_notes.sub(_inner, cell['source'])
    return cell

=======
>>>>>>> template/master
# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(f'{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n')
    
## apply monkey patches
export2html._nb2htmlfname = _nb2htmlfname
<<<<<<< HEAD
export2html.process_cell.append(add_embedded_links)

export2html.notebook2html(fname='_notebooks/*.ipynb', dest='_posts/', template_file='/fastpages/fastpages.tpl')

=======
export2html.notebook2html(fname='_notebooks/*.ipynb', dest='_posts/', template_file='/fastpages/fastpages.tpl')
>>>>>>> template/master
コード例 #3
0
ファイル: nb2post.py プロジェクト: A-Alaa/fastpages
        if title.lower() not in _styles:
            return f"> {m.groups()[0]}: {m.groups()[1]}"
        return '{% include ' + title.lower() + ".html content=\'`" + _to_html(
            text) + "`\' %}"

    if cell['cell_type'] == 'markdown':
        cell['source'] = _re_block_notes.sub(_inner, cell['source'])
    return cell


# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(
        f'{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n'
    )

## apply monkey patches
export2html._nb2htmlfname = _nb2htmlfname
export2html.process_cell.append(add_embedded_links)

if args.free_structure:
    notebooks = list(Path(".").rglob("*.ipynb"))
    for notebook_path in notebooks:
        export2html.notebook2html(fname=notebook_path,
                                  dest=os.path.dirname(notebook_path),
                                  template_file='/fastpages/fastpages.tpl')
else:
    export2html.notebook2html(fname='_notebooks/*.ipynb',
                              dest='_posts/',
                              template_file='_action_files/fastpages.tpl')
コード例 #4
0
from nbdev import export2html
from nbdev.export2html import Config, _re_digits

# Check for leading dashses or numbers
_re_numdash = re.compile(r'(^[-\d]+)')
warnings = set()


def rename_for_jekyll(nb_path: Path,
                      warnings: Set[Tuple[str, str]] = None) -> str:
    """
    Name converted HTML to a .md extension and replace spaces with dashes.
    """
    assert nb_path.exists(), f'{nb_path} could not be found.'
    nm = nb_path.with_suffix('.md').name.replace(' ', '-')
    warnings.add((nb_path, nm))
    return nm


# Modify the naming process such that destination files get named properly for Jekyll _posts
def _nb2htmlfname(nb_path, dest=None):
    fname = rename_for_jekyll(nb_path, warnings=warnings)
    if dest is None: dest = Config().doc_path
    return Path(dest) / fname


## apply monkey patch
export2html._nb2htmlfname = _nb2htmlfname
export2html.notebook2html(fname='notebooks/*.ipynb',
                          dest='docs/docs/reports/',
                          template_file='action_files/template.tpl')
コード例 #5
0
"""Converts Jupyter Notebooks to Jekyll compliant blog posts"""
from datetime import datetime
import re, os, logging
from nbdev import export2html
from nbdev.export2html import Config, Path, _re_digits, _to_html, _re_block_notes
from fast_template import rename_for_jekyll

warnings = set()


# Modify the naming process such that destination files get named properly for Jekyll _posts
def _nb2htmlfname(nb_path, dest=None):
    print(nb_path)
    fname = rename_for_jekyll(nb_path, warnings=warnings)
    if dest is None: dest = Config().doc_path
    return Path(dest) / fname


# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(
        f'{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n'
    )

## apply monkey patches
export2html._nb2htmlfname = _nb2htmlfname
export2html.notebook2html(fname='/data/*.ipynb',
                          dest='/data/A',
                          template_file='/fastpages.tpl')
コード例 #6
0
"""Converts Jupyter Notebooks to Jekyll compliant blog posts"""
from datetime import datetime
import re, os, logging
from nbdev import export2html
from nbdev.export2html import Config, Path, _re_digits, _to_html, _re_block_notes
from fast_template import rename_for_jekyll

warnings = set()


# Modify the naming process such that destination files get named properly for Jekyll _posts
def _nb2htmlfname(nb_path, dest=None):
    fname = rename_for_jekyll(nb_path, warnings=warnings)
    if dest is None:
        dest = Config().doc_path
    return Path(dest) / fname


# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(
        f"{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n"
    )

## apply monkey patches
export2html._nb2htmlfname = _nb2htmlfname
export2html.notebook2html(fname="_notebooks/*.ipynb",
                          dest="_posts/",
                          template_file="/fastpages/fastpages.tpl")
コード例 #7
0
ファイル: nb2post.py プロジェクト: kai-tub/master-thesis-blog
def _nb2htmlfname(nb_path, dest=None):
    print(nb_path)
    fname = rename_for_jekyll(nb_path, warnings=warnings)
    if dest is None:
        dest = Config().doc_path
    return Path(dest) / fname


# TODO: Open a GitHub Issue in addition to printing warnings
for original, new in warnings:
    print(
        f"{original} has been renamed to {new} to be complaint with Jekyll naming conventions.\n"
    )

export2html._nb2htmlfname = _nb2htmlfname
export2html.notebook2html(
    fname="_notebooks/*.ipynb",
    dest="_posts/",
    template_file="/fastpages/fastpages.tpl",
    execute=False,
)

export2html._nb2htmlfname = _nb2htmlfname

export2html.notebook2html(
    fname="_draft_notebooks/*.ipynb",
    dest="_drafts/",
    template_file="/fastpages/fastpages.tpl",
    execute=False,
)