MCPcopy Create free account
hub / github.com/Drakkar-Software/OctoBot / extractDescription

Function extractDescription

docs/scripts/shared.mjs:15–41  ·  view source on GitHub ↗
(content, fallback)

Source from the content-addressed store, hash-verified

13 * truncated to max 160 characters for SEO meta descriptions.
14 */
15export function extractDescription(content, fallback) {
16 const paragraphLines = [];
17 let started = false;
18 for (const line of content.split('\n')) {
19 const trimmed = line.trim();
20 if (!started) {
21 if (trimmed && !trimmed.startsWith('#') && !trimmed.startsWith('---')) {
22 started = true;
23 paragraphLines.push(trimmed);
24 }
25 } else {
26 if (!trimmed || trimmed.startsWith('#')) break;
27 paragraphLines.push(trimmed);
28 }
29 }
30 const firstParagraph = paragraphLines.join(' ').replace(/\s+/g, ' ').trim();
31
32 if (firstParagraph.length > 10 && firstParagraph.length <= 160) {
33 return firstParagraph;
34 }
35 if (firstParagraph.length > 160) {
36 const truncated = firstParagraph.substring(0, 157);
37 const lastSpace = truncated.lastIndexOf(' ');
38 return (lastSpace > 100 ? truncated.substring(0, lastSpace) : truncated) + '...';
39 }
40 return fallback;
41}
42
43/** Escape special characters for safe inclusion in YAML frontmatter values. */
44export function escapeYaml(value) {

Callers 1

processFileFunction · 0.90

Calls 3

replaceMethod · 0.80
pushMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected