If an excerpt is manually specified using <!--more-->, use the content before it as the excerpt.
If no excerpt is specified, extract text from the article (links, images, mermaid diagrams, etc. are ignored) and take the first excerpt_length (default 400, configurable) characters from the beginning of the text.
If the length of the extracted text is less than excerpt_length (i.e., the article is very short), use the entire text as the excerpt and end the processing. Otherwise, take the extracted text as the excerpt text.
(Optional) Extract the first image element from the article based on excerpt_img_selector, and insert the image element at the beginning of the excerpt text to create the final excerpt.
Configuration
Add the configuration to _config.yml. Default configuration is used if not specified.
excerpt_length is set to 400 by default and can be changed by specifying excerpt_length: 500.
excerpt_img_selector is set to '' by default, which means images are not extracted. It can be configured in any CSS selector format, such as excerpt_img_selector: 'img' (matching the first image element), excerpt_img_selector: 'img, pre.mermaid, figure' (matching the first image element, code block, or mermaid diagram, whichever appears first).