mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-14 02:13:51 +00:00
Compare commits
No commits in common. "420994d26adc2d7c84f260e659d12cfb641002d1" and "15f2a4c650583fbae1d7fc0467c83405f88a4388" have entirely different histories.
420994d26a
...
15f2a4c650
Before Width: | Height: | Size: 434 KiB After Width: | Height: | Size: 434 KiB |
14
Makefile
14
Makefile
@ -2,19 +2,9 @@
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
#
|
||||
# MnBook: Mini Markdown Book
|
||||
# https://github.com/wa-lang/mnbook
|
||||
#
|
||||
# install mkbook
|
||||
|
||||
default:
|
||||
mnbook serve
|
||||
|
||||
build:
|
||||
-rm book
|
||||
mnbook build
|
||||
-rm book/.gitignore
|
||||
-rm -rf book/.git
|
||||
mdbook serve
|
||||
|
||||
clean:
|
||||
-rm -rf book
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -25,7 +25,19 @@ function playground_text(playground) {
|
||||
|
||||
var playgrounds = Array.from(document.querySelectorAll(".playground"));
|
||||
if (playgrounds.length > 0) {
|
||||
// ignore
|
||||
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
// get list of crates available in the rust playground
|
||||
let playground_crates = response.crates.map(item => item["id"]);
|
||||
playgrounds.forEach(block => handle_crate_list_update(block, playground_crates));
|
||||
});
|
||||
}
|
||||
|
||||
function handle_crate_list_update(playground_block, playground_crates) {
|
||||
@ -40,23 +52,21 @@ function playground_text(playground) {
|
||||
editor.addEventListener("change", function (e) {
|
||||
update_play_button(playground_block, playground_crates);
|
||||
});
|
||||
|
||||
// add Ctrl-Enter command to execute xxx code
|
||||
// add Ctrl-Enter command to execute rust code
|
||||
editor.commands.addCommand({
|
||||
name: "run",
|
||||
bindKey: {
|
||||
win: "Ctrl-Enter",
|
||||
mac: "Ctrl-Enter"
|
||||
},
|
||||
|
||||
exec: _editor => run_xxx_code(playground_block)
|
||||
exec: _editor => run_rust_code(playground_block)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updates the visibility of play button based on `no_run` class and
|
||||
// used crates vs ones available on http://play.xxx-lang.org
|
||||
// used crates vs ones available on http://play.rust-lang.org
|
||||
function update_play_button(pre_block, playground_crates) {
|
||||
var play_button = pre_block.querySelector(".play-button");
|
||||
|
||||
@ -66,11 +76,65 @@ function playground_text(playground) {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
// get list of `extern crate`'s from snippet
|
||||
var txt = playground_text(pre_block);
|
||||
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
|
||||
var snippet_crates = [];
|
||||
var item;
|
||||
while (item = re.exec(txt)) {
|
||||
snippet_crates.push(item[1]);
|
||||
}
|
||||
|
||||
// check if all used crates are available on play.rust-lang.org
|
||||
var all_available = snippet_crates.every(function (elem) {
|
||||
return playground_crates.indexOf(elem) > -1;
|
||||
});
|
||||
|
||||
if (all_available) {
|
||||
play_button.classList.remove("hidden");
|
||||
} else {
|
||||
play_button.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function run_xxx_code(code_block) {
|
||||
// todo
|
||||
function run_rust_code(code_block) {
|
||||
var result_block = code_block.querySelector(".result");
|
||||
if (!result_block) {
|
||||
result_block = document.createElement('code');
|
||||
result_block.className = 'result hljs language-bash';
|
||||
|
||||
code_block.append(result_block);
|
||||
}
|
||||
|
||||
let text = playground_text(code_block);
|
||||
let classes = code_block.querySelector('code').classList;
|
||||
let has_2018 = classes.contains("edition2018");
|
||||
let edition = has_2018 ? "2018" : "2015";
|
||||
|
||||
var params = {
|
||||
version: "stable",
|
||||
optimize: "0",
|
||||
code: text,
|
||||
edition: edition
|
||||
};
|
||||
|
||||
if (text.indexOf("#![feature") !== -1) {
|
||||
params.version = "nightly";
|
||||
}
|
||||
|
||||
result_block.innerText = "Running...";
|
||||
|
||||
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(params)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => result_block.innerText = response.result)
|
||||
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
||||
}
|
||||
|
||||
// Syntax highlighting Configuration
|
||||
@ -85,15 +149,14 @@ function playground_text(playground) {
|
||||
.filter(function (node) {return !node.parentElement.classList.contains("header"); });
|
||||
|
||||
if (window.ace) {
|
||||
// language-xxx class needs to be removed for editable
|
||||
// language-rust class needs to be removed for editable
|
||||
// blocks or highlightjs will capture events
|
||||
code_nodes
|
||||
.filter(function (node) {return node.classList.contains("editable"); })
|
||||
.forEach(function (block) { block.classList.remove('language-xxx'); });
|
||||
Array
|
||||
.from(document.querySelectorAll('code.editable'))
|
||||
.forEach(function (block) { block.classList.remove('language-rust'); });
|
||||
|
||||
Array
|
||||
code_nodes
|
||||
.filter(function (node) {return !node.classList.contains("editable"); })
|
||||
.from(document.querySelectorAll('code:not(.editable)'))
|
||||
.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
} else {
|
||||
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
@ -102,7 +165,8 @@ function playground_text(playground) {
|
||||
// Adding the hljs class gives code blocks the color css
|
||||
// even if highlighting doesn't apply
|
||||
code_nodes.forEach(function (block) { block.classList.add('hljs'); });
|
||||
Array.from(document.querySelectorAll("code.language-xxx")).forEach(function (block) {
|
||||
|
||||
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
|
||||
|
||||
var lines = Array.from(block.querySelectorAll('.boring'));
|
||||
// If no lines were hidden, return
|
||||
@ -176,7 +240,7 @@ function playground_text(playground) {
|
||||
|
||||
buttons.insertBefore(runCodeButton, buttons.firstChild);
|
||||
runCodeButton.addEventListener('click', function (e) {
|
||||
run_xxx_code(pre_block);
|
||||
run_rust_code(pre_block);
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
@ -232,7 +296,7 @@ function playground_text(playground) {
|
||||
|
||||
function get_theme() {
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mnbook-theme'); } catch (e) { }
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||
if (theme === null || theme === undefined) {
|
||||
return default_theme;
|
||||
} else {
|
||||
@ -274,7 +338,7 @@ function playground_text(playground) {
|
||||
var previousTheme = get_theme();
|
||||
|
||||
if (store) {
|
||||
try { localStorage.setItem('mnbook-theme', theme); } catch (e) { }
|
||||
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
|
||||
}
|
||||
|
||||
html.classList.remove(previousTheme);
|
||||
@ -295,14 +359,7 @@ function playground_text(playground) {
|
||||
});
|
||||
|
||||
themePopup.addEventListener('click', function (e) {
|
||||
var theme;
|
||||
if (e.target.className === "theme") {
|
||||
theme = e.target.id;
|
||||
} else if (e.target.parentElement.className === "theme") {
|
||||
theme = e.target.parentElement.id;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
var theme = e.target.id || e.target.parentElement.id;
|
||||
set_theme(theme);
|
||||
});
|
||||
|
||||
@ -313,7 +370,7 @@ function playground_text(playground) {
|
||||
}
|
||||
});
|
||||
|
||||
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mnbook/issues/628
|
||||
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
|
||||
document.addEventListener('click', function(e) {
|
||||
if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {
|
||||
hideThemes();
|
||||
@ -371,7 +428,7 @@ function playground_text(playground) {
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||
sidebar.setAttribute('aria-hidden', false);
|
||||
try { localStorage.setItem('mnbook-sidebar', 'visible'); } catch (e) { }
|
||||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||
}
|
||||
|
||||
|
||||
@ -393,7 +450,7 @@ function playground_text(playground) {
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||
sidebar.setAttribute('aria-hidden', true);
|
||||
try { localStorage.setItem('mnbook-sidebar', 'hidden'); } catch (e) { }
|
||||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
20
book.toml
Normal file
20
book.toml
Normal file
@ -0,0 +1,20 @@
|
||||
# https://giscus.app
|
||||
# https://github.com/badboy/mdbook-mermaid
|
||||
|
||||
[book]
|
||||
title = "Go语言圣经"
|
||||
authors = ["译者:", "chai2010", "Xargin", "CrazySssst", "foreversmart"]
|
||||
description = "<The Go Programming Language>中文版"
|
||||
language = "zh"
|
||||
multilingual = false
|
||||
src = "."
|
||||
|
||||
[build]
|
||||
build-dir = "book"
|
||||
|
||||
[output.html]
|
||||
additional-css = ["style.css"]
|
||||
additional-js = ["js/custom.js", "js/bigPicture.js"]
|
||||
git-repository-url = "https://github.com/gopl-zh/gopl-zh.github.com"
|
||||
edit-url-template = "https://github.com/gopl-zh/gopl-zh.github.com/edit/master/{path}"
|
||||
git-repository-icon = "fa-github"
|
594
ch1/ch1-01.html
594
ch1/ch1-01.html
File diff suppressed because one or more lines are too long
672
ch1/ch1-02.html
672
ch1/ch1-02.html
File diff suppressed because one or more lines are too long
776
ch1/ch1-03.html
776
ch1/ch1-03.html
File diff suppressed because one or more lines are too long
684
ch1/ch1-04.html
684
ch1/ch1-04.html
File diff suppressed because one or more lines are too long
562
ch1/ch1-05.html
562
ch1/ch1-05.html
File diff suppressed because one or more lines are too long
562
ch1/ch1-06.html
562
ch1/ch1-06.html
File diff suppressed because one or more lines are too long
754
ch1/ch1-07.html
754
ch1/ch1-07.html
File diff suppressed because one or more lines are too long
618
ch1/ch1-08.html
618
ch1/ch1-08.html
File diff suppressed because one or more lines are too long
560
ch1/ch1.html
560
ch1/ch1.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
562
ch10/ch10.html
562
ch10/ch10.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1310
ch11/ch11-02.html
1310
ch11/ch11-02.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
560
ch11/ch11.html
560
ch11/ch11.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
560
ch12/ch12.html
560
ch12/ch12.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
560
ch13/ch13.html
560
ch13/ch13.html
File diff suppressed because one or more lines are too long
590
ch2/ch2-01.html
590
ch2/ch2-01.html
File diff suppressed because one or more lines are too long
620
ch2/ch2-02.html
620
ch2/ch2-02.html
File diff suppressed because one or more lines are too long
816
ch2/ch2-03.html
816
ch2/ch2-03.html
File diff suppressed because one or more lines are too long
648
ch2/ch2-04.html
648
ch2/ch2-04.html
File diff suppressed because one or more lines are too long
634
ch2/ch2-05.html
634
ch2/ch2-05.html
File diff suppressed because one or more lines are too long
754
ch2/ch2-06.html
754
ch2/ch2-06.html
File diff suppressed because one or more lines are too long
718
ch2/ch2-07.html
718
ch2/ch2-07.html
File diff suppressed because one or more lines are too long
560
ch2/ch2.html
560
ch2/ch2.html
File diff suppressed because one or more lines are too long
704
ch3/ch3-01.html
704
ch3/ch3-01.html
File diff suppressed because one or more lines are too long
732
ch3/ch3-02.html
732
ch3/ch3-02.html
File diff suppressed because one or more lines are too long
670
ch3/ch3-03.html
670
ch3/ch3-03.html
File diff suppressed because one or more lines are too long
598
ch3/ch3-04.html
598
ch3/ch3-04.html
File diff suppressed because one or more lines are too long
906
ch3/ch3-05.html
906
ch3/ch3-05.html
File diff suppressed because one or more lines are too long
786
ch3/ch3-06.html
786
ch3/ch3-06.html
File diff suppressed because one or more lines are too long
560
ch3/ch3.html
560
ch3/ch3.html
File diff suppressed because one or more lines are too long
680
ch4/ch4-01.html
680
ch4/ch4-01.html
File diff suppressed because one or more lines are too long
894
ch4/ch4-02.html
894
ch4/ch4-02.html
File diff suppressed because one or more lines are too long
844
ch4/ch4-03.html
844
ch4/ch4-03.html
File diff suppressed because one or more lines are too long
930
ch4/ch4-04.html
930
ch4/ch4-04.html
File diff suppressed because one or more lines are too long
912
ch4/ch4-05.html
912
ch4/ch4-05.html
File diff suppressed because one or more lines are too long
738
ch4/ch4-06.html
738
ch4/ch4-06.html
File diff suppressed because one or more lines are too long
560
ch4/ch4.html
560
ch4/ch4.html
File diff suppressed because one or more lines are too long
602
ch5/ch5-01.html
602
ch5/ch5-01.html
File diff suppressed because one or more lines are too long
782
ch5/ch5-02.html
782
ch5/ch5-02.html
File diff suppressed because one or more lines are too long
684
ch5/ch5-03.html
684
ch5/ch5-03.html
File diff suppressed because one or more lines are too long
712
ch5/ch5-04.html
712
ch5/ch5-04.html
File diff suppressed because one or more lines are too long
710
ch5/ch5-05.html
710
ch5/ch5-05.html
File diff suppressed because one or more lines are too long
952
ch5/ch5-06.html
952
ch5/ch5-06.html
File diff suppressed because one or more lines are too long
614
ch5/ch5-07.html
614
ch5/ch5-07.html
File diff suppressed because one or more lines are too long
848
ch5/ch5-08.html
848
ch5/ch5-08.html
File diff suppressed because one or more lines are too long
704
ch5/ch5-09.html
704
ch5/ch5-09.html
File diff suppressed because one or more lines are too long
632
ch5/ch5-10.html
632
ch5/ch5-10.html
File diff suppressed because one or more lines are too long
560
ch5/ch5.html
560
ch5/ch5.html
File diff suppressed because one or more lines are too long
648
ch6/ch6-01.html
648
ch6/ch6-01.html
File diff suppressed because one or more lines are too long
698
ch6/ch6-02.html
698
ch6/ch6-02.html
File diff suppressed because one or more lines are too long
700
ch6/ch6-03.html
700
ch6/ch6-03.html
File diff suppressed because one or more lines are too long
664
ch6/ch6-04.html
664
ch6/ch6-04.html
File diff suppressed because one or more lines are too long
706
ch6/ch6-05.html
706
ch6/ch6-05.html
File diff suppressed because one or more lines are too long
636
ch6/ch6-06.html
636
ch6/ch6-06.html
File diff suppressed because one or more lines are too long
566
ch6/ch6.html
566
ch6/ch6.html
File diff suppressed because one or more lines are too long
562
ch7/ch7-01.html
562
ch7/ch7-01.html
File diff suppressed because one or more lines are too long
610
ch7/ch7-02.html
610
ch7/ch7-02.html
File diff suppressed because one or more lines are too long
694
ch7/ch7-03.html
694
ch7/ch7-03.html
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user