diff --git a/.gitignore b/.gitignore index bd3a7c8..f2f22ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -book +en/book +zh-CN/book .DS_Store diff --git a/assets/CNAME b/en/assets/CNAME similarity index 100% rename from assets/CNAME rename to en/assets/CNAME diff --git a/en/assets/custom.js b/en/assets/custom.js new file mode 100644 index 0000000..6fd7c44 --- /dev/null +++ b/en/assets/custom.js @@ -0,0 +1,104 @@ +(function() { + var path = window.location.pathname; + if (path.endsWith("/print.html")) { + return; + } + + var images = document.querySelectorAll("main img") + Array.prototype.forEach.call(images, function(img) { + img.addEventListener("click", function() { + BigPicture({ + el: img, + }); + }); + }); + + // Un-active everything when you click it + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.addEventHandler("click", function() { + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.classList.remove("active"); + }); + el.classList.add("active"); + }); + }); + + var updateFunction = function() { + + var id; + var elements = document.getElementsByClassName("header"); + Array.prototype.forEach.call(elements, function(el) { + if (window.pageYOffset >= el.offsetTop) { + id = el; + } + }); + + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.classList.remove("active"); + }); + + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + if (id.href.localeCompare(el.href) == 0) { + el.classList.add("active"); + } + }); + }; + + // Populate sidebar on load + window.addEventListener('load', function() { + var pagetoc = document.getElementsByClassName("pagetoc")[0]; + var elements = document.getElementsByClassName("header"); + Array.prototype.forEach.call(elements, function(el) { + var link = document.createElement("a"); + + // Indent shows hierarchy + var indent = ""; + switch (el.parentElement.tagName) { + case "H1": + return; + // case "H2": + // indent = "20px"; + // break; + case "H3": + indent = "20px"; + break; + case "H4": + indent = "40px"; + break; + default: + break; + } + + link.appendChild(document.createTextNode(el.text)); + link.style.paddingLeft = indent; + link.href = el.href; + pagetoc.appendChild(link); + }); + updateFunction.call(); + }); + + // Handle active elements on scroll + window.addEventListener("scroll", updateFunction); + + var p = path.replace("index.html", ""); + p = p.replace(".html", ""); + var strs = p.split("/"); + if (strs[strs.length-1] == ""){ + strs.pop() + } + var str = strs[strs.length-1]; + var title = document.querySelector("main>h1,h2>a").textContent + var gitalk = new Gitalk({ + clientID: '8e4b2cf9529ebb3dcad6', + clientSecret: '6f6e8c23575a780bdb1faba3c17be08d76dc35f8', + repo: 'rust-by-practice-comments', + owner: 'sunface', + admin: ["sunface"], + labels: ['comments'], + title: title, + createIssueManually: false, + id: str, + distractionFreeMode: true + }); + gitalk.render('gitalk-container'); +})(); \ No newline at end of file diff --git a/assets/logo.png b/en/assets/logo.png similarity index 100% rename from assets/logo.png rename to en/assets/logo.png diff --git a/assets/temp.md b/en/assets/temp.md similarity index 100% rename from assets/temp.md rename to en/assets/temp.md diff --git a/book.toml b/en/book.toml similarity index 83% rename from book.toml rename to en/book.toml index e3c28f5..ca1e7c6 100644 --- a/book.toml +++ b/en/book.toml @@ -13,6 +13,8 @@ enable = true level = 1 [output.html] +additional-css = ["theme/style2.css"] +additional-js = ["assets/custom.js"] git-repository-url = "https://github.com/sunface/rust-by-practice" edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/{path}" diff --git a/deploy.sh b/en/deploy.sh similarity index 95% rename from deploy.sh rename to en/deploy.sh index a5207e7..354505a 100755 --- a/deploy.sh +++ b/en/deploy.sh @@ -21,5 +21,5 @@ git remote add origin https://github.com/sunface/rust-by-practice git push -u -f origin gh-pages ## deploy zh-CN -cd ../zh-CN +cd ../../zh-book ./deploy \ No newline at end of file diff --git a/src/.gitignore b/en/src/.gitignore similarity index 100% rename from src/.gitignore rename to en/src/.gitignore diff --git a/src/SUMMARY.md b/en/src/SUMMARY.md similarity index 100% rename from src/SUMMARY.md rename to en/src/SUMMARY.md diff --git a/src/about.md b/en/src/about.md similarity index 100% rename from src/about.md rename to en/src/about.md diff --git a/src/async/async-await.md b/en/src/async/async-await.md similarity index 100% rename from src/async/async-await.md rename to en/src/async/async-await.md diff --git a/src/async/future.md b/en/src/async/future.md similarity index 100% rename from src/async/future.md rename to en/src/async/future.md diff --git a/src/async/intro.md b/en/src/async/intro.md similarity index 100% rename from src/async/intro.md rename to en/src/async/intro.md diff --git a/src/async/pin-unpin.md b/en/src/async/pin-unpin.md similarity index 100% rename from src/async/pin-unpin.md rename to en/src/async/pin-unpin.md diff --git a/src/async/stream.md b/en/src/async/stream.md similarity index 100% rename from src/async/stream.md rename to en/src/async/stream.md diff --git a/src/basic-types/char-bool-unit.md b/en/src/basic-types/char-bool-unit.md similarity index 100% rename from src/basic-types/char-bool-unit.md rename to en/src/basic-types/char-bool-unit.md diff --git a/src/basic-types/functions.md b/en/src/basic-types/functions.md similarity index 100% rename from src/basic-types/functions.md rename to en/src/basic-types/functions.md diff --git a/src/basic-types/intro.md b/en/src/basic-types/intro.md similarity index 100% rename from src/basic-types/intro.md rename to en/src/basic-types/intro.md diff --git a/src/basic-types/numbers.md b/en/src/basic-types/numbers.md similarity index 100% rename from src/basic-types/numbers.md rename to en/src/basic-types/numbers.md diff --git a/src/basic-types/statements-expressions.md b/en/src/basic-types/statements-expressions.md similarity index 100% rename from src/basic-types/statements-expressions.md rename to en/src/basic-types/statements-expressions.md diff --git a/src/circle-reference/intro.md b/en/src/circle-reference/intro.md similarity index 100% rename from src/circle-reference/intro.md rename to en/src/circle-reference/intro.md diff --git a/src/collections/hashmap.md b/en/src/collections/hashmap.md similarity index 100% rename from src/collections/hashmap.md rename to en/src/collections/hashmap.md diff --git a/src/collections/intro.md b/en/src/collections/intro.md similarity index 100% rename from src/collections/intro.md rename to en/src/collections/intro.md diff --git a/src/collections/string.md b/en/src/collections/string.md similarity index 100% rename from src/collections/string.md rename to en/src/collections/string.md diff --git a/src/collections/vector.md b/en/src/collections/vector.md similarity index 100% rename from src/collections/vector.md rename to en/src/collections/vector.md diff --git a/src/comments-docs.md b/en/src/comments-docs.md similarity index 100% rename from src/comments-docs.md rename to en/src/comments-docs.md diff --git a/src/compound-types/array.md b/en/src/compound-types/array.md similarity index 100% rename from src/compound-types/array.md rename to en/src/compound-types/array.md diff --git a/src/compound-types/enum.md b/en/src/compound-types/enum.md similarity index 100% rename from src/compound-types/enum.md rename to en/src/compound-types/enum.md diff --git a/src/compound-types/intro.md b/en/src/compound-types/intro.md similarity index 100% rename from src/compound-types/intro.md rename to en/src/compound-types/intro.md diff --git a/src/compound-types/slice.md b/en/src/compound-types/slice.md similarity index 100% rename from src/compound-types/slice.md rename to en/src/compound-types/slice.md diff --git a/src/compound-types/string.md b/en/src/compound-types/string.md similarity index 100% rename from src/compound-types/string.md rename to en/src/compound-types/string.md diff --git a/src/compound-types/struct.md b/en/src/compound-types/struct.md similarity index 100% rename from src/compound-types/struct.md rename to en/src/compound-types/struct.md diff --git a/src/compound-types/tuple.md b/en/src/compound-types/tuple.md similarity index 100% rename from src/compound-types/tuple.md rename to en/src/compound-types/tuple.md diff --git a/src/crate-module/crate.md b/en/src/crate-module/crate.md similarity index 100% rename from src/crate-module/crate.md rename to en/src/crate-module/crate.md diff --git a/src/crate-module/intro.md b/en/src/crate-module/intro.md similarity index 100% rename from src/crate-module/intro.md rename to en/src/crate-module/intro.md diff --git a/src/crate-module/module.md b/en/src/crate-module/module.md similarity index 100% rename from src/crate-module/module.md rename to en/src/crate-module/module.md diff --git a/src/crate-module/use-pub.md b/en/src/crate-module/use-pub.md similarity index 100% rename from src/crate-module/use-pub.md rename to en/src/crate-module/use-pub.md diff --git a/src/elegant-code-base.md b/en/src/elegant-code-base.md similarity index 100% rename from src/elegant-code-base.md rename to en/src/elegant-code-base.md diff --git a/src/errors.md b/en/src/errors.md similarity index 100% rename from src/errors.md rename to en/src/errors.md diff --git a/src/fight-compiler/borrowing.md b/en/src/fight-compiler/borrowing.md similarity index 100% rename from src/fight-compiler/borrowing.md rename to en/src/fight-compiler/borrowing.md diff --git a/src/fight-compiler/intro.md b/en/src/fight-compiler/intro.md similarity index 100% rename from src/fight-compiler/intro.md rename to en/src/fight-compiler/intro.md diff --git a/src/flow-control.md b/en/src/flow-control.md similarity index 100% rename from src/flow-control.md rename to en/src/flow-control.md diff --git a/src/formatted-output/debug-display.md b/en/src/formatted-output/debug-display.md similarity index 100% rename from src/formatted-output/debug-display.md rename to en/src/formatted-output/debug-display.md diff --git a/src/formatted-output/formatting.md b/en/src/formatted-output/formatting.md similarity index 100% rename from src/formatted-output/formatting.md rename to en/src/formatted-output/formatting.md diff --git a/src/formatted-output/intro.md b/en/src/formatted-output/intro.md similarity index 100% rename from src/formatted-output/intro.md rename to en/src/formatted-output/intro.md diff --git a/src/formatted-output/println.md b/en/src/formatted-output/println.md similarity index 100% rename from src/formatted-output/println.md rename to en/src/formatted-output/println.md diff --git a/src/functional-programing/cloure.md b/en/src/functional-programing/cloure.md similarity index 100% rename from src/functional-programing/cloure.md rename to en/src/functional-programing/cloure.md diff --git a/src/functional-programing/intro.md b/en/src/functional-programing/intro.md similarity index 100% rename from src/functional-programing/intro.md rename to en/src/functional-programing/intro.md diff --git a/src/functional-programing/iterator.md b/en/src/functional-programing/iterator.md similarity index 100% rename from src/functional-programing/iterator.md rename to en/src/functional-programing/iterator.md diff --git a/src/functional-programming/closure.md b/en/src/functional-programming/closure.md similarity index 100% rename from src/functional-programming/closure.md rename to en/src/functional-programming/closure.md diff --git a/src/functional-programming/intro.md b/en/src/functional-programming/intro.md similarity index 100% rename from src/functional-programming/intro.md rename to en/src/functional-programming/intro.md diff --git a/src/generics-traits/advanced-traits.md b/en/src/generics-traits/advanced-traits.md similarity index 100% rename from src/generics-traits/advanced-traits.md rename to en/src/generics-traits/advanced-traits.md diff --git a/src/generics-traits/const-generics.md b/en/src/generics-traits/const-generics.md similarity index 100% rename from src/generics-traits/const-generics.md rename to en/src/generics-traits/const-generics.md diff --git a/src/generics-traits/generics.md b/en/src/generics-traits/generics.md similarity index 100% rename from src/generics-traits/generics.md rename to en/src/generics-traits/generics.md diff --git a/src/generics-traits/intro.md b/en/src/generics-traits/intro.md similarity index 100% rename from src/generics-traits/intro.md rename to en/src/generics-traits/intro.md diff --git a/src/generics-traits/trait-object.md b/en/src/generics-traits/trait-object.md similarity index 100% rename from src/generics-traits/trait-object.md rename to en/src/generics-traits/trait-object.md diff --git a/src/generics-traits/traits.md b/en/src/generics-traits/traits.md similarity index 100% rename from src/generics-traits/traits.md rename to en/src/generics-traits/traits.md diff --git a/src/global-variables.md b/en/src/global-variables.md similarity index 100% rename from src/global-variables.md rename to en/src/global-variables.md diff --git a/src/lifetime/advance.md b/en/src/lifetime/advance.md similarity index 100% rename from src/lifetime/advance.md rename to en/src/lifetime/advance.md diff --git a/src/lifetime/basic.md b/en/src/lifetime/basic.md similarity index 100% rename from src/lifetime/basic.md rename to en/src/lifetime/basic.md diff --git a/src/lifetime/intro.md b/en/src/lifetime/intro.md similarity index 100% rename from src/lifetime/intro.md rename to en/src/lifetime/intro.md diff --git a/src/lifetime/static.md b/en/src/lifetime/static.md similarity index 100% rename from src/lifetime/static.md rename to en/src/lifetime/static.md diff --git a/src/macro.md b/en/src/macro.md similarity index 100% rename from src/macro.md rename to en/src/macro.md diff --git a/src/method.md b/en/src/method.md similarity index 100% rename from src/method.md rename to en/src/method.md diff --git a/src/newtype-sized.md b/en/src/newtype-sized.md similarity index 100% rename from src/newtype-sized.md rename to en/src/newtype-sized.md diff --git a/src/ownership/borrowing.md b/en/src/ownership/borrowing.md similarity index 100% rename from src/ownership/borrowing.md rename to en/src/ownership/borrowing.md diff --git a/src/ownership/intro.md b/en/src/ownership/intro.md similarity index 100% rename from src/ownership/intro.md rename to en/src/ownership/intro.md diff --git a/src/ownership/ownership.md b/en/src/ownership/ownership.md similarity index 100% rename from src/ownership/ownership.md rename to en/src/ownership/ownership.md diff --git a/src/pattern-match/intro.md b/en/src/pattern-match/intro.md similarity index 100% rename from src/pattern-match/intro.md rename to en/src/pattern-match/intro.md diff --git a/src/pattern-match/match-iflet.md b/en/src/pattern-match/match-iflet.md similarity index 100% rename from src/pattern-match/match-iflet.md rename to en/src/pattern-match/match-iflet.md diff --git a/src/pattern-match/patterns.md b/en/src/pattern-match/patterns.md similarity index 100% rename from src/pattern-match/patterns.md rename to en/src/pattern-match/patterns.md diff --git a/src/result-panic/intro.md b/en/src/result-panic/intro.md similarity index 100% rename from src/result-panic/intro.md rename to en/src/result-panic/intro.md diff --git a/src/result-panic/panic.md b/en/src/result-panic/panic.md similarity index 100% rename from src/result-panic/panic.md rename to en/src/result-panic/panic.md diff --git a/src/result-panic/result.md b/en/src/result-panic/result.md similarity index 100% rename from src/result-panic/result.md rename to en/src/result-panic/result.md diff --git a/src/self-referential.md b/en/src/self-referential.md similarity index 100% rename from src/self-referential.md rename to en/src/self-referential.md diff --git a/src/smart-pointers/box.md b/en/src/smart-pointers/box.md similarity index 100% rename from src/smart-pointers/box.md rename to en/src/smart-pointers/box.md diff --git a/src/smart-pointers/cell-refcell.md b/en/src/smart-pointers/cell-refcell.md similarity index 100% rename from src/smart-pointers/cell-refcell.md rename to en/src/smart-pointers/cell-refcell.md diff --git a/src/smart-pointers/deref.md b/en/src/smart-pointers/deref.md similarity index 100% rename from src/smart-pointers/deref.md rename to en/src/smart-pointers/deref.md diff --git a/src/smart-pointers/drop.md b/en/src/smart-pointers/drop.md similarity index 100% rename from src/smart-pointers/drop.md rename to en/src/smart-pointers/drop.md diff --git a/src/smart-pointers/intro.md b/en/src/smart-pointers/intro.md similarity index 100% rename from src/smart-pointers/intro.md rename to en/src/smart-pointers/intro.md diff --git a/src/smart-pointers/rc-arc.md b/en/src/smart-pointers/rc-arc.md similarity index 100% rename from src/smart-pointers/rc-arc.md rename to en/src/smart-pointers/rc-arc.md diff --git a/src/std/String.md b/en/src/std/String.md similarity index 100% rename from src/std/String.md rename to en/src/std/String.md diff --git a/src/std/intro.md b/en/src/std/intro.md similarity index 100% rename from src/std/intro.md rename to en/src/std/intro.md diff --git a/src/tests/assertions.md b/en/src/tests/assertions.md similarity index 100% rename from src/tests/assertions.md rename to en/src/tests/assertions.md diff --git a/src/tests/benchmark.md b/en/src/tests/benchmark.md similarity index 100% rename from src/tests/benchmark.md rename to en/src/tests/benchmark.md diff --git a/src/tests/intro.md b/en/src/tests/intro.md similarity index 100% rename from src/tests/intro.md rename to en/src/tests/intro.md diff --git a/src/tests/unit-integration.md b/en/src/tests/unit-integration.md similarity index 100% rename from src/tests/unit-integration.md rename to en/src/tests/unit-integration.md diff --git a/src/tests/write-tests.md b/en/src/tests/write-tests.md similarity index 100% rename from src/tests/write-tests.md rename to en/src/tests/write-tests.md diff --git a/src/threads/atomic.md b/en/src/threads/atomic.md similarity index 100% rename from src/threads/atomic.md rename to en/src/threads/atomic.md diff --git a/src/threads/basic-using.md b/en/src/threads/basic-using.md similarity index 100% rename from src/threads/basic-using.md rename to en/src/threads/basic-using.md diff --git a/src/threads/intro.md b/en/src/threads/intro.md similarity index 100% rename from src/threads/intro.md rename to en/src/threads/intro.md diff --git a/src/threads/message-passing.md b/en/src/threads/message-passing.md similarity index 100% rename from src/threads/message-passing.md rename to en/src/threads/message-passing.md diff --git a/src/threads/send-sync.md b/en/src/threads/send-sync.md similarity index 100% rename from src/threads/send-sync.md rename to en/src/threads/send-sync.md diff --git a/src/threads/sync.md b/en/src/threads/sync.md similarity index 100% rename from src/threads/sync.md rename to en/src/threads/sync.md diff --git a/src/type-conversions/as.md b/en/src/type-conversions/as.md similarity index 100% rename from src/type-conversions/as.md rename to en/src/type-conversions/as.md diff --git a/src/type-conversions/from-into.md b/en/src/type-conversions/from-into.md similarity index 100% rename from src/type-conversions/from-into.md rename to en/src/type-conversions/from-into.md diff --git a/src/type-conversions/intro.md b/en/src/type-conversions/intro.md similarity index 100% rename from src/type-conversions/intro.md rename to en/src/type-conversions/intro.md diff --git a/src/type-conversions/others.md b/en/src/type-conversions/others.md similarity index 100% rename from src/type-conversions/others.md rename to en/src/type-conversions/others.md diff --git a/src/unsafe/inline-asm.md b/en/src/unsafe/inline-asm.md similarity index 100% rename from src/unsafe/inline-asm.md rename to en/src/unsafe/inline-asm.md diff --git a/src/unsafe/intro.md b/en/src/unsafe/intro.md similarity index 100% rename from src/unsafe/intro.md rename to en/src/unsafe/intro.md diff --git a/src/variables.md b/en/src/variables.md similarity index 100% rename from src/variables.md rename to en/src/variables.md diff --git a/src/weak.md b/en/src/weak.md similarity index 100% rename from src/weak.md rename to en/src/weak.md diff --git a/src/why-exercise.md b/en/src/why-exercise.md similarity index 100% rename from src/why-exercise.md rename to en/src/why-exercise.md diff --git a/en/theme/index.hbs b/en/theme/index.hbs new file mode 100644 index 0000000..69134ba --- /dev/null +++ b/en/theme/index.hbs @@ -0,0 +1,318 @@ + + + + + + {{ title }} + {{#if is_print }} + + {{/if}} + {{#if base_url}} + + {{/if}} + + + + {{> head}} + + + + + + + {{#if favicon_svg}} + + {{/if}} + {{#if favicon_png}} + + {{/if}} + + + + {{#if print_enable}} + + {{/if}} + + + + {{#if copy_fonts}} + + {{/if}} + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + + + + + + + + + + + + + + + + + + + +
+ +
+ {{> header}} + + + + {{#if search_enabled}} + + {{/if}} + + + + +
+ +
+
+ {{{ content }}} +
+
+ + +
+
+ + + +
+ + {{#if livereload}} + + + {{/if}} + + {{#if google_analytics}} + + + {{/if}} + + {{#if playground_line_numbers}} + + {{/if}} + + {{#if playground_copyable}} + + {{/if}} + + {{#if playground_js}} + + + + + + {{/if}} + + {{#if search_js}} + + + + {{/if}} + + + + + + + {{#each additional_js}} + + {{/each}} + + {{#if is_print}} + {{#if mathjax_support}} + + {{else}} + + {{/if}} + {{/if}} + + + \ No newline at end of file diff --git a/en/theme/style2.css b/en/theme/style2.css new file mode 100644 index 0000000..16b7e03 --- /dev/null +++ b/en/theme/style2.css @@ -0,0 +1,53 @@ +@media only screen and (max-width:1080px) { + .sidetoc { + display: none !important; + } +} + +@media only screen and (min-width:1080px) { + main { + position: relative; + padding-right: 170px; + } + .sidetoc { + margin-left: auto; + margin-right: auto; + /*left: calc(100% + (var(--content-max-width))/4 - 180px);*/ + left: calc(100% - 200px); + position: absolute; + } + .pagetoc { + position: fixed; + width: 200px; + height: calc(100vh - var(--menu-bar-height) - 0.67em * 4); + overflow: auto; + } + .pagetoc a { + border-left: 1px solid var(--sidebar-bg); + color: var(--fg) !important; + display: block; + padding-bottom: 5px; + padding-top: 5px; + padding-left: 10px; + text-align: left; + text-decoration: none; + font-size: 1.2rem; + } + .pagetoc a:hover, + .pagetoc a.active { + background: var(--sidebar-bg); + color: var(--sidebar-fg) !important; + } + .pagetoc .active { + background: var(--sidebar-bg); + color: var(--sidebar-fg); + } +} + +.page-footer { + margin-top: 50px; + border-top: 1px solid #ccc; + overflow: hidden; + padding: 10px 0; + color: gray; +} \ No newline at end of file diff --git a/zh-CN/.DS_Store b/zh-CN/.DS_Store index d3603fd..bf66362 100644 Binary files a/zh-CN/.DS_Store and b/zh-CN/.DS_Store differ diff --git a/zh-CN/.gitignore b/zh-CN/.gitignore deleted file mode 100644 index 7585238..0000000 --- a/zh-CN/.gitignore +++ /dev/null @@ -1 +0,0 @@ -book diff --git a/zh-CN/assets/custom.js b/zh-CN/assets/custom.js new file mode 100644 index 0000000..6fd7c44 --- /dev/null +++ b/zh-CN/assets/custom.js @@ -0,0 +1,104 @@ +(function() { + var path = window.location.pathname; + if (path.endsWith("/print.html")) { + return; + } + + var images = document.querySelectorAll("main img") + Array.prototype.forEach.call(images, function(img) { + img.addEventListener("click", function() { + BigPicture({ + el: img, + }); + }); + }); + + // Un-active everything when you click it + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.addEventHandler("click", function() { + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.classList.remove("active"); + }); + el.classList.add("active"); + }); + }); + + var updateFunction = function() { + + var id; + var elements = document.getElementsByClassName("header"); + Array.prototype.forEach.call(elements, function(el) { + if (window.pageYOffset >= el.offsetTop) { + id = el; + } + }); + + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + el.classList.remove("active"); + }); + + Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) { + if (id.href.localeCompare(el.href) == 0) { + el.classList.add("active"); + } + }); + }; + + // Populate sidebar on load + window.addEventListener('load', function() { + var pagetoc = document.getElementsByClassName("pagetoc")[0]; + var elements = document.getElementsByClassName("header"); + Array.prototype.forEach.call(elements, function(el) { + var link = document.createElement("a"); + + // Indent shows hierarchy + var indent = ""; + switch (el.parentElement.tagName) { + case "H1": + return; + // case "H2": + // indent = "20px"; + // break; + case "H3": + indent = "20px"; + break; + case "H4": + indent = "40px"; + break; + default: + break; + } + + link.appendChild(document.createTextNode(el.text)); + link.style.paddingLeft = indent; + link.href = el.href; + pagetoc.appendChild(link); + }); + updateFunction.call(); + }); + + // Handle active elements on scroll + window.addEventListener("scroll", updateFunction); + + var p = path.replace("index.html", ""); + p = p.replace(".html", ""); + var strs = p.split("/"); + if (strs[strs.length-1] == ""){ + strs.pop() + } + var str = strs[strs.length-1]; + var title = document.querySelector("main>h1,h2>a").textContent + var gitalk = new Gitalk({ + clientID: '8e4b2cf9529ebb3dcad6', + clientSecret: '6f6e8c23575a780bdb1faba3c17be08d76dc35f8', + repo: 'rust-by-practice-comments', + owner: 'sunface', + admin: ["sunface"], + labels: ['comments'], + title: title, + createIssueManually: false, + id: str, + distractionFreeMode: true + }); + gitalk.render('gitalk-container'); +})(); \ No newline at end of file diff --git a/zh-CN/book.toml b/zh-CN/book.toml index f6c4e69..5b5b44c 100644 --- a/zh-CN/book.toml +++ b/zh-CN/book.toml @@ -1,6 +1,6 @@ [book] title = "Rust By Practice( Rust 练习实践 )" -description = "Practice Rust by example, exercise and hand-to-hand projects. Written with ❤️ by https://course.rs team" +description = "Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects." authors = ["sunface, https://im.dev"] language = "en" @@ -13,6 +13,8 @@ enable = true level = 1 [output.html] +additional-css = ["theme/style2.css"] +additional-js = ["assets/custom.js"] git-repository-url = "https://github.com/sunface/rust-by-practice" edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/zh-CN/{path}" diff --git a/zh-CN/theme/index.hbs b/zh-CN/theme/index.hbs new file mode 100644 index 0000000..69134ba --- /dev/null +++ b/zh-CN/theme/index.hbs @@ -0,0 +1,318 @@ + + + + + + {{ title }} + {{#if is_print }} + + {{/if}} + {{#if base_url}} + + {{/if}} + + + + {{> head}} + + + + + + + {{#if favicon_svg}} + + {{/if}} + {{#if favicon_png}} + + {{/if}} + + + + {{#if print_enable}} + + {{/if}} + + + + {{#if copy_fonts}} + + {{/if}} + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + + + + + + + + + + + + + + + + + + + +
+ +
+ {{> header}} + + + + {{#if search_enabled}} + + {{/if}} + + + + +
+ +
+
+ {{{ content }}} +
+
+ + +
+
+ + + +
+ + {{#if livereload}} + + + {{/if}} + + {{#if google_analytics}} + + + {{/if}} + + {{#if playground_line_numbers}} + + {{/if}} + + {{#if playground_copyable}} + + {{/if}} + + {{#if playground_js}} + + + + + + {{/if}} + + {{#if search_js}} + + + + {{/if}} + + + + + + + {{#each additional_js}} + + {{/each}} + + {{#if is_print}} + {{#if mathjax_support}} + + {{else}} + + {{/if}} + {{/if}} + + + \ No newline at end of file diff --git a/zh-CN/theme/style2.css b/zh-CN/theme/style2.css new file mode 100644 index 0000000..16b7e03 --- /dev/null +++ b/zh-CN/theme/style2.css @@ -0,0 +1,53 @@ +@media only screen and (max-width:1080px) { + .sidetoc { + display: none !important; + } +} + +@media only screen and (min-width:1080px) { + main { + position: relative; + padding-right: 170px; + } + .sidetoc { + margin-left: auto; + margin-right: auto; + /*left: calc(100% + (var(--content-max-width))/4 - 180px);*/ + left: calc(100% - 200px); + position: absolute; + } + .pagetoc { + position: fixed; + width: 200px; + height: calc(100vh - var(--menu-bar-height) - 0.67em * 4); + overflow: auto; + } + .pagetoc a { + border-left: 1px solid var(--sidebar-bg); + color: var(--fg) !important; + display: block; + padding-bottom: 5px; + padding-top: 5px; + padding-left: 10px; + text-align: left; + text-decoration: none; + font-size: 1.2rem; + } + .pagetoc a:hover, + .pagetoc a.active { + background: var(--sidebar-bg); + color: var(--sidebar-fg) !important; + } + .pagetoc .active { + background: var(--sidebar-bg); + color: var(--sidebar-fg); + } +} + +.page-footer { + margin-top: 50px; + border-top: 1px solid #ccc; + overflow: hidden; + padding: 10px 0; + color: gray; +} \ No newline at end of file