77
88import os
99import shutil
10- import subprocess
10+ from subprocess import Popen , PIPE
1111
1212def read_file (filepath ):
1313 with open (filepath , "r" ) as f :
@@ -27,12 +27,12 @@ def write_string_to_file(s, filepath):
2727 f .write (s )
2828
2929def render_lhs (lhs_filepath ):
30- return subprocess . check_output ([
31- "pandoc" , lhs_filepath ,
32- "-f" , "markdown+lhs" ,
33- "-t" , "html" ,
34- "--mathjax"
35- ]) .decode ("utf8" )
30+ cmd = [ "pandoc" , lhs_filepath , "-f" , "markdown+lhs" , "-t" , "html" , "--mathjax" ]
31+ p = Popen ( cmd , stdout = PIPE , stderr = PIPE )
32+ stdout , stderr = p . communicate ()
33+ if stderr != b"" :
34+ print ( "file: {}, stderr: {}" . format ( lhs_filepath , stderr ))
35+ return stdout .decode ("utf8" )
3636
3737def has_image_ext (filename ):
3838 _ , ext = os .path .splitext (filename )
@@ -58,15 +58,22 @@ def build_sections(sources):
5858 if not os .path .exists (section ):
5959 os .makedirs (section )
6060 chapter_path = "../../" + chapter_source
61+ lhs_source_href = "https://github.com/DSLsofMath/BScProj2018/blob/master/{}" .format (chapter_source )
62+ prefix = "Physics/src/"
63+ lhs_source_name = chapter_source [len (prefix ):] if chapter_source .startswith (prefix ) else chapter_source
6164 content = render_lhs (chapter_path )
6265 chapter = apply_template (
6366 chapter_templ ,
6467 {
68+ "section-name" : section ,
69+ "chapter-name" : chapter_name ,
6570 "content" : content ,
6671 "previous-href" : prev_chap_href ,
6772 "previous-name" : prev_chap_name ,
6873 "next-href" : next_chap_href ,
6974 "next-name" : next_chap_name ,
75+ "lhs-source-href" : lhs_source_href ,
76+ "lhs-source-name" : lhs_source_name ,
7077 })
7178 out_path = "{}/{}.html" .format (section , chapter_name )
7279 write_string_to_file (chapter , out_path )
@@ -89,6 +96,9 @@ def build_index(sources):
8996 write_string_to_file (index , "index.html" )
9097
9198sources = [
99+ ("Introduction" , [
100+ ("Introduction'" , "Physics/src/Introduction/Introduction.lhs" ),
101+ ]),
92102 ("Dimensions" , [
93103 ("Introduction" , "Physics/src/Dimensions/Intro.lhs" ),
94104 ("Value-level dimensions" , "Physics/src/Dimensions/ValueLevel.lhs" ),
@@ -104,8 +114,11 @@ def build_index(sources):
104114 ("Vector" , "Physics/src/Vector/Vector.lhs" )
105115 ]),
106116 ("Calculus" , [
107- ("Calculus" , "Physics/src/Calculus/Calculus.lhs" ),
108- ("Syntax Tree" , "Physics/src/Calculus/SyntaxTree.lhs" ),
117+ ("Introduction" , "Physics/src/Calculus/Intro.lhs" ),
118+ ("Function expressions" , "Physics/src/Calculus/FunExpr.lhs" ),
119+ ("Differential calculus" , "Physics/src/Calculus/DifferentialCalc.lhs" ),
120+ ("Integral calculus" , "Physics/src/Calculus/IntegralCalc.lhs" ),
121+ ("Visualization, Verification, and Application" , "Physics/src/Calculus/VisVerApp.lhs" ),
109122 ]),
110123 ("Newtonian Mechanics" , [
111124 ("Single particle mechanics" , "Physics/src/NewtonianMechanics/SingleParticle.lhs" )
0 commit comments