### Lesson YAML Structure Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Define lesson content using YAML files. Code examples are provided as URL-encoded Rust Playground links. ```yaml # lessons/es/chapter_1.yaml - Spanish translation example - title: Capítulo 1 - Los Fundamentos content_markdown: > En este primer capítulo vamos a explorar los fundamentos básicos con funciones, variables y los tipos más primitivos. - title: Variables code: >- https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%2013%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A content_markdown: > Las variables se declaran usando la palabra clave **let**. Los nombres de variables siempre usan `snake_case`. # lessons/es/common_words.yaml - Spanish common words chapter: Capítulo tor: Tour de Rust next: Siguiente previous: Anterior toc: Tabla de Contenidos lessons: Lecciones untranslated: Sin traducir ``` ```yaml # lessons/zh-tw/chapter_1.yaml - Cloning from simplified Chinese - title: 變數 clone: zh-cn # Reuse content from zh-cn (Simplified Chinese) code: >- # Optional: provide Traditional Chinese specific code example https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=... ``` ```yaml # Lesson with embedded Rust Playground code - title: Functions code: >- https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20add(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20return%20x%20%2B%20y%3B%0A%7D%0A%0Afn%20subtract(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20x%20-%20y%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%2242%20%2B%2013%20%3D%20%7B%7D%22%2C%20add(42%2C%2013))%3B%0A%20%20%20%20println!(%2242%20-%2013%20%3D%20%7B%7D%22%2C%20subtract(42%2C%2013))%3B%0A%7D%0A content_markdown: > A function has zero or more parameters. Function names are always in `snake_case`. ``` -------------------------------- ### Build and Serve Tutorial via Makefile Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Provides commands for building, testing, and deploying the static site. ```bash # Using Makefile make serve # Build with beta content and start local server on port 8080 make test # Build without beta content and start local server make publish # Build and deploy to gh-pages branch make clean # Remove generated HTML files ``` -------------------------------- ### Define Project Dependencies Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Required npm packages for building the tutorial site. ```json { "dependencies": { "js-yaml": "4.1.0", "showdown": "^1.9.1" }, "devDependencies": { "eslint": "^7.26.0", "nodemon": "^2.0.20", "prettier": "^2.2.1", "rimraf": "^3.0.2" } } ``` -------------------------------- ### Project Build and Development Scripts Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Use these npm scripts to manage the build process, serve the documentation locally, and maintain code quality. ```bash npm run build # Generate HTML: node generate.js lessons docs beta && node generate.js wasm docs/webassembly beta npm run serve # Build and serve: npm run build && cd docs && python -m http.server 8080 npm run watch # Auto-rebuild: nodemon -w lessons/**/* -w wasm/**/* -e yaml --exec npm run serve npm run lint # Format YAML and JS: prettier --write ./lessons/*/*.yaml && eslint --fix generate.js npm run lint:lessons # Format lesson YAML only npm run lint:webassembly # Format wasm lesson YAML only ``` -------------------------------- ### Configure Localization in YAML Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Defines common UI strings for localization within the tutorial interface. ```yaml # lessons/en/common_words.yaml - English localization chapter: Chapter tor: Tour of Rust next: Next previous: Previous toc: Table of Contents lessons: Lessons untranslated: Untranslated welcometothe: Welcome to the presstocontinue: Press to Continue ``` -------------------------------- ### Frontend JavaScript Utilities Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Handles keyboard navigation and RTL language layout detection. ```javascript // docs/tour.js - Keyboard navigation handler const setupKeys = () => { document.body.addEventListener('keyup', (e) => { if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey) { return; // Ignore modified key presses } let link; if (e.key === 'Right' || e.key === 'ArrowRight') { link = document.querySelector('.next a'); // Navigate to next lesson } if (e.key === 'Left' || e.key === 'ArrowLeft') { link = document.querySelector('.back a'); // Navigate to previous lesson } if (link) { link.click(); } }); }; // Setup keyboard navigation on page load and iframe load const iframeElement = document.querySelector('iframe'); if (iframeElement) { setupKeys(); iframeElement.addEventListener('load', () => { setTimeout(() => { document.querySelector('a').focus(); setupKeys(); }, 100); }); } else { setupKeys(); } ``` ```javascript // generate.js - RTL language detection const getHead = (words, lang) => { let rtl_langs = ["ar"]; // Arabic requires RTL layout let lang_dir = rtl_langs.includes(lang) ? "rtl" : "ltr"; return `
