Files
claude-skills-reference/marketing-skill/schema-markup/scripts/schema_validator.py
Alireza Rezvani 52321c86bc feat: Marketing Division expansion — 7 → 42 skills (#266)
* feat: Skill Authoring Standard + Marketing Expansion plans

SKILL-AUTHORING-STANDARD.md — the DNA of every skill in this repo:
10 universal patterns codified from C-Suite innovations + Corey Haines' marketingskills patterns:

1. Context-First: check domain context, ask only for gaps
2. Practitioner Voice: expert persona, goal-oriented, not textbook
3. Multi-Mode Workflows: build from scratch / optimize existing / situation-specific
4. Related Skills Navigation: when to use, when NOT to, bidirectional
5. Reference Separation: SKILL.md lean (≤10KB), refs deep
6. Proactive Triggers: surface issues without being asked
7. Output Artifacts: request → specific deliverable mapping
8. Quality Loop: self-verify, confidence tagging
9. Communication Standard: bottom line first, structured output
10. Python Tools: stdlib-only, CLI-first, JSON output, sample data

Marketing expansion plans for 40-skill marketing division build.

* feat: marketing foundation — context + ops router + authoring standard

marketing-context/: Foundation skill every marketing skill reads first
  - SKILL.md: 3 modes (auto-draft, guided interview, update)
  - templates/marketing-context-template.md: 14 sections covering
    product, audience, personas, pain points, competitive landscape,
    differentiation, objections, switching dynamics, customer language
    (verbatim), brand voice, style guide, proof points, SEO context, goals
  - scripts/context_validator.py: Scores completeness 0-100, section-by-section

marketing-ops/: Central router for 40-skill marketing ecosystem
  - Full routing matrix: 7 pods + cross-domain routing to 6 skills in
    business-growth, product-team, engineering-team, c-level-advisor
  - Campaign orchestration sequences (launch, content, CRO sprint)
  - Quality gate matching C-Suite standard
  - scripts/campaign_tracker.py: Campaign status tracking with progress,
    overdue detection, pod coverage, blocker identification

SKILL-AUTHORING-STANDARD.md: Universal DNA for all skills
  - 10 patterns: context-first, practitioner voice, multi-mode workflows,
    related skills navigation, reference separation, proactive triggers,
    output artifacts, quality loop, communication standard, python tools
  - Quality checklist for skill completion verification
  - Domain context file mapping for all 5 domains

* feat: import 20 workspace marketing skills + standard sections

Imported 20 marketing skills from OpenClaw workspace into repo:

Content Pod (5):
  content-strategy, copywriting, copy-editing, social-content, marketing-ideas

SEO Pod (2):
  seo-audit (+ references enriched by subagent), programmatic-seo (+ refs)

CRO Pod (5):
  page-cro, form-cro, signup-flow-cro, onboarding-cro, popup-cro, paywall-upgrade-cro

Channels Pod (2):
  email-sequence, paid-ads

Growth + Intel + GTM (5):
  ab-test-setup, competitor-alternatives, marketing-psychology, launch-strategy, brand-guidelines

All 29 skills now have standard sections per SKILL-AUTHORING-STANDARD.md:
   Proactive Triggers (4-5 per skill)
   Output Artifacts table
   Communication standard reference
   Related Skills with WHEN/NOT disambiguation

Subagents enriched 8 skills with additional reference docs:
  seo-audit, programmatic-seo, page-cro, form-cro,
  onboarding-cro, popup-cro, paywall-upgrade-cro, email-sequence

43 files, 10,566 lines added.

* feat: build 13 new marketing skills + social-media-manager upgrade

All skills are 100% original work — inspired by industry best practices,
written from scratch in our own voice following SKILL-AUTHORING-STANDARD.md.

NEW Content Pod (2):
  content-production — full research→draft→optimize pipeline, content_scorer.py
  content-humanizer — AI pattern detection + voice injection, humanizer_scorer.py

NEW SEO Pod (3):
  ai-seo — AI search optimization (AEO/GEO/LLMO), entirely new category
  schema-markup — JSON-LD structured data, schema_validator.py
  site-architecture — URL structure + internal linking, sitemap_analyzer.py

NEW Channels Pod (2):
  cold-email — B2B outreach (distinct from email-sequence lifecycle)
  ad-creative — bulk ad generation + platform specs, ad_copy_validator.py

NEW Growth Pod (3):
  churn-prevention — cancel flows + save offers + dunning, churn_impact_calculator.py
  referral-program — referral + affiliate programs
  free-tool-strategy — engineering as marketing

NEW Intelligence Pod (1):
  analytics-tracking — GA4/GTM setup + event taxonomy, tracking_plan_generator.py

NEW Sales Pod (1):
  pricing-strategy — pricing, packaging, monetization

UPGRADED:
  social-media-analyzer → social-media-manager (strategy, calendar, community)

Totals: 42 skills, 27 Python scripts, 60 reference docs, 163 files, 43,265 lines

* feat: update index, marketplace, README for 42 marketing skills

- skills-index.json: 89 → 124 skills (42 marketing entries)
- marketplace.json: marketing-skills v2.0.0 (42 skills, 27 tools)
- README.md: badge 134 → 169, marketing row updated
- prompt-engineer-toolkit: added YAML frontmatter
- Removed build logs from repo
- Parity check: 42/42 passed (YAML + Related + Proactive + Output + Communication)

* fix: merge content-creator into content-production, split marketing-psychology

Quality audit fixes:

1. content-creator → DEPRECATED redirect
   - Scripts (brand_voice_analyzer.py, seo_optimizer.py) moved to content-production
   - SKILL.md replaced with redirect to content-production + content-strategy
   - Eliminates duplicate routing confusion

2. marketing-psychology → 24KB split to 6.8KB + reference
   - 70+ mental models moved to references/mental-models-catalog.md (397 lines)
   - SKILL.md now lean: categories overview, most-used models, quick reference
   - Saves ~4,300 tokens per invocation

* feat: add plugin configs, Codex/OpenClaw compatibility, ClawHub packaging

- marketing-skill/SKILL.md: ClawHub-compatible root with Quick Start for Claude Code, Codex CLI, OpenClaw
- marketing-skill/CLAUDE.md: Agent instructions (routing, context, anti-patterns)
- marketing-skill/.codex/instructions.md: Codex CLI skill routing
- .claude-plugin/marketplace.json: deduplicated, marketing-skills v2.0.0
- .codex/skills-index.json: content-creator marked deprecated, psychology updated
- Total: 42 skills, 27 Python tools, 60 references, 18 plugins

* feat: add 16 Python tools to knowledge-only skills

Enriched 12 previously tool-less skills with practical Python scripts:
- seo-audit/seo_checker.py — HTML on-page SEO analysis (0-100)
- copywriting/headline_scorer.py — headline quality scoring (0-100)
- copy-editing/readability_scorer.py — Flesch + passive + filler detection
- content-strategy/topic_cluster_mapper.py — keyword clustering
- page-cro/conversion_audit.py — HTML CRO signal analysis (0-100)
- paid-ads/roas_calculator.py — ROAS/CPA/CPL calculator
- email-sequence/sequence_analyzer.py — email sequence scoring (0-100)
- form-cro/form_field_analyzer.py — form field CRO audit (0-100)
- onboarding-cro/activation_funnel_analyzer.py — funnel drop-off analysis
- programmatic-seo/url_pattern_generator.py — URL pattern planning
- ab-test-setup/sample_size_calculator.py — statistical sample sizing
- signup-flow-cro/funnel_drop_analyzer.py — signup funnel analysis
- launch-strategy/launch_readiness_scorer.py — launch checklist scoring
- competitor-alternatives/comparison_matrix_builder.py — feature comparison
- social-media-manager/social_calendar_generator.py — content calendar
- readability_scorer.py — fixed demo mode for non-TTY execution

All 43/43 scripts pass execution. All stdlib-only, zero pip installs.
Total: 42 skills, 43 Python tools, 60+ reference docs.

* feat: add 3 more Python tools + improve 6 existing scripts

New tools from build agent:
- email-sequence/scripts/sequence_analyzer.py — email sequence scoring (91/100 demo)
- paid-ads/scripts/roas_calculator.py — ROAS/CPA/CPL/break-even calculator
- competitor-alternatives/scripts/comparison_matrix_builder.py — feature matrix

Improved scripts (better demo modes, fuller analysis):
- seo_checker.py, headline_scorer.py, readability_scorer.py,
  conversion_audit.py, topic_cluster_mapper.py, launch_readiness_scorer.py

Total: 42 skills, 47 Python tools, all passing.

* fix: remove duplicate scripts from deprecated content-creator

Scripts already live in content-production/scripts/. The content-creator
directory is now a pure redirect (SKILL.md only + legacy assets/refs).

* fix: scope VirusTotal scan to executable files only

Skip scanning .md, .py, .json, .yml — they're plain text files
that VirusTotal can't meaningfully analyze. This prevents 429 rate
limit errors on PRs with many text file changes (like 42 marketing skills).

Scan still covers: .js, .ts, .sh, .mjs, .cjs, .exe, .dll, .so, .bin, .wasm

---------

Co-authored-by: Leo <leo@openclaw.ai>
2026-03-06 03:56:16 +01:00

431 lines
15 KiB
Python

#!/usr/bin/env python3
"""
schema_validator.py — Extracts and validates JSON-LD structured data from HTML.
Usage:
python3 schema_validator.py [file.html]
cat page.html | python3 schema_validator.py
If no file is provided, runs on embedded sample HTML for demonstration.
Output: Human-readable validation report + JSON summary.
Scoring: 0-100 per schema block based on required/recommended field coverage.
"""
import json
import sys
import re
import select
from html.parser import HTMLParser
from typing import List, Dict, Any, Optional
# ─── Required and recommended fields per schema type ─────────────────────────
SCHEMA_RULES: Dict[str, Dict[str, List[str]]] = {
"Article": {
"required": ["headline", "image", "datePublished", "author"],
"recommended": ["dateModified", "publisher", "description", "url", "mainEntityOfPage"],
},
"BlogPosting": {
"required": ["headline", "image", "datePublished", "author"],
"recommended": ["dateModified", "publisher", "description", "url", "mainEntityOfPage"],
},
"NewsArticle": {
"required": ["headline", "image", "datePublished", "author"],
"recommended": ["dateModified", "publisher", "description", "url"],
},
"HowTo": {
"required": ["name", "step"],
"recommended": ["description", "image", "totalTime", "tool", "supply", "estimatedCost"],
},
"FAQPage": {
"required": ["mainEntity"],
"recommended": [],
},
"Product": {
"required": ["name", "offers"],
"recommended": ["description", "image", "sku", "brand", "aggregateRating"],
},
"Organization": {
"required": ["name", "url"],
"recommended": ["logo", "sameAs", "contactPoint", "description", "foundingDate"],
},
"LocalBusiness": {
"required": ["name", "address"],
"recommended": ["telephone", "openingHoursSpecification", "geo", "priceRange", "image", "url"],
},
"BreadcrumbList": {
"required": ["itemListElement"],
"recommended": [],
},
"VideoObject": {
"required": ["name", "description", "thumbnailUrl", "uploadDate"],
"recommended": ["duration", "contentUrl", "embedUrl", "interactionStatistic", "hasPart"],
},
"WebSite": {
"required": ["url"],
"recommended": ["name", "potentialAction"],
},
"Event": {
"required": ["name", "startDate", "location"],
"recommended": ["endDate", "description", "image", "organizer", "offers"],
},
"Recipe": {
"required": ["name", "image", "author", "datePublished"],
"recommended": ["description", "cookTime", "prepTime", "totalTime", "recipeYield",
"recipeIngredient", "recipeInstructions", "aggregateRating"],
},
}
KNOWN_TYPES = set(SCHEMA_RULES.keys())
# ─── HTML Parser to extract JSON-LD blocks ───────────────────────────────────
class JSONLDExtractor(HTMLParser):
"""Extracts all <script type="application/ld+json"> blocks from HTML."""
def __init__(self):
super().__init__()
self.blocks: List[str] = []
self._in_ld_json = False
self._current = []
def handle_starttag(self, tag: str, attrs: list):
if tag.lower() == "script":
attr_dict = dict(attrs)
if attr_dict.get("type", "").lower() == "application/ld+json":
self._in_ld_json = True
self._current = []
def handle_endtag(self, tag: str):
if tag.lower() == "script" and self._in_ld_json:
self._in_ld_json = False
self.blocks.append("".join(self._current).strip())
def handle_data(self, data: str):
if self._in_ld_json:
self._current.append(data)
# ─── Validation logic ────────────────────────────────────────────────────────
def detect_type(obj: Dict) -> Optional[str]:
"""Determine the @type of a schema object."""
t = obj.get("@type")
if isinstance(t, list):
# Return first known type
for item in t:
if item in KNOWN_TYPES:
return item
return t[0] if t else None
return t
def score_schema(schema_type: str, obj: Dict) -> Dict:
"""Score a single schema object against known rules. Returns 0-100."""
if schema_type not in SCHEMA_RULES:
return {
"score": 50,
"status": "unknown_type",
"required_present": [],
"required_missing": [],
"recommended_present": [],
"recommended_missing": [],
"notes": [f"No validation rules defined for '{schema_type}' — manual check recommended."],
}
rules = SCHEMA_RULES[schema_type]
required = rules.get("required", [])
recommended = rules.get("recommended", [])
required_present = [f for f in required if f in obj and obj[f]]
required_missing = [f for f in required if f not in obj or not obj[f]]
recommended_present = [f for f in recommended if f in obj and obj[f]]
recommended_missing = [f for f in recommended if f not in obj or not obj[f]]
# Score: required fields = 70 points, recommended = 30 points
req_score = (len(required_present) / len(required) * 70) if required else 70
rec_score = (len(recommended_present) / len(recommended) * 30) if recommended else 30
total_score = int(req_score + rec_score)
notes = []
# Type-specific checks
if schema_type in ("Article", "BlogPosting", "NewsArticle"):
image = obj.get("image")
if image:
img_url = image if isinstance(image, str) else image.get("url", "") if isinstance(image, dict) else ""
if img_url and not img_url.startswith("http"):
notes.append("⚠️ 'image' URL appears to be relative — must be absolute (https://...)")
if "datePublished" in obj:
dp = obj["datePublished"]
if not re.match(r"\d{4}-\d{2}-\d{2}", str(dp)):
notes.append("⚠️ 'datePublished' should be ISO 8601 format: YYYY-MM-DD")
if schema_type == "Product":
offers = obj.get("offers", {})
if isinstance(offers, dict):
price = offers.get("price")
if isinstance(price, str) and any(c in price for c in "$€£¥"):
notes.append("⚠️ 'offers.price' should be numeric (49.99), not a string with currency symbol.")
avail = offers.get("availability", "")
if avail and not avail.startswith("https://schema.org/"):
notes.append("⚠️ 'offers.availability' must use full URL: https://schema.org/InStock")
if schema_type == "FAQPage":
entities = obj.get("mainEntity", [])
if isinstance(entities, list):
for i, q in enumerate(entities):
if not q.get("acceptedAnswer", {}).get("text"):
notes.append(f"⚠️ Question #{i+1} has empty 'acceptedAnswer.text'")
if schema_type == "BreadcrumbList":
items = obj.get("itemListElement", [])
if isinstance(items, list):
positions = [item.get("position") for item in items if isinstance(item, dict)]
if sorted(positions) != list(range(1, len(positions) + 1)):
notes.append("⚠️ 'itemListElement' positions must be sequential integers starting at 1.")
return {
"score": total_score,
"status": "valid" if not required_missing else "missing_required",
"required_present": required_present,
"required_missing": required_missing,
"recommended_present": recommended_present,
"recommended_missing": recommended_missing,
"notes": notes,
}
def validate_block(raw_json: str, block_index: int) -> List[Dict]:
"""Parse and validate a single JSON-LD block. Returns list of results (may contain @graph)."""
results = []
try:
data = json.loads(raw_json)
except json.JSONDecodeError as e:
return [{
"block": block_index,
"type": "PARSE_ERROR",
"score": 0,
"status": "parse_error",
"error": str(e),
"notes": ["❌ JSON is malformed — fix syntax before validation."],
}]
# Handle @graph
objects = data.get("@graph", [data]) if isinstance(data, dict) else [data]
for obj in objects:
if not isinstance(obj, dict):
continue
schema_type = detect_type(obj)
if not schema_type:
results.append({
"block": block_index,
"type": "UNKNOWN",
"score": 0,
"status": "no_type",
"notes": ["❌ No '@type' found in schema object."],
})
continue
validation = score_schema(schema_type, obj)
results.append({
"block": block_index,
"type": schema_type,
**validation,
})
return results
def grade(score: int) -> str:
if score >= 90:
return "🟢 Excellent"
if score >= 70:
return "🟡 Good"
if score >= 50:
return "🟠 Needs Work"
return "🔴 Poor"
# ─── Report printer ──────────────────────────────────────────────────────────
def print_report(all_results: List[Dict], html_source: str) -> None:
print("\n" + "" * 60)
print(" SCHEMA MARKUP VALIDATION REPORT")
print("" * 60)
if not all_results:
print("\n❌ No JSON-LD blocks found in this HTML.")
print(" Add structured data in <script type=\"application/ld+json\"> tags.\n")
return
total_score = 0
for r in all_results:
print(f"\n── Block {r['block']} · @type: {r['type']} ──")
score = r.get("score", 0)
total_score += score
print(f" Score: {score}/100 {grade(score)}")
if r.get("status") == "parse_error":
print(f" ❌ Parse error: {r.get('error')}")
continue
if r.get("required_missing"):
print(f" Missing required: {', '.join(r['required_missing'])}")
else:
print(f" Required fields: ✅ All present ({', '.join(r.get('required_present', []))})")
if r.get("recommended_missing"):
print(f" Missing recommended: {', '.join(r['recommended_missing'])}")
if r.get("recommended_present"):
print(f" Recommended present: {', '.join(r['recommended_present'])}")
for note in r.get("notes", []):
print(f" {note}")
avg = total_score // len(all_results) if all_results else 0
print(f"\n{'' * 60}")
print(f" OVERALL SCORE: {avg}/100 {grade(avg)}")
print(f" Blocks analyzed: {len(all_results)}")
print("" * 60)
print("\n📋 TESTING CHECKLIST")
print(" □ Google Rich Results Test: https://search.google.com/test/rich-results")
print(" □ Schema.org Validator: https://validator.schema.org")
print(" □ After deploy: Check Search Console → Enhancements\n")
# ─── Sample HTML ─────────────────────────────────────────────────────────────
SAMPLE_HTML = """<!DOCTYPE html>
<html>
<head>
<title>How to Write Cold Emails That Get Replies</title>
<!-- Article schema — headline present, but image is relative URL -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "How to Write Cold Emails That Get Replies",
"image": "/images/cold-email-guide.jpg",
"datePublished": "2024-03-01",
"dateModified": "2024-03-15",
"author": {
"@type": "Person",
"name": "Reza Rezvani"
},
"publisher": {
"@type": "Organization",
"name": "Growth Lab",
"logo": {
"@type": "ImageObject",
"url": "https://growthlab.com/logo.png"
}
}
}
</script>
<!-- FAQPage schema — complete and valid -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the ideal length for a cold email?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Keep cold emails under 150 words. Busy professionals scan, not read. If your email needs scrolling, it will not get a reply."
}
},
{
"@type": "Question",
"name": "How many follow-ups should I send?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Send 3-5 follow-ups with increasing gaps (3 days, 5 days, 7 days, 14 days). Each follow-up must add new value — never just check in."
}
}
]
}
</script>
<!-- BreadcrumbList — position gap (jumps from 1 to 3) -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://growthlab.com"
},
{
"@type": "ListItem",
"position": 3,
"name": "How to Write Cold Emails",
"item": "https://growthlab.com/blog/cold-email-guide"
}
]
}
</script>
</head>
<body>
<h1>How to Write Cold Emails That Get Replies</h1>
<p>Cold email works when it sounds human...</p>
</body>
</html>
"""
# ─── Main ─────────────────────────────────────────────────────────────────────
def main():
if len(sys.argv) > 1:
arg = sys.argv[1]
if arg == "-":
html = sys.stdin.read()
else:
try:
with open(arg, "r", encoding="utf-8") as f:
html = f.read()
except FileNotFoundError:
print(f"Error: File not found: {arg}", file=sys.stderr)
sys.exit(1)
else:
print("No file provided — running on embedded sample HTML.\n")
html = SAMPLE_HTML
extractor = JSONLDExtractor()
extractor.feed(html)
all_results = []
for i, block in enumerate(extractor.blocks, start=1):
results = validate_block(block, i)
all_results.extend(results)
print_report(all_results, html)
# JSON output for programmatic use
summary = {
"blocks_found": len(extractor.blocks),
"schemas_validated": len(all_results),
"average_score": (sum(r.get("score", 0) for r in all_results) // len(all_results)) if all_results else 0,
"results": all_results,
}
print("\n── JSON Output ──")
print(json.dumps(summary, indent=2))
if __name__ == "__main__":
main()