- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBuildBlogPost.py
More file actions
Latest commit
82 lines (48 loc) · 1.26 KB
/
Copy pathBuildBlogPost.py
File metadata and controls
82 lines (48 loc) · 1.26 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <headingcell level=1>
# Showoff Presentation -> Blog Post
# <headingcell level=2>
# Setup
# <headingcell level=3>
# Configuration
# <codecell>
config_fn="showoff.json"
outfile="blogpost/blogpost.md"
# <headingcell level=3>
# Helper Functions
# <codecell>
# [[a]] -> [a]
defflatten(l):
return [itemforsublistinlforiteminsublist]
defconcatstrings(x):
addtwo=lambdax,y: x+y
returnreduce(addtwo, x, "")
# String -> IO [String]
ls=os.listdir
# <headingcell level=3>
# Imports
# <codecell>
importjson
importos
importre
config=json.loads(open(config_fn).read())
# <headingcell level=2>
# Extraction
# <headingcell level=3>
# Read in the presentation MD
# <codecell>
mdfiles=flatten([sort([os.path.join(section["section"], x) forxinls(section["section"])]) forsectioninconfig["sections"]])
addtwo=lambdax,y: x+y
md_concatenated=concatstrings([open(f).read() forfinmdfiles])
# <headingcell level=3>
# Remove SLIDE lines
# <codecell>
slide_pattern=r".*SLIDE.*"
md_out=concatstrings( re.split(slide_pattern, md_concatenated) )
# <headingcell level=3>
# Write to a file
# <codecell>
ohandle=open(outfile, "w")
ohandle.write(md_out)
ohandle.close()