Build and utility scripts for the Physics Book project.
| Script | Command | Description |
|---|---|---|
| content | npm run check:content |
Validate and fix content quality |
| equations | npm run check:equations |
Validate and fix equations |
| check-links | npm run check:links |
Validate internal/external links |
| check-orphans | npm run check:orphans |
Find unreferenced files |
| check-figures | npm run check:figures |
Validate figure references |
| check-math | npm run check:math |
Check LaTeX delimiter balance |
| check-accessibility | npm run check:accessibility |
Check alt text and accessibility |
| check-yaml | npm run check:yaml |
Validate YAML front matter |
| check-structure | npm run check:structure |
Validate document structure |
| check-cross-references | npm run check:cross-refs |
Validate cross-references |
| lint-markdown | npm run lint:markdown |
Lint markdown files |
| fix-liquid-syntax | npm run fix:liquid |
Fix Liquid syntax in math |
| standardize-links | npm run fix:links |
Convert links to Jekyll format |
| generate-pdf | npm run generate:pdf |
Generate PDF of chapters |
| generate-icons | npm run generate:icons |
Generate PWA icons |
| build-index | npm run generate:search-index |
Generate search index |
| parse-summary | npm run parse:summary |
Generate summary.json |
| update-front-matter | npm run update:front-matter |
Update YAML front matter |
| rename-figures | npm run update:figures |
Rename figures and update refs |
| convert-webp | npm run convert:webp |
Convert images to WebP |
| convert-math-delimiters | npm run convert:math-delimiters |
Convert LaTeX delimiters |
| sync-config | npm run sync:config |
Sync package.json with _config.yml |
| validate-deploy | npm run deploy:validate |
Validate deployment |
| crawl-all-pages | npm run crawl |
Navigate all pages to find errors |
All scripts follow a consistent naming convention using colons as separators:
| Prefix | Purpose | Examples |
|---|---|---|
check:* |
Validation/quality checks | check:links, check:yaml, check:content |
fix:* |
Auto-fix issues | fix:content, fix:equations, fix:liquid |
lint:* |
Lint files | lint:markdown |
generate:* |
File/asset generation | generate:pdf, generate:icons |
parse:* |
Parse/extract data | parse:summary |
update:* |
Update existing files | update:front-matter, update:figures |
convert:* |
Format conversion | convert:webp |
sync:* |
Synchronize data | sync:config |
deploy:* |
Deployment operations | deploy:validate |
:strict- Enable stricter validation (e.g.,check:content:strict):fix- Apply fixes (e.g.,check:content:fix):apply- Apply changes to files (e.g.,fix:liquid:apply)
All scripts use a shared utilities library in scripts/lib/:
scripts/lib/
├── index.js # Re-exports all utilities
├── constants.js # Shared constants (UNITS, TERMINOLOGY, etc.)
├── parser.js # Content parsing utilities
├── reporter.js # Output formatting with chalk
├── cli.js # CLI argument parsing
└── files.js # File operations
// Import everything
import { UNITS, ContentParser, printHeader, runCli } from './lib/index.js';
// Or import specific modules
import { UNITS, TERMINOLOGY } from './lib/constants.js';
import { ContentParser } from './lib/parser.js';
import { printHeader, printResults } from './lib/reporter.js';Combined content validation and fixing script. Replaces the old check-content.js and validate-content.js.
npm run check:content # Check only
npm run check:content:strict # Stricter validation
npm run check:content:fix # Apply fixes
npm run fix:content # Alias for --fixChecks/Fixes:
- Physical units spacing (e.g., "20m" -> "20 m")
- Terminology consistency (British -> American English)
- Duplicate words
- Common typos
- Inconsistent notation
Options:
--fix- Apply fixes to files--strict- Enable stricter validation--check- Check only mode
Combined equation validation and fixing script. Replaces the old check-equations.js and validate-equations.js.
npm run check:equations # Check only
npm run check:equations:strict # Stricter validation
npm run check:equations:fix # Apply fixes
npm run fix:equations # Alias for --fixChecks/Fixes:
- Equation numbering consistency
- LaTeX syntax errors
- Unbalanced delimiters (braces, $, \left/\right)
- Equation references
- Common LaTeX mistakes
- Broken inline math
Options:
--fix- Apply fixes to files--strict- Enable stricter validation
Validates all links (internal and external) in markdown files.
npm run check:links # Standard check
npm run check:links:fast # Faster with shorter timeoutsOptions:
--timeout <ms>- Request timeout (default: 10000)--retries <num>- Retries for failed requests (default: 2)--concurrent <num>- Max concurrent requests (default: 10)
Detects unreferenced files in assets/ and resources/ directories.
npm run check:orphans # Report orphaned files
npm run check:orphans:cleanup # Generate cleanup scriptComprehensive figure validation.
npm run check:figures # Run all checks
npm run check:figures:pattern # Check filename patterns only
npm run check:figures:missing # Check for missing files onlyChecks for unbalanced LaTeX math delimiters.
npm run check:math # Check contents/ directoryChecks accessibility concerns in markdown files.
npm run check:accessibility # Standard check
npm run check:accessibility:strict # Strict modeChecks:
- Missing or empty alt text on images
- Uninformative alt text
- Heading level skips
- Empty or uninformative link text
Validates YAML front matter structure.
npm run check:yaml # Standard validation
npm run check:yaml:strict # Strict modeValidates document structure and organization.
npm run check:structure # Standard validation
npm run check:structure:strict # Strict modeValidates cross-references between chapters.
npm run check:cross-refs # Standard validation
npm run check:cross-refs:strict # Strict modeFixes Liquid syntax errors in LaTeX math expressions.
npm run fix:liquid # Check for issues (dry run)
npm run fix:liquid:apply # Apply fixes to filesConverts internal links to Jekyll/MyST convention.
npm run fix:links # Dry run
npm run fix:links:apply # Apply changesLints markdown files for common issues and physics-specific rules.
npm run lint:markdown # Dry run
npm run lint:markdown:apply # Apply fixes
npm run lint:markdown:strict # Strict modeGenerates PDF versions of chapters using Playwright.
npm run generate:pdf # All chapters separately
npm run generate:pdf:combined # All chapters in one PDF
npm run generate:pdf:chapter # Specific chapter
npm run generate:pdf:install # Install Playwright browsersOptimized parallel PDF generation with configurable concurrency. Generates all PDFs in three phases for maximum efficiency.
# Generate all PDFs with parallel processing (default: 4 concurrent)
node scripts/generate-pdf-parallel.js
# With custom concurrency
MAX_CONCURRENCY=8 node scripts/generate-pdf-parallel.jsFeatures:
- Phase 1: Section PDFs (241 items, 4 parallel) - ~683s
- Phase 2: Chapter intro PDFs (34 items, 4 parallel) - ~32s
- Phase 3: Combined chapter PDFs (34 items, 2 parallel) - ~1094s
- Automatic error handling and retry logic
- Real-time progress reporting
- Total generation: ~30 minutes for 309 PDFs
Performance:
- 4x-8x faster than sequential generation
- Memory-optimized with controlled concurrency
- Reuses browser instances across batches
Recovery script for failed PDF generations. Automatically regenerates problematic combined chapter PDFs with extended timeouts.
# Regenerate failed PDFs (hardcoded list)
node scripts/regenerate-failed-pdfs.jsFeatures:
- Extended timeout (300s vs standard 180s)
- No strict networkidle requirements for large content
- Sequential processing to avoid resource contention
- Detailed progress logging
This script is automatically called by the GitHub Actions workflow when parallel generation reports failures.
Generates PWA icons and favicons from source logo.
npm run generate:iconsCreates a searchable index for the PWA using MiniSearch.
npm run generate:search-indexParses SUMMARY.md to generate summary.json.
npm run parse:summaryUpdates YAML front matter with chapter/section numbers.
npm run update:front-matterRenames figure files and updates all references.
npm run update:figures -- Figure_01_02_03 Figure_01_02_04Converts images to WebP format for better compression.
npm run convert:webp
npm run convert:webp -- --dry-run # Preview changesConverts LaTeX math delimiters between formats (e.g., \(...\) to $...$).
npm run convert:math-delimiters # Dry run
npm run convert:math-delimiters -- --apply # Apply changesValidates deployed site with Playwright browser tests.
npm run deploy:validate # Validate Vercel deployment
npm run deploy:validate:github # Validate GitHub Pages
npm run deploy:validate:verbose # Verbose outputPrerequisites:
- Playwright browsers installed:
npx playwright install chromium
Navigates through all pages on local Jekyll server to detect errors during development.
npm run crawl # Crawl all pages (quiet mode)
npm run crawl:verbose # Show detailed output for every pageWhat it checks:
- JavaScript console errors
- Failed resource loads (CSS, JS, images)
- Unrendered MathJax equations ($$)
- HTTP errors (404, 500, etc.)
- Page load failures
Prerequisites:
- Jekyll server must be running:
bundle exec jekyll serve - Playwright browsers installed:
npx playwright install chromium
Typical workflow:
# Terminal 1: Start Jekyll server
bundle exec jekyll serve
# Terminal 2: Crawl all pages
npm run crawlThis is especially useful after major changes to catch errors across the entire site.
Full audit of the project:
npm run auditThis runs all validation scripts:
check:links- Link validationcheck:orphans- Orphan file detectioncheck:figures- Figure validationcheck:yaml- YAML front matter validationcheck:accessibility- Accessibility checkscheck:content- Content quality validationcheck:structure- Document structure validationcheck:cross-refs- Cross-reference validationcheck:equations- Equation validation
For a comprehensive check including all validations:
npm run check:allScripts use these npm packages:
chalk- Terminal stylingcheerio- HTML parsing (for search index)glob- File pattern matchinggray-matter- YAML front matter parsingjs-yaml- YAML processingminisearch- Full-text search indexingnode-fetch- HTTP requestssharp- Image processingsimple-git- Git operations@playwright/test- PDF generation
For physics calculation verification:
python- Python 3.x (for check_math.py)