Convert Wordpress to Markdown Files
_post = _getpost('')
assert _post

_post = _getpost(post_id=247, baseurl='') #this is an alternate way of calling this 
assert _post



Get the wordpress api endpoint to retrieve post from the public url

url2api allows you to retrieve the full api endpoint to get the contents of the wordpress article as described here from any public-facing wordpress url!

test_eq(url2api(''), '')

class WP[source]

WP(url:str=None, baseurl:str=None, post_id:int=None)

Instantiating a WP object will allow you to get access to useful properties that can render as front matter.

_post = WP('')
title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: ""
slug: "notebooks-in-production-with-metaflow"

title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: ""
slug: "notebooks-in-production-with-metaflow"
test_eq(_post.frontmatter, _result)

The markdown representation is also available as a property (below we print the first 1,000 characters:

title: "Notebooks In Production With Metaflow"
date: "2022-02-09T22:59:06"
image: ""
slug: "notebooks-in-production-with-metaflow"

By Hamel Husain

*Learn how to use notebooks in production ML workflows with a new Metaflow feature*

When building production-ready machine learning systems, it is critical to monitor the health and performance of those systems with reports and visualizations. Furthermore, allowing for rapid debugging and interactive introspection is critical when workflows fail or do unexpected things. Jupyter notebooks have often been a preferred tool of data scientists for these tasks of visualization, exploration, debugging, and rapid iteration.  Ironically, many production systems do not integrate appropriately with notebooks, which can significantly frustrate progress on these tasks.

Indeed, in the field of data science tooling, one of the most [hotly-contested]( questions is whether notebooks are suitable for production use. We believe that tools should strive to meet data scientists where they are instead of forcing them to adapt approaches from other disciplines not suited to their needs. This is why we are excited to introduce **Notebook Cards**, which allow data scientists to use notebooks for visualizing and debugging production workflows and help to bridge the MLOps divide between 

Getting Hidden Posts

A wordpress post may note be public (i.e. it might have a status other than published). In that case, you will need two pieces of information to retrieve the markdown content for that post.

  1. The url for the api. This is <your_site>/wp-json/v2/posts, for example Note: This is the api route to retrieve a single WP post.

  2. The post id you wish to convert to markdown. The post id can be extracted from wordpress edit url, for example the id for is 220.

For example, we can get the contets of a post which has an id of 220 as follows:

_post = WP(baseurl='', post_id=220)
test_eq(_post.title, 'Notebooks In Production With Metaflow')

Downloading Images

nb2md also Downloads Images for you, and puts the images in a folder named _<name_of_markdown_file>_data/

assert len(_post.mdimages) == 5
_data_dir = Path('_notebooks-in-production-with-metaflow_data/')
assert _data_dir.exists()
(#5) [Path('_notebooks-in-production-with-metaflow_data/4_img'),Path('_notebooks-in-production-with-metaflow_data/2_img'),Path('_notebooks-in-production-with-metaflow_data/3_img'),Path('_notebooks-in-production-with-metaflow_data/1_img'),Path('_notebooks-in-production-with-metaflow_data/0_img')]

The paths to downloaded images are also automatically replaced in the markdown file:

_md = Path('').read_text()
assert _img_url in _post.raw_markdown
assert _img_url not in _md

CLI Utility For Wordpress To Markdown


wp2md(url_or_id:"the public URL of the WP article OR the post id", apiurl:"the base url for the wordpress api to retrieve posts for your site."='', dest_path:"The path to save the markdown file to"='.', dest_file:"Name of destination markdown file. If not given defaults to the slug indicated in wordpress"=None, no_download:"Pass this flag to NOT download any images locally"=False)

Convert A wordpress post into markdown file with front matter.