About Blog Current

Almost made it to the other side

Issues

Since I have no idea about web development, but like to do things on server rather than let browser make decisions for me I decided on writing a little python script to convert markdown files to html files so that I can simply write markdown (pandoc flavor) on my computer and then upload it to the webserver where it will be automatically converted to html and placed into the web directory.

Since I am always looking for small python projects I decided to use that.

DISCLAIMER

I am a hack, this probably makes things more complicated than they need to be

Here is the Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import glob
import pypandoc
import os
import os.path 

def create_file_list(filepath):
    """Creates an array of markdown files to be converted"""
    mds = []
    for file in glob.glob("*.md"):
        mds.append(file)
    return mds

def get_file_names():
    """Get filenames without file extensions"""
    names = []
    for files in create_file_list('/home/normal/Code/own/content_deployment'):
        for file in os.path.splitext(files):
            names.append(file[0])
    return names

def convert_markdown():
    """Convert markdown files to html"""
    names = get_file_names()
    for files in create_file_list('/home/normal/Code/own/content_deployment'):
        pypandoc.convert_file(files,'html', outputfile=files+'.html',
                extra_args=['--include-in-header=style.html'])

convert_markdown()

This requires pandoc to be installed on the machine it is intended to be run.

What I currently find really weird, is that pandoc is injecting alot of stuff via the

1
--include-in-header=$FILENAME

my initial file only contains

1
2
3
4
5
6
7
<body style="font-family: Open Sans">
<!-- Side navigation -->
<div class="sidenav">
     <a href="/about.html">About</a>
     <a href="/blog">Blog</a>
     <a href="/index.html">Current</a>
</div>

and now it contains

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="pandoc" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <title>test</title>
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
  <!--[if lt IE 9]>
    <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
  <![endif]-->
  <body style="font-family: Open Sans">
  <!-- Side navigation -->
  <div class="sidenav">
       <a href="/about.html">About</a>
       <a href="/blog">Blog</a>
       <a href="/index.html">Current</a>
  </div>
</head>

That is a lot of stuff and I am not sure if I actually need this ( I am okay with not supporting IE9).

More of this in the new year!