33
loading...
This website collects cookies to deliver better user experience
This is Day 4 of the #100DaysOfPython challenge.
hello-frontmatter
directory and install python-frontmatter
. We will also need to add an example markdown file.# Make the `hello-frontmatter` directory
$ mkdir hello-frontmatter
$ cd hello-frontmatter
# Create an example MDX file
$ touch frontmatter-example.mdx
# Init the virtual environment
$ pipenv --three
$ pipenv install python-frontmatter
$ pipenv install --dev jupyterlab
frontmatter-example.mdx
add the following:---
title: "Henlo, FrontMatter"
date: "2016-12-16"
---
Henlo world, this is me.
# Startup the notebook server
$ pipenv run jupyter-lab
# ... Server is now running on http://localhost:8888/lab
hello-frontmatter/docs/<your-file-name>
.python-frontmatter
library and related modules for the os.path
library to help determine the relative path.os.path
imports to get the relative path to the file.import frontmatter
from os.path import join, dirname, abspath
mdx_filepath = join(dirname(abspath("__file__")), '../frontmatter-example.mdx')
print(mdx_filepath)
# ... prints out path to the markdown file
frontmatter.load
method to parse the frontmatter metadata from the file.post = frontmatter.load(mdx_filepath)
print(post.keys())
print(post['title']) # prints "Henlo, FrontMatter"
print(post['date']) # prints "2016-12-16"