diff --git a/laravel/app/ContentCenter/ReformatPublished.php b/laravel/app/ContentCenter/ReformatPublished.php index 5b288d06..2b96e821 100644 --- a/laravel/app/ContentCenter/ReformatPublished.php +++ b/laravel/app/ContentCenter/ReformatPublished.php @@ -41,23 +41,28 @@ final class ReformatPublished foreach ($records as $x) { abort_unless($x['status'] === 'published' && $x['approval_id'] === $job['approval_id'] && $x['source_key'] === $artifact['source_key'], 409); } + $current = file_get_contents($path); + $siteMarkdown = Publication::siteMarkdown($artifact['markdown']); if ($records[0]['artifact_hash'] === $hash && $records[1]['artifact_hash'] === $hash) { - abort_unless(file_get_contents($path) === $artifact['markdown'], 409); + abort_unless(in_array($current, [$artifact['markdown'], $siteMarkdown], true), 409); return ['artifact' => $artifact, 'artifact_hash' => $hash, 'receipt' => $records[0], 'changed' => false]; } - abort_unless($records[0]['artifact_hash'] === $job['expected_hash'] && $records[1]['artifact_hash'] === $job['expected_hash'] && file_get_contents($path) === $old['markdown'], 409); + $originalMarkdown = [$old['markdown'], Publication::siteMarkdown($old['markdown'])]; + abort_unless($records[0]['artifact_hash'] === $job['expected_hash'] + && $records[1]['artifact_hash'] === $job['expected_hash'] + && in_array($current, $originalMarkdown, true), 409); $backup = $dir.'/reformat-'.$job['approval_id'].'-'.$hash.'.json'; if (! is_file($backup)) { - ArticleDocument::write($backup, json_encode(['artifact' => $old, 'records' => $records], JSON_THROW_ON_ERROR)); + ArticleDocument::write($backup, json_encode(['artifact' => $old, 'site_markdown' => $current, 'records' => $records], JSON_THROW_ON_ERROR)); chmod($backup, 0600); } try { - ArticleDocument::write($path, $artifact['markdown']); + ArticleDocument::write($path, $siteMarkdown); (new WeeklyRanking($p))->renderCurrent(); $p->build(); } catch (\Throwable $e) { - ArticleDocument::write($path, $old['markdown']); + ArticleDocument::write($path, $current); throw new \RuntimeException('格式修复构建失败,原文章已恢复。', 0, $e); } $record = $records[0]; diff --git a/laravel/tests/Feature/ContentCenterTest.php b/laravel/tests/Feature/ContentCenterTest.php index a8b334cf..0b9b13c5 100644 --- a/laravel/tests/Feature/ContentCenterTest.php +++ b/laravel/tests/Feature/ContentCenterTest.php @@ -149,12 +149,12 @@ final class ContentCenterTest extends TestCase } } - private function repairJob(): array + private function repairJob(bool $normalizeEmptyTags = false): array { $input = $this->reviewInput(); $old = app(ArticleArtifact::class)->build($input); File::makeDirectory($this->root.'/vuepress/docs/.vuepress', 0755, true); - $old['markdown'] = "---\ntitle: legacy\n---\n