html - How to make Jekyll excerpts work with Jupyter Notebooks -
i have github.io blog contains both text (markdown) , jupyter notebook posts. jupyter notebook posts converted html using nbconvert. works index page has except section doesn't work html notebooks. markdown posts, pulls in excerpt each post onto index page, not html ones. able include excerpt, such first cell of markdown, except on index page. i'm trying find solution that's both functional , looks good.
the blog fork barry clark's jekyll template.
i tried using strip_html so:
<div class="entry"> {{ post.excerpt | strip_html | truncatewords: 50}} </div>
but includes front matter date , title, kind of this:
example blog
2017-9-6-example-blog example!
where like:
example blog
this example!
i tried writing piece of code added description each jupyter notebook html injecting each file:
<font size="5"><description>this example!</description></font size="5">
this worked index page each blog post has "this example" @ top of page looks different jupyter notebook format. isn't elegant solution anyway if there html tag index pick (without using strip_html) wouldn't show in post, suffice.
i tried converting jupyter notebook straight markdown, formatting doesn't @ html conversion , input/output of code blocks lost.
i figured out way make work, although perhaps it's not best solution. edit index.html file include:
<div class="entry"> {{ post.content | strip_html | truncatewords: 25 }} </div>
then can use following script remove title section nbconvert adds.
import os import re load_posts_path = '' save_posts_path = '' items_in_path = os.listdir(load_posts_path) regex_pattern = "<title>.*</title>" file in items_in_path: # if file html if file[-4:].lower() == 'html': open(load_posts_path+file) f: text = f.readlines() # check see if file contains regex pattern if re.search(pattern=regex_pattern, string=text[3]): print("removing file name " + file) # remove title text text[3] = re.sub(regex_string, "", text[3]) # title in third line open(save_posts_path+file, 'w') w: line in text: w.write(line)
now index grab first 25 words of file can provide in first markdown cell.
Comments
Post a Comment