MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / parseFrontmatter

Function parseFrontmatter

scripts/check-seo-metadata.cjs:47–65  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

45}
46
47function parseFrontmatter(content) {
48 const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
49 if (!match) return {};
50 const fm = {};
51 for (const line of match[1].split(/\r?\n/)) {
52 // Handle quoted keys like "og:image": value
53 const quoted = line.match(/^"([^"]+)"\s*:\s*(.+)/);
54 if (quoted) {
55 fm[quoted[1].trim()] = quoted[2].trim().replace(/^["']|["']$/g, '');
56 continue;
57 }
58 // Handle unquoted keys like title: value
59 const unquoted = line.match(/^([a-zA-Z_][\w-]*)\s*:\s*(.+)/);
60 if (unquoted) {
61 fm[unquoted[1].trim()] = unquoted[2].trim().replace(/^["']|["']$/g, '');
62 }
63 }
64 return fm;
65}
66
67function hasIllustrations(content) {
68 return IMAGE_PATTERN.test(content);

Callers 1

Calls 1

trimMethod · 0.65

Tested by

no test coverage detected