### 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 ` ${getWord(words, lang, "tor")} `; }; ``` -------------------------------- ### Generate HTML with Node.js Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Processes YAML lesson files and generates HTML pages with embedded Rust Playground iframes. ```javascript // generate.js - Core generation logic const showdown = require("showdown"); const fs = require("fs"); const yaml = require("js-yaml"); const lessonSource = process.argv[2]; // "lessons" or "wasm" const targetDir = process.argv[3]; // "docs" or "docs/webassembly" const generateBetaContent = process.argv[4] === "beta"; // Load YAML lessons const getYaml = (path) => yaml.load(fs.readFileSync(path)); // Get language directories const languages = fs.readdirSync(lessonSource, { withFileTypes: true }) .filter((dirent) => dirent.isDirectory()) .map((dirent) => dirent.name); // Load common words and chapters for each language languages.forEach((lang) => { const langDir = `${lessonSource}/${lang}`; commonWords[lang] = getYaml(`${langDir}/common_words.yaml`); // Load chapter files (chapter_0.yaml, chapter_1.yaml, etc.) }); // Generate HTML template with Rust Playground iframe function template(lessonsData, lang, title, code, content, index, isLast, words, isBeta) { return ` ${getWord(words, lang, "tor")} - Let's go on an adventure!

${title}

${content}
${code ? `
` : '
' }
`; } ``` -------------------------------- ### Define Lesson Structure in YAML Source: https://context7.com/richardanaya/tour_of_rust/llms.txt Defines the structure for lesson pages, including titles, markdown content, and links to interactive Rust Playground code. ```yaml # lessons/en/chapter_1.yaml - Example lesson structure - title: Variables code: >- https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20%2F%2F%20rust%20infers%20the%20type%20of%20x%0A%20%20%20%20let%20x%20%3D%2013%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%0A%20%20%20%20%2F%2F%20rust%20can%20also%20be%20explicit%20about%20the%20type%0A%20%20%20%20let%20x%3A%20f64%20%3D%203.14159%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A content_markdown: > Variables are declared using the **let** keyword. When assigning a value, Rust will be able to infer the type of your variable 99% of the time. Variable names are always in `snake_case`. - title: Chapter 1 - Conclusion content_markdown: > Nice job so far! The basics of Rust aren't so bad, right? Next up we'll be looking at `if` tests and `for` loops. ``` -------------------------------- ### Define a localized lesson chapter in YAML Source: https://github.com/richardanaya/tour_of_rust/blob/master/README.md Use this structure to define a new localized chapter. The code field should contain a URL generated from the Rust Playground. ```yaml - title: Capítulo 3 - Conclusión content_markdown: | ¡Rust tiene algunos increíbles ** punteros **! * A * `let` * C code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%7D%0A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.