{
  "url": "https://unifast.dev/zh-TW/docs/packages/node/excerpt/",
  "locale": "zh-TW",
  "title": "excerpt()",
  "description": "從文件內容中擷取摘要。",
  "section": "packages",
  "body": "```ts\nimport { excerpt } from \"@unifast/node\";\n```\n\n## 函式簽名\n\n```ts\nfunction excerpt(options?: ExcerptPluginOptions): UnifastPlugin\n```\n\n## 參數\n\n### options?\n\n摘要擷取的設定\n\n| 屬性 | 型別 | 預設值 | 說明 |\n|----------|------|---------|-------------|\n| `separator` | `string` | `\"<!-- more -->\"` | 用來區隔摘要與其餘內容的註解標記 |\n| `fallbackParagraphs` | `number` | `1` | 找不到分隔標記時，要做為摘要的開頭段落數 |\n| `fallbackCharacters` | `number` | `undefined` | 備援摘要的最大字元長度（會在詞界處截斷） |\n\n同時設定 `fallbackParagraphs` 與 `fallbackCharacters` 時，`fallbackParagraphs` 優先生效。\n\n## 回傳值\n\n此外掛會在 compile 結果中加入 `excerpt` 屬性：\n\n| 屬性 | 型別 | 說明 |\n|----------|------|-------------|\n| `result.excerpt` | `string \\| undefined` | 從文件中擷取出的純文字摘要 |\n\n## 用法\n\n```ts\nimport { compile, excerpt } from \"@unifast/node\";\n\nconst md = `\nThis is the introduction to my blog post.\n\n<!-- more -->\n\nThe rest of the article continues here with more details.\n`;\n\nconst result = compile(md, {\n  plugins: [excerpt()],\n});\n\nconsole.log(result.excerpt);\n// \"This is the introduction to my blog post.\"\n```\n\n## 範例\n\n### 搭配分隔標記\n\n在 Markdown 中放置 `<!-- more -->` 註解，即可明確標示摘要的結束位置：\n\n```ts\nimport { compile, excerpt } from \"@unifast/node\";\n\nconst md = `\n# My Blog Post\n\nThis is a **bold** introduction with some content.\n\nHere is a second paragraph still in the excerpt.\n\n<!-- more -->\n\nThis content is not included in the excerpt.\n`;\n\nconst result = compile(md, {\n  plugins: [excerpt()],\n});\n\nconsole.log(result.excerpt);\n// \"My Blog Post This is a bold introduction with some content. Here is a second paragraph still in the excerpt.\"\n```\n\n### 備援為前幾段\n\n當找不到分隔標記時，外掛會退回擷取前 N 個段落：\n\n```ts\nimport { compile, excerpt } from \"@unifast/node\";\n\nconst md = `\n# My Blog Post\n\nThis is the first paragraph of my article.\n\nThis is the second paragraph with more details.\n\nThis is the third paragraph.\n`;\n\nconst result = compile(md, {\n  plugins: [\n    excerpt({\n      fallbackParagraphs: 2,\n    }),\n  ],\n});\n\nconsole.log(result.excerpt);\n// \"This is the first paragraph of my article. This is the second paragraph with more details.\"\n```\n\n### 備援為字元上限\n\n將摘要截斷至指定的最大字元長度，並在詞界處斷開：\n\n```ts\nimport { compile, excerpt } from \"@unifast/node\";\n\nconst md = `\nThis is a long article that goes on and on with lots of content.\n`;\n\nconst result = compile(md, {\n  plugins: [\n    excerpt({\n      fallbackCharacters: 30,\n    }),\n  ],\n});\n\nconsole.log(result.excerpt);\n// \"This is a long article that\"\n```",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/docs/packages/node/excerpt.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/ja/docs/packages/node/excerpt.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/node/excerpt.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/node/excerpt.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/ko/docs/packages/node/excerpt.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/fr/docs/packages/node/excerpt.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/it/docs/packages/node/excerpt.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/es/docs/packages/node/excerpt.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/node/excerpt.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/de/docs/packages/node/excerpt.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/ru/docs/packages/node/excerpt.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/hi/docs/packages/node/excerpt.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/id/docs/packages/node/excerpt.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/tr/docs/packages/node/excerpt.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/node/excerpt/",
      "api": "https://unifast.dev//api/vi/docs/packages/node/excerpt.json"
    }
  ]
}
