Browse Source

无论导出什么格式,都先输出成markdown

visuddhinanda 1 year ago
parent
commit
4fc8e1987c
2 changed files with 11 additions and 30 deletions
  1. 3 2
      app/Console/Commands/ExportArticle.php
  2. 8 28
      app/Console/Commands/ExportChapter.php

+ 3 - 2
app/Console/Commands/ExportArticle.php

@@ -125,7 +125,7 @@ class ExportArticle extends Command
     }
 
     private function fetch($articleId){
-        $api = config('app.url') . '/api';
+        $api = config('mint.server.api.bamboo');
         $basicUrl = $api . '/v2/article/';
         $url =  $basicUrl . $articleId;;
         $this->info('http request url='.$url);
@@ -134,6 +134,7 @@ class ExportArticle extends Command
                 'format' => 'markdown',
                 'anthology'=> $this->option('anthology'),
                 'channel' => $this->option('channel'),
+                'origin' => $this->option('origin'),
         ];
         Log::debug('export article http request',['url'=>$url,'param'=>$urlParam]);
         if($this->option('token')){
@@ -144,7 +145,7 @@ class ExportArticle extends Command
 
         if($response->failed()){
             $this->error('http request error'.$response->json('message'));
-            Log::error('http request error'.$response->json('message'));
+            Log::error('http request error',['error'=>$response->json('message')]);
             return false;
         }
         if(!$response->json('ok')){

+ 8 - 28
app/Console/Commands/ExportChapter.php

@@ -28,7 +28,7 @@ class ExportChapter extends Command
      * php artisan export:chapter 168 915 7fea264d-7a26-40f8-bef7-bc95102760fb 168-915.html --format=html --origin=true
      * @var string
      */
-    protected $signature = 'export:chapter {book} {para} {channel} {query_id} {--token=} {--origin=false} {--translation=true} {--debug} {--format=tex} ';
+    protected $signature = 'export:chapter {book} {para} {channel} {query_id} {--token=} {--origin=false} {--translation=true} {--debug} {--format=markdown} ';
 
     /**
      * The console command description.
@@ -74,23 +74,12 @@ class ExportChapter extends Command
                                         'escape'=>function ($value){
                                             return $value;
                                         }));
-        $tplFile = resource_path("mustache/chapter/".$this->option('format')."/paragraph.".$this->option('format'));
+        $tplFile = resource_path("mustache/chapter/md/paragraph.md");
         $tplParagraph = file_get_contents($tplFile);
 
         MdRender::init();
 
-
-        switch ($this->option('format')) {
-            case 'md':
-                $renderFormat='markdown';
-                break;
-            case 'html':
-                $renderFormat='html';
-                break;
-            default:
-                $renderFormat=$this->option('format');
-                break;
-        }
+        $renderFormat='markdown';
 
         //获取原文channel
         $orgChannelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
@@ -253,20 +242,11 @@ class ExportChapter extends Command
                     }else{
                         $subSessionTitle = $paraData['translations'][0]['content'];
                     }
-                    switch ($this->option('format')) {
-                        case 'tex':
-                            $subStr = array_fill(0,$currLevel,'sub');
-                            $content[] = '\\'. implode('',$subStr) . "section{".$subSessionTitle.'}';
-                            break;
-                        case 'md':
-                            $subStr = array_fill(0,$currLevel,'#');
-                            $content[] = implode('',$subStr) . " ".$subSessionTitle;
-                            break;
-                        case 'html':
-                            $level = $currLevel+2;
-                            $content[] = "<h{$currLevel}>".$subSessionTitle."</h{$currLevel}>";
-                            break;
-                    }
+
+                    //标题
+                    $subStr = array_fill(0,$currLevel,'#');
+                    $content[] = implode('',$subStr) . " ".$subSessionTitle;
+
                 }
                 $content[] = "\n\n";
             }