@@ -59,38 +59,41 @@ def generate_sections_from_pyquery(body):
59
59
}
60
60
61
61
62
- def process_file (filename ):
63
- """Read a file from disk and parse it into a structured dict."""
62
+ def process_file (fjson_filename ):
63
+ """Read the fjson file from disk and parse it into a structured dict."""
64
64
try :
65
- with codecs .open (filename , encoding = 'utf-8' , mode = 'r' ) as f :
65
+ with codecs .open (fjson_filename , encoding = 'utf-8' , mode = 'r' ) as f :
66
66
file_contents = f .read ()
67
67
except IOError :
68
- log .info ('Unable to read file: %s' , filename )
69
- return None
68
+ log .info ('Unable to read file: %s' , fjson_filename )
69
+ raise
70
70
data = json .loads (file_contents )
71
71
sections = []
72
+ path = ''
72
73
title = ''
73
74
body_content = ''
75
+
74
76
if 'current_page_name' in data :
75
77
path = data ['current_page_name' ]
76
78
else :
77
- log .info ('Unable to index file due to no name %s' , filename )
78
- return None
79
- if 'body' in data and data [ 'body' ] :
79
+ log .info ('Unable to index file due to no name %s' , fjson_filename )
80
+
81
+ if data . get ( 'body' ) :
80
82
body = PyQuery (data ['body' ])
81
83
body_content = body .text ().replace ('¶' , '' )
82
84
sections .extend (generate_sections_from_pyquery (body ))
83
85
else :
84
- log .info ('Unable to index content for: %s' , filename )
86
+ log .info ('Unable to index content for: %s' , fjson_filename )
87
+
85
88
if 'title' in data :
86
89
title = data ['title' ]
87
90
if title .startswith ('<' ):
88
91
title = PyQuery (data ['title' ]).text ()
89
92
else :
90
- log .info ('Unable to index title for: %s' , filename )
93
+ log .info ('Unable to index title for: %s' , fjson_filename )
91
94
92
95
return {
93
- 'headers' : process_headers (data , filename ),
96
+ 'headers' : process_headers (data , fjson_filename ),
94
97
'content' : body_content ,
95
98
'path' : path ,
96
99
'title' : title ,
0 commit comments