chore: adjusted tags to accept yaml multiline arrays for tags 427f7591
Steve · 2026-01-31 07:50 1 file(s) · +51 −3
packages/cli/src/lib/markdown.ts +51 −3
34 34
  const raw: Record<string, unknown> = {};
35 35
  const lines = frontmatterStr.split("\n");
36 36
37 -
  for (const line of lines) {
37 +
  let i = 0;
38 +
  while (i < lines.length) {
39 +
    const line = lines[i];
40 +
    if (line === undefined) {
41 +
      i++;
42 +
      continue;
43 +
    }
38 44
    const sepIndex = line.indexOf(separator);
39 -
    if (sepIndex === -1) continue;
45 +
    if (sepIndex === -1) {
46 +
      i++;
47 +
      continue;
48 +
    }
40 49
41 50
    const key = line.slice(0, sepIndex).trim();
42 51
    let value = line.slice(sepIndex + 1).trim();
49 58
      value = value.slice(1, -1);
50 59
    }
51 60
52 -
    // Handle arrays (simple case for tags)
61 +
    // Handle inline arrays (simple case for tags)
53 62
    if (value.startsWith("[") && value.endsWith("]")) {
54 63
      const arrayContent = value.slice(1, -1);
55 64
      raw[key] = arrayContent
56 65
        .split(",")
57 66
        .map((item) => item.trim().replace(/^["']|["']$/g, ""));
67 +
    } else if (value === "" && !isToml) {
68 +
      // Check for YAML-style multiline array (key with no value followed by - items)
69 +
      const arrayItems: string[] = [];
70 +
      let j = i + 1;
71 +
      while (j < lines.length) {
72 +
        const nextLine = lines[j];
73 +
        if (nextLine === undefined) {
74 +
          j++;
75 +
          continue;
76 +
        }
77 +
        // Check if line is a list item (starts with whitespace and -)
78 +
        const listMatch = nextLine.match(/^\s+-\s*(.*)$/);
79 +
        if (listMatch && listMatch[1] !== undefined) {
80 +
          let itemValue = listMatch[1].trim();
81 +
          // Remove quotes if present
82 +
          if (
83 +
            (itemValue.startsWith('"') && itemValue.endsWith('"')) ||
84 +
            (itemValue.startsWith("'") && itemValue.endsWith("'"))
85 +
          ) {
86 +
            itemValue = itemValue.slice(1, -1);
87 +
          }
88 +
          arrayItems.push(itemValue);
89 +
          j++;
90 +
        } else if (nextLine.trim() === "") {
91 +
          // Skip empty lines within the array
92 +
          j++;
93 +
        } else {
94 +
          // Hit a new key or non-list content
95 +
          break;
96 +
        }
97 +
      }
98 +
      if (arrayItems.length > 0) {
99 +
        raw[key] = arrayItems;
100 +
        i = j;
101 +
        continue;
102 +
      } else {
103 +
        raw[key] = value;
104 +
      }
58 105
    } else if (value === "true") {
59 106
      raw[key] = true;
60 107
    } else if (value === "false") {
62 109
    } else {
63 110
      raw[key] = value;
64 111
    }
112 +
    i++;
65 113
  }
66 114
67 115
  // Apply field mappings to normalize to standard PostFrontmatter fields