-
Notifications
You must be signed in to change notification settings - Fork 2
Add HTMLHint validation with auto-fix to all 10 news generation workflows #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
72d4572
b1e6b18
e3f76fe
acf7ade
47e7c2e
ed1ff46
f1c1530
d88c0a0
8cec59c
91f9fec
8205a00
0393e7c
62a85be
8ac9269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -294,7 +294,30 @@ grep -o 'Why It Matters[^<]*' "news/$(date +%Y-%m-%d)-committee-reports-en.html" | |||||||||||||
| **Note**: News index files, metadata, and sitemap are generated automatically at build time by the `prebuild` script. Do NOT run generation scripts or commit their output — only commit the article HTML files. Run `npm run prebuild` (or `npm run build`) locally if you need to preview the generated indexes, metadata, or sitemap. | ||||||||||||||
|
|
||||||||||||||
| ### Step 6: Validate & Create PR | ||||||||||||||
| Validate HTML structure, then create PR: | ||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1001,9 +1001,28 @@ This validation checks: | |||||||||
| 6. ✅ Index files have content (> 1KB) (blocking) | ||||||||||
| 7. ⚠️ Sitemap news-URL coverage (validated at build time; missing sitemap.xml is OK — it's generated by prebuild) | ||||||||||
| 8. ⚠️ Language switcher consistency across all 14 languages (warning level) | ||||||||||
|
||||||||||
| 8. ⚠️ Language switcher consistency across all 14 languages (warning level) | |
| 8. ⚠️ Language switcher consistency across all 14 languages (warning level) | |
| 9. ⚠️ Additional non-blocking quality checks as implemented in \`validate-news-generation.sh\` (warning level) | |
| 10. ✅ Additional blocking quality checks as implemented in \`validate-news-generation.sh\` (blocking) |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -232,6 +232,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ Validation script failed. Please fix the reported issues before proceeding to HTML validation or creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0393e7c: added if [ "$VALIDATION_EXIT" -ne 0 ]; then exit "$VALIDATION_EXIT"; fi after VALIDATION_EXIT=$? in all 7 workflow files where the guard was missing.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -240,6 +240,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ News generation validation failed. Please fix the reported issues before running HTMLHint or creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -231,6 +231,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ News generation validation failed (exit code $VALIDATION_EXIT). Please fix the reported issues before creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -230,6 +230,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ Validation failed (scripts/validate-news-generation.sh). Please fix the reported issues before running HTMLHint or creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -800,9 +800,28 @@ This validation checks: | |||||
| 6. ℹ️ Index files have content (skipped — index files generated at build time) | ||||||
| 7. ⚠️ Sitemap news-URL coverage (warning; missing sitemap.xml is OK — generated by prebuild) | ||||||
| 8. ⚠️ Language switcher consistency across all 14 languages (warning level) | ||||||
| 9. ⚠️ Articles have article-top-nav with back-to-news link (warning level) | ||||||
| 10. ⚠️ Articles have back-to-news link in footer (warning level) | ||||||
| 11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted) | ||||||
|
||||||
| 11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted) | |
| 9. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted) |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -230,6 +230,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | ||||||||||||||
| echo "❌ News generation validation failed. Fix the reported issues before creating a PR." | ||||||||||||||
| exit "$VALIDATION_EXIT" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ Content validation failed. Please fix the issues reported by validate-news-generation.sh before creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -235,6 +235,29 @@ npx tsx scripts/fix-article-navigation.ts | |||||||||||||
|
|
||||||||||||||
| ### Step 4: Translate, Validate & Verify Analysis Quality | ||||||||||||||
|
|
||||||||||||||
| Run validation and HTMLHint before creating PR: | ||||||||||||||
| ```bash | ||||||||||||||
| bash scripts/validate-news-generation.sh | ||||||||||||||
| VALIDATION_EXIT=$? | ||||||||||||||
|
||||||||||||||
| VALIDATION_EXIT=$? | |
| VALIDATION_EXIT=$? | |
| if [ "$VALIDATION_EXIT" -ne 0 ]; then | |
| echo "❌ Validation script failed. Please fix the reported issues before creating a PR." | |
| exit "$VALIDATION_EXIT" | |
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -423,6 +423,81 @@ export async function batchEnhanceQuality( | |
| return results; | ||
| } | ||
|
|
||
| /** | ||
| * Fix common HTML nesting errors in article content. | ||
| * | ||
| * Corrects invalid block-level nesting patterns: | ||
| * - `<p><ul>` → removes the enclosing `<p>` so the `<ul>` list is not nested inside a `<p>` paragraph | ||
| * - `<p><ol>` → removes the enclosing `<p>` so the `<ol>` list is not nested inside a `<p>` paragraph | ||
| * - `<p><div>` → removes the enclosing `<p>` so the block-level `<div>` is not nested inside a `<p>` paragraph | ||
| * - Orphaned `</p>` immediately after `</ul>` → removed | ||
| * - Orphaned `</p>` immediately after `</ol>` → removed | ||
| * - Orphaned `</p>` immediately after `</div>` (when wrapped by `<p>`) → removed | ||
| * | ||
| * @param content - Raw HTML content | ||
| * @returns Fixed HTML content | ||
| */ | ||
| export function fixArticleHtmlNesting(content: string): string { | ||
| let fixed = content; | ||
|
|
||
|
Comment on lines
+426
to
+442
|
||
| // Fix <p><ul>: remove the enclosing <p> so the list is not nested inside a paragraph | ||
| fixed = fixed.replace(/<p([^>]*)>\s*(<ul[\s>])/g, '$2'); | ||
|
|
||
| // Fix <p><ol>: remove the enclosing <p> so the ordered list is not nested inside a paragraph | ||
| fixed = fixed.replace(/<p([^>]*)>\s*(<ol[\s>])/g, '$2'); | ||
|
|
||
| // Fix <p><div>: remove enclosing <p> around block-level div | ||
| fixed = fixed.replace(/<p([^>]*)>\s*(<div[\s>])/g, '$2'); | ||
|
|
||
| // Fix orphaned </p> immediately after </ul> | ||
| fixed = fixed.replace(/<\/ul>\s*<\/p>/g, '</ul>'); | ||
|
|
||
| // Fix orphaned </p> immediately after </ol> | ||
| fixed = fixed.replace(/<\/ol>\s*<\/p>/g, '</ol>'); | ||
|
|
||
| // Fix orphaned </p> immediately after </div> that was wrapped in <p> | ||
| fixed = fixed.replace(/<\/div>\s*<\/p>/g, '</div>'); | ||
|
Comment on lines
+426
to
+459
|
||
|
|
||
| return fixed; | ||
| } | ||
|
|
||
| /** | ||
| * Fix HTML nesting errors in a file in-place. | ||
| * | ||
| * @param filePath - Path to the HTML file to fix | ||
| * @returns True if the file was modified | ||
| */ | ||
| export function fixHtmlNestingInFile(filePath: string): boolean { | ||
| if (!fs.existsSync(filePath)) { | ||
| return false; | ||
| } | ||
| const original = fs.readFileSync(filePath, 'utf-8'); | ||
| const fixed = fixArticleHtmlNesting(original); | ||
| if (fixed !== original) { | ||
| fs.writeFileSync(filePath, fixed, 'utf-8'); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // CLI entry point: support --fix flag to fix HTML nesting in news/*-*.html article files | ||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||
| if (process.argv.includes('--fix')) { | ||
| const globPattern = process.argv[process.argv.indexOf('--fix') + 1]; | ||
| const targetGlob = (globPattern && !globPattern.startsWith('-')) ? globPattern : 'news/*-*.html'; | ||
| const { globSync } = await import('glob'); | ||
| const files: string[] = globSync(targetGlob); | ||
| let fixedCount = 0; | ||
| for (const file of files) { | ||
| if (fixHtmlNestingInFile(file)) { | ||
| console.log(`Fixed HTML nesting in: ${file}`); | ||
| fixedCount++; | ||
| } | ||
| } | ||
| console.log(`Fixed ${fixedCount} of ${files.length} files.`); | ||
| } | ||
| } | ||
|
|
||
| // Export individual assessment functions for testing | ||
| export { | ||
| assessAnalyticalDepth, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented validation checklist numbering now jumps from 8 to 11, which no longer matches the actual
validate-news-generation.shchecks (it has checks 9 and 10 as well). Please update this list to include the missing check numbers/descriptions or renumber so it stays consistent with the script output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
0393e7c: added the missing check 9 (article-top-nav) and check 10 (footer back-to-news link) so the list now runs 1–11 consecutively.