def test_split_yaml(): with open(op.join(curdir, 'site', '_build', 'tests', 'features.md'), 'r') as ff: lines = ff.readlines() # Make sure the yaml remains in the file assert is_in(lines, "yaml_frontmatter: true") # Edgecases etc on the splitter function assert _split_yaml([]) == ([], []) assert _split_yaml(['foo\n', 'bar\n']) == ([], ['foo\n', 'bar\n']) assert _split_yaml(['---\n', 'foo\n', 'bar\n']) == ([], ['---\n', 'foo\n', 'bar\n']) exp = ['---\n', 'foo\n', '---\n'] assert _split_yaml(exp) == (['foo\n'], []) assert (_split_yaml(['---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) == (['foo\n'], ['baz\n', 'barf\n'])) assert (_split_yaml( ['---\n', 'foo\n', 'bar\n', '---\n', 'baz\n', 'barf\n']) == (['foo\n', 'bar\n'], ['baz\n', 'barf\n'])) assert (_split_yaml( ['\n', '\n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) == (['foo\n'], ['baz\n', 'barf\n'])) assert (_split_yaml( [' \n', ' \n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) == (['foo\n'], ['baz\n', 'barf\n']))
# If markdown we'll add frontmatter later sh.copy2(path_url_page, path_new_file) else: raise _error("Files must end in ipynb or md. Found file {}".format( path_url_page)) ############################################################################### # Modify the generated Markdown to work with Jekyll # Clean markdown for Jekyll quirks (e.g. extra escape characters) with open(path_new_file, 'r') as ff: lines = ff.readlines() lines = _clean_lines(lines, path_new_file) # Split off original yaml yaml_orig, lines = _split_yaml(lines) # Front-matter YAML yaml_fm = [] yaml_fm += ['---'] yaml_fm += ['redirect_from:'] yaml_fm += [ ' - "{}"'.format( _prepare_url(url_page).replace('_', '-').lower()) ] if ix_file == 0: yaml_fm += [' - "/"'] if path_url_page.endswith('.ipynb'): interact_path = 'content/' + path_url_page.split('content/')[-1] yaml_fm += ['interact_link: {}'.format(interact_path)] yaml_fm += ["title: '{}'".format(title)]