Jelajahi Sumber

Merge pull request #2461 from visuddhinanda/development

Development
visuddhinanda 1 Minggu lalu
induk
melakukan
263505d3d3

+ 2 - 1
api-v13/app/Console/Commands/ExportPaliSynonyms.php

@@ -56,7 +56,8 @@ class ExportPaliSynonyms extends Command
         $dictId[] = DictApi::getSysDict('robot_compound');
 */
         $filename =  $this->option('output');
-        $fp = fopen(Str::finish(config('mint.opensearch.config.synonyms_path'), '/') . $filename, 'w') or exit('Unable to open file!');
+        $BASE_PATH = '/srv/opensearch/synonyms/pali/';
+        $fp = fopen($BASE_PATH . $filename, 'w') or exit('Unable to open file!');
 
         $parents = UserDict::select('parent')
             ->whereNotNull('parent')

+ 15 - 2
api-v13/app/Http/Api/MdRender.php

@@ -287,12 +287,25 @@ class MdRender
                         }
                     }
                     if (empty($paramName)) {
+                        /**
+                         * 位置参数。多个文本节点要拼接,不能互相覆盖。
+                         * 如果参数里含有嵌套模版(元素节点),纯文本是残缺的,
+                         * 此时不设置该参数,交给渲染结果的子节点(children)显示。
+                         * TODO: html / markdown 格式下嵌套模版仍会丢失外层模版结构,
+                         * 因为 dfn 是按文档顺序遍历的,外层先于内层渲染。
+                         */
+                        $paramText = '';
+                        $hasNestedTpl = false;
                         foreach ($child->childNodes as $param_child) {
-                            // code...
                             if ($param_child->nodeType === 3) {
-                                $props["{$param_id}"] = $param_child->nodeValue;
+                                $paramText .= $param_child->nodeValue;
+                            } elseif ($param_child->nodeType === 1) {
+                                $hasNestedTpl = true;
                             }
                         }
+                        if (! $hasNestedTpl) {
+                            $props["{$param_id}"] = $paramText;
+                        }
                     }
                 }
                 $child = $child->nextSibling;

+ 8 - 0
api-v13/app/Http/Api/TemplateRender.php

@@ -681,6 +681,14 @@ class TemplateRender
                     'tpl' => 'nissaya',
                 ];
                 break;
+            case 'html':
+                if ($this->lang === 'my') {
+                    $output = "<span lang='pi-Mymr'>{$pali}</span>၊ ";
+                } else {
+                    $output = "<span lang='pi-Latn'>{$pali}</span> ";
+                }
+                $output .= "<span lang='{$this->lang}'>{$meaning}</span>";
+                break;
             case 'prompt':
                 $output = Tools::MyToRm($pali).':'.end($props['meaning']);
                 break;

+ 7 - 1
api-v13/app/Http/Controllers/CorpusController.php

@@ -155,9 +155,15 @@ class CorpusController extends Controller
 
         // 获取wbw channel
         // 目前默认的 wbw channel 是第一个translation channel
+        // TODO: channel 不存在时目前只是静默跳过(句子会渲染为空)。
+        // 以后改为抛出异常,由外层(render_sent / 控制器)捕获,
+        // 把出错信息 message 传给前端提示用户 channel 无效。
         foreach ($channels as $channel) {
             // code...
-            if ($channelIndex[$channel]->type === 'translation') {
+            if (
+                isset($channelIndex[$channel]) &&
+                $channelIndex[$channel]->type === 'translation'
+            ) {
                 $this->wbwChannels[] = $channel;
                 break;
             }

+ 2 - 5
api-v13/app/Http/Controllers/SentenceController.php

@@ -8,15 +8,12 @@ use App\Http\Api\PaliTextApi;
 use App\Http\Api\ShareApi;
 use App\Http\Controllers\Concerns\ChecksChannelEditPower;
 use App\Http\Resources\SentResource;
-use App\Models\AccessToken;
 use App\Models\Channel;
 use App\Models\Sentence;
 use App\Models\WbwAnalysis;
 use App\Services\AuthService;
 use App\Services\SentenceService;
 use App\Tools\OpsLog;
-use Firebase\JWT\JWT;
-use Firebase\JWT\Key;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Cache;
@@ -88,7 +85,7 @@ class SentenceController extends Controller
                     return $this->error('没有关键词');
                 }
                 $table = Sentence::select($indexCol)
-                    ->where('content', 'like', '%'.$key.'%')
+                    ->where('content', 'like', '%' . $key . '%')
                     ->where('editor_uid', $userUid);
 
                 break;
@@ -206,7 +203,7 @@ class SentenceController extends Controller
                 break;
         }
         if (! empty($request->input('key'))) {
-            $table = $table->where('content', 'like', '%'.$request->input('key').'%');
+            $table = $table->where('content', 'like', '%' . $request->input('key') . '%');
         }
 
         $count = $table->count();

+ 8 - 2
dashboard-v6/src/components/template/Note.tsx

@@ -6,7 +6,11 @@ const { Link } = Typography;
 
 interface IWidgetNoteCtl {
   trigger?: string; //界面上显示的文字
-  note?: string; //note内容
+  /**
+   * note 内容。注释里含有嵌套模版时后端不下发这个字段,
+   * 内容以 children(已渲染的嵌套模版)的形式传进来。
+   */
+  note?: string;
   children?: React.ReactNode;
 }
 const NoteCtl = ({ trigger, note, children }: IWidgetNoteCtl) => {
@@ -14,7 +18,9 @@ const NoteCtl = ({ trigger, note, children }: IWidgetNoteCtl) => {
   return (
     <>
       <Popover
-        content={<div style={{ width: 500 }}>{note ?? children}</div>}
+        content={
+          <div style={{ width: 500 }}>{note ? note : children}</div>
+        }
         placement="bottom"
       >
         <Link>{show}</Link>