Explorar o código

fix(nissaya): 支持对齐后的 JSON nissaya 格式渲染,修复 tab 500

MdRender::markdown2wiki 之前只处理逐词解析(wbw)的 JSON nissaya,
访问 `sn` 字段导致对齐格式(original/translation/note/confidence)
抛 Undefined property 异常,进而使 sent-can-read 接口返回 500。

- MdRender:区分两种 JSON nissaya 格式,对齐格式转成 {{nissaya|...}}
  模版(translation 的 > 转 =),并保留 note
- PaliContentService:read 模式对 nissaya 的 json 内容也渲染 html,
  不再返回 null
visuddhinanda hai 5 días
pai
achega
5c88dcb532
Modificáronse 2 ficheiros con 29 adicións e 15 borrados
  1. 20 2
      api-v13/app/Http/Api/MdRender.php
  2. 9 13
      api-v13/app/Services/PaliContentService.php

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

@@ -402,8 +402,26 @@ class MdRender
                 $nissayaWord = [];
                 if (is_array($json)) {
                     foreach ($json as $word) {
-                        if (count($word->sn) === 1) {
-                            // 只输出第一层级
+                        if (isset($word->original)) {
+                            // 对齐后的 nissaya json 格式:
+                            // {original, translation, note, confidence}
+                            // translation 用 ">" 分隔多层意思,转成 wiki 模版使用的 "=" 分隔符
+                            $str = '{{nissaya|';
+                            $str .= $word->original;
+                            $str .= '|';
+                            $str .= str_replace(
+                                '>',
+                                '=',
+                                isset($word->translation) ? $word->translation : ''
+                            );
+                            $str .= '}}';
+                            $nissayaWord[] = $str;
+
+                            if (! empty($word->note)) {
+                                $nissayaWord[] = '{{note|'.$word->note.'|[nt]}}';
+                            }
+                        } elseif (isset($word->sn) && count($word->sn) === 1) {
+                            // 逐词解析 wbw json 格式,只输出第一层级
                             $str = '{{nissaya|';
                             if (isset($word->word->value)) {
                                 $str .= $word->word->value;

+ 9 - 13
api-v13/app/Services/PaliContentService.php

@@ -330,19 +330,15 @@ class PaliContentService
                                     "/sent/{$channelId}/{$ids}/{$format}",
                                     config('mint.cache.expire'),
                                     function () use ($row, $mode, $format) {
-                                        if ($row->content_type === 'markdown') {
-                                            return MdRender::render(
-                                                $row->content,
-                                                [$row->channel_uid],
-                                                null,
-                                                $mode,
-                                                'nissaya',
-                                                $row->content_type,
-                                                $format
-                                            );
-                                        } else {
-                                            return null;
-                                        }
+                                        return MdRender::render(
+                                            $row->content,
+                                            [$row->channel_uid],
+                                            null,
+                                            $mode,
+                                            'nissaya',
+                                            $row->content_type,
+                                            $format
+                                        );
                                     }
                                 );
                                 break;