Skip to content

Commit a53f2dc

Browse files
fix(seo): handle multi-line yaml block scalar in surgical edit
Vercel build 在 PR 341 fail,根因:surgical edit 没考虑 title 用 YAML folded/literal block scalar(>- / |- / >+ 等)时的多行续行。 case: --- title: >- line 1 line 2 date: "..." --- 之前逻辑在第一个顶级键(title:)行后直接插入 description:,把 title 的续行变成 dangling indented text,js-yaml 报 "bad indentation of a mapping entry"。 修:找 insert 位置时也吃缩进/空行续行,与 description 块检测同样处理。 顺手修复 2309 文件被先前 bug 改坏的 frontmatter。 另外 142 / 1545 两个 mdx 是 prebuild escape-angles.mjs 跑出来的产物 (转义 markdown 文本里的 <、>),一起提交进来防止 build 时反复变更。
1 parent 3132871 commit a53f2dc

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

content/docs/career/interview-prep/leetcode/2309兼具大小写的最好英文字母_translated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: >-
3-
description: "LeetCode 2309. 兼具大小写的最好英文字母 题解 — 使用哈希表与位运算两种解法,哈希表法从 Z 开始逆序查找字母是否同时出现大小写,位运算法用两个整数掩码分别记录小写和大写字母出现情况,再通过与运算找出最高位对应字母。适合正在刷 LeetCode 每日一题、想掌握哈希表与位运算技巧的求职者和算法学习者。"
43
2309. The best English letters with both appropriates and lowercases One
54
question daily
5+
description: "LeetCode 2309. 兼具大小写的最好英文字母 题解 — 使用哈希表与位运算两种解法,哈希表法从 Z 开始逆序查找字母是否同时出现大小写,位运算法用两个整数掩码分别记录小写和大写字母出现情况,再通过与运算找出最高位对应字母。适合正在刷 LeetCode 每日一题、想掌握哈希表与位运算技巧的求职者和算法学习者。"
66
date: "2024.01.01 0:00"
77
tags:
88
- - Python

content/docs/career/interview-prep/leetcode/[1545]找出第 N 个二进制字符串中的第 K 位.en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Length pattern: $|S_n| = 2^n - 1$.
6868

6969
Three cases for the position of `k`:
7070

71-
- **Left half** ($k < mid$): This is an exact copy of $S_{n-1}$, so we simply ask "what is the $k$-th bit of $S_{n-1}$?"
71+
- **Left half** ($k &lt; mid$): This is an exact copy of $S_{n-1}$, so we simply ask "what is the $k$-th bit of $S_{n-1}$?"
7272
- **Middle** ($k = mid$): By the construction rule, this bit is always `"1"`.
73-
- **Right half** ($k > mid$): This is the most elegant part. The right half is the reverse-invert of $S_{n-1}$.
73+
- **Right half** ($k &gt; mid$): This is the most elegant part. The right half is the reverse-invert of $S_{n-1}$.
7474

7575
Because of the **reverse**, the 1st character of the right half corresponds to the last character of the left half, and so on.
7676

scripts/generate-descriptions.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,29 @@ function writeFrontmatterDescription(relPath, newDescription) {
464464
const after = lines.slice(descEnd + 1);
465465
newBody = [...before, newLine, ...after].join("\n");
466466
} else {
467-
// 没有 description 字段,插在首个顶级 yaml 键行后(一般是 title 后)
467+
// 没有 description 字段,插在首个顶级 yaml 键 + 它的所有续行 之后。
468+
// 必须跳过续行,否则 title 用 ">-"/"|" 多行 block scalar 时,把
469+
// description 插到续行中间会破坏 yaml(CodeQL 测过的 case):
470+
// title: >- ← 我们找到这行
471+
// line 1 of title ← 续行(缩进)
472+
// line 2 of title ← 续行
473+
// description: "新" ← 必须插这里,不是 title 行后
474+
// date: "..."
468475
let insertAt = 1;
469476
for (let i = 0; i < lines.length; i++) {
470477
if (TOP_LEVEL_KEY_RE.test(lines[i])) {
471-
insertAt = i + 1;
478+
let endOfFirstKey = i;
479+
for (let j = i + 1; j < lines.length; j++) {
480+
const line = lines[j];
481+
// 缩进或空行视为当前键的续行(block scalar / multi-line quoted)
482+
if (line === "" || /^[ \t]/.test(line)) {
483+
endOfFirstKey = j;
484+
continue;
485+
}
486+
// 下一个顶级键出现 → 停
487+
break;
488+
}
489+
insertAt = endOfFirstKey + 1;
472490
break;
473491
}
474492
}

0 commit comments

Comments
 (0)