mirror of
https://github.com/MPSU/APS.git
synced 2026-05-25 11:39:26 +00:00
WIP: сборка английской версии mdbook
This commit is contained in:
4
.github/book.toml
vendored
4
.github/book.toml
vendored
@@ -1,10 +1,12 @@
|
|||||||
[book]
|
[book]
|
||||||
authors = ["Andrei Solodovnikov, Mikhail Popov"]
|
authors = ["Andrei Solodovnikov, Mikhail Popov"]
|
||||||
language = "ru"
|
language = "ru"
|
||||||
multilingual = true
|
|
||||||
src = "./"
|
src = "./"
|
||||||
title = "Архитектуры процессорных систем"
|
title = "Архитектуры процессорных систем"
|
||||||
|
|
||||||
[output.html]
|
[output.html]
|
||||||
git-repository-url = "https://github.com/MPSU/APS"
|
git-repository-url = "https://github.com/MPSU/APS"
|
||||||
git-repository-icon = "fa-github"
|
git-repository-icon = "fa-github"
|
||||||
|
site-url = "/APS/"
|
||||||
|
additional-js = ["theme/language-switcher.js"]
|
||||||
|
additional-css = ["theme/language-switcher.css"]
|
||||||
|
|||||||
12
.github/book_en.toml
vendored
Normal file
12
.github/book_en.toml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[book]
|
||||||
|
authors = ["Andrei Solodovnikov, Mikhail Popov"]
|
||||||
|
language = "en"
|
||||||
|
src = "./"
|
||||||
|
title = "Processor System Architectures"
|
||||||
|
|
||||||
|
[output.html]
|
||||||
|
git-repository-url = "https://github.com/MPSU/APS"
|
||||||
|
git-repository-icon = "fa-github"
|
||||||
|
site-url = "/APS/en/"
|
||||||
|
additional-js = ["theme/language-switcher.js"]
|
||||||
|
additional-css = ["theme/language-switcher.css"]
|
||||||
8
.github/prepare.sh
vendored
8
.github/prepare.sh
vendored
@@ -1,4 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
mkdir src
|
mkdir -p src
|
||||||
cp .github/book.toml .github/*.md ./
|
cp .github/book.toml .github/*.md ./
|
||||||
|
|
||||||
|
# Copy custom theme assets (language switcher, etc.)
|
||||||
|
if [ -d ".github/theme" ]; then
|
||||||
|
cp -r .github/theme ./
|
||||||
|
fi
|
||||||
|
|||||||
44
.github/theme/language-switcher.css
vendored
Normal file
44
.github/theme/language-switcher.css
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* ── Language Switcher ───────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
#language-switcher {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
background: none;
|
||||||
|
border: 1px solid var(--icons);
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--icons);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.82em;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1;
|
||||||
|
padding: 3px 8px;
|
||||||
|
|
||||||
|
/* sit nicely alongside the existing icon buttons */
|
||||||
|
margin-right: 4px;
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
|
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#language-switcher:hover,
|
||||||
|
#language-switcher:focus-visible {
|
||||||
|
color: var(--icons-hover);
|
||||||
|
border-color: var(--icons-hover);
|
||||||
|
background-color: rgba(128, 128, 128, 0.08);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep the flag emoji from being shrunk by the parent flex layout */
|
||||||
|
#language-switcher span[aria-hidden] {
|
||||||
|
font-size: 1.1em;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide text label on very small screens, show only flag */
|
||||||
|
@media (max-width: 420px) {
|
||||||
|
#language-switcher .lang-label {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
149
.github/theme/language-switcher.js
vendored
Normal file
149
.github/theme/language-switcher.js
vendored
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const STORAGE_KEY = "book-language";
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// Current language from URL
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function currentLang() {
|
||||||
|
return /\/en\//.test(window.location.pathname) ? "en" : "ru";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// Browser language
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function preferredLang() {
|
||||||
|
const langs = navigator.languages || [
|
||||||
|
navigator.language || "en",
|
||||||
|
];
|
||||||
|
|
||||||
|
const isRussian = langs.some((lang) =>
|
||||||
|
lang.toLowerCase().startsWith("ru")
|
||||||
|
);
|
||||||
|
|
||||||
|
return isRussian ? "ru" : "en";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// URL conversion
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function pathForLang(lang) {
|
||||||
|
const path = window.location.pathname;
|
||||||
|
|
||||||
|
if (lang === "en") {
|
||||||
|
if (/\/en\//.test(path)) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// /APS/foo → /APS/en/foo
|
||||||
|
return path.replace(/^(\/[^\/]+\/)/, "$1en/");
|
||||||
|
}
|
||||||
|
|
||||||
|
// lang === "ru"
|
||||||
|
|
||||||
|
// /APS/en/foo → /APS/foo
|
||||||
|
return path.replace("/en/", "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// Switch language manually
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function switchLanguage() {
|
||||||
|
const newLang = currentLang() === "ru" ? "en" : "ru";
|
||||||
|
|
||||||
|
// Save explicit user choice
|
||||||
|
localStorage.setItem(STORAGE_KEY, newLang);
|
||||||
|
|
||||||
|
window.location.href =
|
||||||
|
pathForLang(newLang) +
|
||||||
|
window.location.search +
|
||||||
|
window.location.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// Automatic language selection
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function autoSelectLanguage() {
|
||||||
|
const current = currentLang();
|
||||||
|
|
||||||
|
// 1. User preference has priority
|
||||||
|
let desired = localStorage.getItem(STORAGE_KEY);
|
||||||
|
|
||||||
|
// 2. Otherwise use browser language
|
||||||
|
if (!desired) {
|
||||||
|
desired = preferredLang();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already correct
|
||||||
|
if (desired === current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect
|
||||||
|
window.location.replace(
|
||||||
|
pathForLang(desired) +
|
||||||
|
window.location.search +
|
||||||
|
window.location.hash
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// UI
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function addSwitcher() {
|
||||||
|
const lang = currentLang();
|
||||||
|
|
||||||
|
const btn = document.createElement("button");
|
||||||
|
btn.id = "language-switcher";
|
||||||
|
|
||||||
|
btn.setAttribute(
|
||||||
|
"title",
|
||||||
|
lang === "ru"
|
||||||
|
? "Switch to English"
|
||||||
|
: "Переключить на русский"
|
||||||
|
);
|
||||||
|
|
||||||
|
btn.setAttribute("aria-label", btn.getAttribute("title"));
|
||||||
|
|
||||||
|
const icon = document.createElement("span");
|
||||||
|
icon.setAttribute("aria-hidden", "true");
|
||||||
|
icon.textContent = lang === "ru" ? "🇬🇧" : "🇷🇺";
|
||||||
|
|
||||||
|
const label = document.createElement("span");
|
||||||
|
label.className = "lang-label";
|
||||||
|
label.textContent = lang === "ru" ? "EN" : "RU";
|
||||||
|
|
||||||
|
btn.appendChild(icon);
|
||||||
|
btn.appendChild(label);
|
||||||
|
|
||||||
|
btn.addEventListener("click", switchLanguage);
|
||||||
|
|
||||||
|
const target = document.querySelector(".right-buttons");
|
||||||
|
|
||||||
|
if (target) {
|
||||||
|
target.insertBefore(btn, target.firstChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------
|
||||||
|
// Init
|
||||||
|
// ---------------------------------
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
autoSelectLanguage();
|
||||||
|
addSwitcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
} else {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
})();
|
||||||
79
.github/workflows/mdbook.yml
vendored
79
.github/workflows/mdbook.yml
vendored
@@ -1,55 +1,98 @@
|
|||||||
# Sample workflow for building and deploying a mdBook site to GitHub Pages
|
# Builds the Russian (master) and English (english_version) editions of the
|
||||||
|
# mdBook and deploys them as one GitHub Pages site:
|
||||||
#
|
#
|
||||||
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
|
# /APS/ ← Russian
|
||||||
|
# /APS/en/ ← English
|
||||||
#
|
#
|
||||||
name: Deploy mdBook site to Pages
|
name: Deploy mdBook site to Pages
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# Runs on pushes targeting the default branch
|
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches: ["master", "english_version"]
|
||||||
|
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pages: write
|
pages: write
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
|
||||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: "pages"
|
group: "pages"
|
||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build job
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
MDBOOK_VERSION: 0.4.36
|
MDBOOK_VERSION: 0.4.36
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# ── 1. Checkout master (Russian) ──────────────────────────────────────
|
||||||
|
- name: Checkout master (Russian)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
# checks out into $GITHUB_WORKSPACE (i.e. the working directory)
|
||||||
|
|
||||||
|
# ── 2. Install mdBook ─────────────────────────────────────────────────
|
||||||
- name: Install mdBook
|
- name: Install mdBook
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
|
source "$HOME/.cargo/env"
|
||||||
|
cargo install --version "${MDBOOK_VERSION}" mdbook
|
||||||
|
|
||||||
|
# ── 3. Build Russian version ──────────────────────────────────────────
|
||||||
|
- name: Prepare Russian sources
|
||||||
run: |
|
run: |
|
||||||
chmod +x .github/prepare.sh
|
chmod +x .github/prepare.sh
|
||||||
.github/prepare.sh
|
.github/prepare.sh
|
||||||
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
|
|
||||||
rustup update
|
- name: Build Russian (mdbook → ./book/)
|
||||||
cargo install --version ${MDBOOK_VERSION} mdbook
|
run: |
|
||||||
|
source "$HOME/.cargo/env"
|
||||||
|
mdbook build
|
||||||
|
|
||||||
|
# ── 4. Checkout English branch ────────────────────────────────────────
|
||||||
|
- name: Checkout english_version branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: english_version
|
||||||
|
path: english_src # checked out next to the working directory
|
||||||
|
|
||||||
|
# ── 5. Build English version ──────────────────────────────────────────
|
||||||
|
- name: Prepare English sources
|
||||||
|
run: |
|
||||||
|
cd english_src
|
||||||
|
|
||||||
|
chmod +x .github/prepare.sh
|
||||||
|
.github/prepare.sh
|
||||||
|
|
||||||
|
# Use the dedicated English book.toml (sets site-url = "/APS/en/")
|
||||||
|
cp .github/book_en.toml book.toml
|
||||||
|
|
||||||
|
# Copy language-switcher theme files from the master checkout
|
||||||
|
cp -r ../.github/theme ./theme
|
||||||
|
|
||||||
|
- name: Build English (mdbook → english_src/book/)
|
||||||
|
run: |
|
||||||
|
source "$HOME/.cargo/env"
|
||||||
|
cd english_src
|
||||||
|
mdbook build
|
||||||
|
|
||||||
|
# ── 6. Merge artifacts ────────────────────────────────────────────────
|
||||||
|
- name: Merge English build into Russian book/en/
|
||||||
|
run: |
|
||||||
|
mkdir -p book/en
|
||||||
|
cp -r english_src/book/. book/en/
|
||||||
|
|
||||||
|
# ── 7. Deploy ─────────────────────────────────────────────────────────
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
id: pages
|
id: pages
|
||||||
uses: actions/configure-pages@v5
|
uses: actions/configure-pages@v5
|
||||||
- name: Build with mdBook
|
|
||||||
run: mdbook build
|
- name: Upload Pages artifact
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
with:
|
with:
|
||||||
path: ./book
|
path: ./book
|
||||||
|
|
||||||
# Deployment job
|
|
||||||
deploy:
|
deploy:
|
||||||
environment:
|
environment:
|
||||||
name: github-pages
|
name: github-pages
|
||||||
|
|||||||
Reference in New Issue
Block a user