浏览代码

Allow modification of info text

Marcel Pociot 9 年之前
父节点
当前提交
ac75132797

+ 19 - 1
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php

@@ -88,10 +88,28 @@ class GenerateDocumentation extends Command
     private function writeMarkdown($parsedRoutes)
     {
         $outputPath = $this->option('output');
+        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
+
+        $infoText = view('apidoc::partials.info')
+            ->with('outputPath', $this->option('output'))
+            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'));
+
+        /**
+         * In case the target file already exists, we should check if the documentation was modified
+         * and skip the modified parts of the routes.
+         */
+        if (file_exists($targetFile)) {
+            $generatedDocumentation = file_get_contents($targetFile);
+
+            if (preg_match("/<!-- START_INFO -->(.*)<!-- END_INFO -->/is", $generatedDocumentation, $generatedInfoText)) {
+                $infoText = trim($generatedInfoText[1],"\n");
+            }
+        }
 
         $documentarian = new Documentarian();
 
         $markdown = view('apidoc::documentarian')
+            ->with('infoText', $infoText)
             ->with('outputPath', $this->option('output'))
             ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
             ->with('parsedRoutes', $parsedRoutes->all());
@@ -100,7 +118,7 @@ class GenerateDocumentation extends Command
             $documentarian->create($outputPath);
         }
 
-        file_put_contents($outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md', $markdown);
+        file_put_contents($targetFile, $markdown);
 
         $this->info('Wrote index.md to: '.$outputPath);
 

+ 3 - 7
src/resources/views/documentarian.blade.php

@@ -12,13 +12,9 @@ search: true
 toc_footers:
 - <a href='http://github.com/mpociot/documentarian'>Documentation Powered by Documentarian</a>
 ---
-
-# Info
-
-Welcome to the generated API reference.
-@if($showPostmanCollectionButton)
-[Get Postman Collection]({{$outputPath}}/collection.json)
-@endif
+<!-- START_INFO -->
+{!! $infoText !!}
+<!-- END_INFO -->
 
 @foreach($parsedRoutes as $group => $routes)
 @if($group)

+ 6 - 0
src/resources/views/partials/info.blade.php

@@ -0,0 +1,6 @@
+# Info
+
+Welcome to the generated API reference.
+@if($showPostmanCollectionButton)
+[Get Postman Collection]({{$outputPath}}/collection.json)
+@endif

+ 2 - 1
tests/Fixtures/index.md

@@ -12,11 +12,12 @@ search: true
 toc_footers:
 - <a href='http://github.com/mpociot/documentarian'>Documentation Powered by Documentarian</a>
 ---
-
+<!-- START_INFO -->
 # Info
 
 Welcome to the generated API reference.
 [Get Postman Collection](public/docs/collection.json)
+<!-- END_INFO -->
 
 #general
 ## Example title.