Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions _site/scripts/update_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

Usage:
python _site/scripts/update_kb.py
python _site/scripts/update_kb.py --locale es
"""

import re
import argparse
import json
import re
from pathlib import Path
from typing import Dict, Any, Tuple

Expand All @@ -44,6 +46,27 @@
'general-faqs': 'General & FAQs',
}

# Category names are structural metadata rather than article frontmatter, so
# localized indexes need an explicit label for each knowledge-base directory.
LOCALIZED_CATEGORY_LABELS = {
'es': {
'performance-optimization': 'Rendimiento y optimización',
'cloud-services': 'Cloud',
'data-import-export': 'Importación y exportación de datos',
'configuration-settings': 'Configuración y ajustes',
'integrations': 'Integraciones y bibliotecas de cliente',
'troubleshooting': 'Resolución de problemas y errores',
'tables-schema': 'Tablas y esquema',
'queries-sql': 'Consultas y SQL',
'materialized-views': 'Vistas materializadas y proyecciones',
'monitoring-debugging': 'Monitorización y depuración',
'security': 'Seguridad y control de acceso',
'data-management': 'Gestión de datos',
'setup-installation': 'Configuración e instalación',
'general-faqs': 'General y preguntas frecuentes',
},
}

def parse_frontmatter(content: str) -> Dict[str, Any]:
"""Parse simple YAML frontmatter (key: value and inline [arrays])."""
match = re.match(r'^---\s*\n(.*?)\n---\s*\n', content, re.DOTALL)
Expand Down Expand Up @@ -79,7 +102,7 @@ def is_article(frontmatter: Dict[str, Any], file_path: Path) -> bool:
return bool(frontmatter.get('title'))


def extract_article(file_path: Path, kb_dir: Path) -> Dict[str, Any]:
def extract_article(file_path: Path, kb_dir: Path, locale: str) -> Dict[str, Any]:
"""Extract a single article's index entry from its MDX file."""
content = file_path.read_text(encoding='utf-8')
frontmatter = parse_frontmatter(content)
Expand All @@ -92,20 +115,23 @@ def extract_article(file_path: Path, kb_dir: Path) -> Dict[str, Any]:
if isinstance(tags, str):
tags = [tags] if tags else []

category_labels = LOCALIZED_CATEGORY_LABELS.get(locale, CATEGORY_LABELS)
locale_prefix = '' if locale == 'en' else f'/{locale}'

return {
'id': article_id,
'title': frontmatter.get('title', ''),
'description': frontmatter.get('description', ''),
'href': '/resources/support-center/knowledge-base/' + article_id,
'category': CATEGORY_LABELS.get(
'href': locale_prefix + '/resources/support-center/knowledge-base/' + article_id,
'category': category_labels.get(
category_slug,
category_slug.replace('-', ' ').title()
),
'tags': tags,
}


def build_index(kb_dir: Path) -> Tuple[Dict[str, Any], int]:
def build_index(kb_dir: Path, locale: str = 'en') -> Tuple[Dict[str, Any], int]:
files = []
for file_path in kb_dir.glob('**/*.mdx'):
# Skip files in underscore-prefixed directories (assets/partials).
Expand All @@ -121,7 +147,7 @@ def build_index(kb_dir: Path) -> Tuple[Dict[str, Any], int]:
if not is_article(frontmatter, file_path):
skipped += 1
continue
articles.append(extract_article(file_path, kb_dir))
articles.append(extract_article(file_path, kb_dir, locale))

articles.sort(key=lambda a: a['title'].lower())

Expand All @@ -148,16 +174,28 @@ def render_module(index: Dict[str, Any]) -> str:


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'--locale',
default='en',
help="Locale to generate (default: en)",
)
args = parser.parse_args()

project_root = Path(__file__).resolve().parents[2]
kb_dir = project_root / 'resources' / 'support-center' / 'knowledge-base'
output_path = (project_root / 'snippets' / 'components' / 'KBExplorer'
/ 'kb-data.jsx')
locale = args.locale
locale_root = project_root if locale == 'en' else project_root / locale
kb_dir = locale_root / 'resources' / 'support-center' / 'knowledge-base'
snippets_root = project_root / 'snippets'
if locale != 'en':
snippets_root /= locale
output_path = snippets_root / 'components' / 'KBExplorer' / 'kb-data.jsx'

if not kb_dir.exists():
print(f"Error: knowledge-base directory not found: {kb_dir}")
return 1

index, skipped = build_index(kb_dir)
index, skipped = build_index(kb_dir, locale)
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(render_module(index), encoding='utf-8')

Expand All @@ -168,4 +206,4 @@ def main() -> int:


if __name__ == '__main__':
raise SystemExit(main())
raise SystemExit(main())
4 changes: 2 additions & 2 deletions ar/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="صورة خلفية للزينة." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="صورة خلفية للزينة." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex is imported from the generated kb-data.jsx; featuredArticles is hand-maintained */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions es/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="Imagen de fondo decorativa." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="Imagen de fondo decorativa." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex se importa desde el kb-data.jsx generado; featuredArticles se mantiene manualmente */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions fr/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="Image décorative d’arrière-plan." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="Image décorative d’arrière-plan." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex est importé depuis le fichier kb-data.jsx généré ; featuredArticles est maintenu manuellement */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions ja/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="装飾用の背景画像。" />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="装飾用の背景画像。" />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex は生成された kb-data.jsx からインポートされ、featuredArticles は手動で保守されています */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions ko/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="장식용 배경 이미지." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="장식용 배경 이미지." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex는 생성된 kb-data.jsx에서 가져오며, featuredArticles는 수동으로 관리합니다. */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions pt-BR/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="Imagem decorativa de fundo." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="Imagem decorativa de fundo." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex é importado do kb-data.jsx gerado; featuredArticles é mantido manualmente */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img
src="/images/background-light.svg"
className="block dark:hidden pointer-events-none w-full h-auto"
Expand All @@ -34,4 +34,4 @@ export const featuredArticles = [

{/* kbIndex is imported from the generated kb-data.jsx; featuredArticles is hand-maintained */}
<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
4 changes: 2 additions & 2 deletions ru/resources/support-center/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const featuredArticles = [
];

<div className="relative overflow-hidden">
<div className="absolute top-0 left-0 right-0 opacity-80">
<div className="absolute top-0 left-0 right-0 opacity-80 pointer-events-none">
<img src="/images/background-light.svg" className="block dark:hidden pointer-events-none w-full h-auto" alt="Декоративное фоновое изображение." />

<img src="/images/background-dark.svg" className="hidden dark:block pointer-events-none w-full h-auto" alt="Декоративное фоновое изображение." />
Expand All @@ -29,4 +29,4 @@ export const featuredArticles = [
{/* kbIndex импортируется из сгенерированного файла kb-data.jsx; featuredArticles поддерживается вручную */}

<KBExplorer index={kbIndex} featured={featuredArticles} />
</div>
</div>
6 changes: 3 additions & 3 deletions snippets/es/components/KBExplorer/KBExplorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const KBExplorer = ({ index, featured = [] }) => {
</svg>
)}
</span>
<span className="text-sm text-black dark:text-white">{option}</span>
<span className="text-sm text-black dark:text-white">{option === "All" ? "Todos" : option}</span>
</label>
))}
</div>
Expand Down Expand Up @@ -298,7 +298,7 @@ export const KBExplorer = ({ index, featured = [] }) => {
<div>
<div className="space-y-3">
<Expandable
label="Category"
label="Categoría"
options={categoryOptions}
selectedOptions={selectedCategories}
onToggle={toggleCategory}
Expand Down Expand Up @@ -396,4 +396,4 @@ export const KBExplorer = ({ index, featured = [] }) => {
</div>
</>
)
}
}
Loading
Loading