pythonParseImgFolder.py 1.14 KB
Newer Older
1 2 3 4 5 6 7 8 9
# parser that is ran in md_sources folder to output multiple parsed .md files to app/pages folder
# $ python pythonParseImgFolder.py .
import re
import sys
from yaml import load, dump
import yaml
import os
from glob import glob

10
PATH_TO_REPO_HOME = '/home/zvevqx/LAB/work/www/eu.bemaker.flask/'
11 12


colmoneill's avatar
colmoneill committed
13 14
print('parsing all .md files in md_sources folder')

15 16 17 18 19 20
inputMd = glob('*.md')

for file in inputMd:
    fileName = file.partition('.')
    input = open(file, 'r')
    input = input.read()
21
    # outputFile = open('pages/_PARSED_'+fileName[0]+'.md', 'w')
22
    outputFile = open(PATH_TO_REPO_HOME +'app/pages/'+'_PARSED_'+fileName[0]+'.md', 'w')
23
    yamlData = yaml.load(str(input.partition('...')[2].partition('...')[0]))
24 25
    if yamlData['folderImg']:
    	folderName = yamlData['folderImg']
erreur401's avatar
erreur401 committed
26
    	# rsync local image folders to app/static ?
27 28
    	os.system('rsync -rv media/%s  ../static/media/'%(folderName) )
    	outputMd = re.sub(r'(?:!\[(.*)\]\()(.*)(\/)(.*)(?:\))', r'![\1](/static/media/%s/\4)'%(folderName), input )
29 30 31
    outputMd = re.sub(r'(\.\.\.)\n','', outputMd )
    outputFile.write(outputMd)
    outputFile.close()
colmoneill's avatar
colmoneill committed
32

erreur401's avatar
erreur401 committed
33

colmoneill's avatar
colmoneill committed
34 35

print('.md files _PARSED_ to pages folder')