Selaa lähdekoodia

Merge pull request #2214 from visuddhinanda/agile

添加标题自动编号
visuddhinanda 1 vuosi sitten
vanhempi
sitoutus
81141cf403

+ 1 - 0
dashboard/src/components/api/ai.ts

@@ -16,6 +16,7 @@ export interface AiUsage {
 export interface AiChoice {
   index: number;
   message: AiMessage;
+  logprobs?: string | null; //volcengine
   finish_reason: string;
 }
 

+ 33 - 4
dashboard/src/components/article/AnchorNav.tsx

@@ -110,18 +110,47 @@ const AnchorNavWidget = ({ open = false, content }: IWidget) => {
     console.log("heading", headingAnchor);
   }, [open]);
 
-  const GetLink = (anchors: IHeadingAnchor[]) => {
+  const GetLink = (anchors: IHeadingAnchor[], level: number) => {
     return anchors.map((it, id) => {
+      let title = <></>;
+      switch (level) {
+        case 1:
+          title = <h1>{it.label}</h1>;
+          break;
+        case 2:
+          title = <h2>{it.label}</h2>;
+          break;
+        case 3:
+          title = <h3>{it.label}</h3>;
+          break;
+        case 3:
+          title = <h3>{it.label}</h3>;
+          break;
+        case 4:
+          title = <h4>{it.label}</h4>;
+          break;
+        case 5:
+          title = <h5>{it.label}</h5>;
+          break;
+        case 6:
+          title = <h6>{it.label}</h6>;
+          break;
+        default:
+          title = <>{it.label}</>;
+          break;
+      }
       return (
-        <Link key={id} href={it.key} title={it.label}>
-          {it.children ? GetLink(it.children) : undefined}
+        <Link key={id} href={it.key} title={title}>
+          {it.children ? GetLink(it.children, level + 1) : undefined}
         </Link>
       );
     });
   };
 
   return open && heading ? (
-    <Anchor offsetTop={50}>{GetLink(heading)}</Anchor>
+    <div className="article_anchor paper_zh">
+      <Anchor offsetTop={50}>{GetLink(heading, 1)}</Anchor>
+    </div>
   ) : (
     <></>
   );

+ 1 - 1
dashboard/src/components/article/ArticleView.tsx

@@ -125,7 +125,7 @@ const ArticleViewWidget = ({
         ? html.map((item, id) => {
             return (
               <div key={id}>
-                <MdView className="pcd_article" html={item} />
+                <MdView className="pcd_article paper paper_zh" html={item} />
               </div>
             );
           })

+ 75 - 0
dashboard/src/components/article/article.css

@@ -6,22 +6,97 @@ h5,
 h6 {
   font-weight: 700;
 }
+
+/*重置文章容器的计数器*/
+.pcd_article {
+  counter-reset: h1 h2 h3 h4;
+}
+
+/*重置文章导航容器的计数器*/
+.article_anchor {
+  counter-reset: h1 h2 h3 h4 !important;
+}
+
+/*统一文章导航容器的字体*/
+.article_anchor h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+  font-size: 14px !important;
+  font-weight: 500 !important;
+}
+
+.article_anchor a:has(> h1) {
+  counter-increment: h1;
+  counter-reset: h2;
+}
+
+.paper_zh h1::before {
+  content: counter(h1, trad-chinese-informal) "、";
+}
+.paper_en h1::before {
+  content: counter(h1) ".";
+}
+
+.article_anchor a:has(> h2) {
+  counter-increment: h2;
+  counter-reset: h3;
+}
+.paper_zh h2::before {
+  content: "(" counter(h2, trad-chinese-informal) ")";
+}
+.paper_en h2::before {
+  content: counter(h1) "." counter(h2);
+}
+
+.article_anchor a:has(> h3) {
+  counter-increment: h3;
+  counter-reset: h4;
+}
+.paper_zh h3::before {
+  content: counter(h3) ".";
+}
+.paper_en h3::before {
+  content: counter(h1) "." counter(h2) "." counter(h3);
+}
+
+.article_anchor a:has(> h4) {
+  counter-increment: h4;
+  /*counter-reset: h5;*/
+}
+.paper_zh h4::before {
+  content: "(" counter(h4) ")";
+}
+.paper_en h4::before {
+  content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4);
+}
+
 .pcd_article h1 {
   margin-top: 1em;
   font-size: 27px !important;
   border-bottom: 1px solid gray;
+  counter-increment: h1;
+  counter-reset: h2;
 }
 .pcd_article h2 {
   margin-top: 1em;
   font-size: 24px !important;
   border-bottom: 1px solid gray;
+  counter-increment: h2;
+  counter-reset: h3;
 }
 .pcd_article h3 {
   margin-top: 0.5em;
   font-size: 22px !important;
+  counter-increment: h3;
+  counter-reset: h4;
 }
 .pcd_article h4 {
   font-size: 20px !important;
+  counter-increment: h4;
+  counter-reset: h5;
 }
 .pcd_article h5 {
   font-size: 18px !important;