Modify Markdown files
3 related links
The second last step of the process to convert my Wordpress blog into mkdocs generated site. This step modifies the markdown files produced in the export-wordpress-to-markdown process and generates new content for the purposes of:
- Modify markdown sourced from Wordpress to tidy up any outdated content/links to make it fit within
mkdocsrequirements. - Modify the structure of the exported data to re-create the blog structure.
- Generate new content to re-create additional blog content (e.g. category pages, tag pages, archives, RSS feeds, adding comments/pingbacks)
Done in two main Python scripts
blogTidyUp.py- Run from the Memex repo to modify the markdown files from the previous step and relocate them into the blog repo. Run once to generate/rewrite the blog structure.- Use computational-components (e.g.
blog.py) running from withinmkdocsto generation additional markdown files during the site build process.
blogTidyUp.py#
Three main steps
- Parse the Wordpress XML file to extract additional data used in the following steps.
- Read, modify, and move the markdown files for blog pages.
- Read, modify, and move the markdown files for blog posts.
The distinction between pages and posts is made because:
wpparseplaces pages and posts into separate folders; and,- the
mkdocblog's intended folder structure for pages and posts differs.
However, the the same process is performed for both pages and posts:
- Read the content of the markdown file produced by
wpparse -
Modify the content by
- converting the publish date to a string
-
clean up the content of the file using data from the XML file
Changes made includes:
- replace davidtjones.wordpress.com links with djon.es links
- convert djon.es full links to absolute links within mkdocs
- remove any links internal to the blog post/page
- change Comments author "admin" to "David Jones"
- clean up the YAML front matter for the post/page
- Move the file to the correct location by
-
creating and copying any images and other resource files to the correct location
- writing an updated index file with the post/page content
Computational components#
mkdocs-gen-file is a plugin for the mkdocs static site generator used to publish the new blog. mkdocs-gen-file enables the integration of local Pythons scripts into the mkdocs build process. A primary enabler of the computational-components approach used in this site.
For the blog, the primary computational components is blog.py, which performs the following tasks:
-
Generate category pages.
At the time of this work blog posts were allocated into 152 different categories. A category page lists an excerpt of all the posts belonging to the category. - Generate an RSS feed - using python-feedgen of the 20 most recent posts. - Generate the home page, which
- adds excerpts of the 20 most recent posts to the home page
-
generate archive pages for all posts
An archive page is a list of all posts for a month and year. - adds to the left-column of the home page a navigable list of archive pages.