@@ -39,21 +39,22 @@ public function build(BuildConfig $config): BuildResult
39
39
$ filesystem ->dumpFile ($ config ->getOutputDir ().'/build_errors.txt ' , implode ("\n" , $ buildResult ->getErrors ()));
40
40
}
41
41
42
- $ metas = $ buildResult ->getMetadata ();
43
- if ($ config ->getSubdirectoryToBuild ()) {
44
- $ htmlForPdfGenerator = new HtmlForPdfGenerator ($ metas , $ config );
45
- $ htmlForPdfGenerator ->generateHtmlForPdf ();
46
- } elseif ($ config ->generateJsonFiles ()) {
47
- $ jsonGenerator = new JsonGenerator ($ metas , $ config );
48
- $ buildResult ->setJsonResults ($ jsonGenerator ->generateJson ($ builder ->getIndexName ()));
49
- } elseif ($ config ->isContentAString ()) {
42
+ if ($ config ->isContentAString ()) {
50
43
$ htmlFilePath = $ config ->getOutputDir ().'/index.html ' ;
51
44
if (is_file ($ htmlFilePath )) {
52
45
// generated HTML contents are a full HTML page, so we need to
53
46
// extract the contents of the <body> tag
54
47
$ crawler = new Crawler (file_get_contents ($ htmlFilePath ));
55
48
$ buildResult ->setStringResult (trim ($ crawler ->filter ('body ' )->html ()));
56
49
}
50
+ } elseif ($ config ->getSubdirectoryToBuild ()) {
51
+ $ metas = $ buildResult ->getMetadata ();
52
+ $ htmlForPdfGenerator = new HtmlForPdfGenerator ($ metas , $ config );
53
+ $ htmlForPdfGenerator ->generateHtmlForPdf ();
54
+ } elseif ($ config ->generateJsonFiles ()) {
55
+ $ metas = $ buildResult ->getMetadata ();
56
+ $ jsonGenerator = new JsonGenerator ($ metas , $ config );
57
+ $ buildResult ->setJsonResults ($ jsonGenerator ->generateJson ($ builder ->getIndexName ()));
57
58
}
58
59
59
60
return $ buildResult ;
@@ -62,7 +63,7 @@ public function build(BuildConfig $config): BuildResult
62
63
public function buildString (string $ contents ): BuildResult
63
64
{
64
65
$ filesystem = new Filesystem ();
65
- $ tmpDir = sys_get_temp_dir ().'/rst_ ' .random_int (1 , 100000000 );
66
+ $ tmpDir = sys_get_temp_dir ().'/doc_builder_build_string_ ' .random_int (1 , 100000000 );
66
67
if ($ filesystem ->exists ($ tmpDir )) {
67
68
$ filesystem ->remove ($ tmpDir );
68
69
}
@@ -71,13 +72,16 @@ public function buildString(string $contents): BuildResult
71
72
$ filesystem ->dumpFile ($ tmpDir .'/index.rst ' , $ contents );
72
73
73
74
$ buildConfig = (new BuildConfig ())
74
- ->setIsContentAString ( true )
75
+ ->setContentIsString ( )
75
76
->setContentDir ($ tmpDir )
76
77
->setOutputDir ($ tmpDir .'/output ' )
77
78
->disableBuildCache ()
78
79
->disableJsonFileGeneration ()
79
80
;
80
81
81
- return $ this ->build ($ buildConfig );
82
+ $ buildResult = $ this ->build ($ buildConfig );
83
+ $ filesystem ->remove ($ tmpDir );
84
+
85
+ return $ buildResult ;
82
86
}
83
87
}
0 commit comments