Skip to content

Commit f5241a4

Browse files
committed
配置 mdbook
1 parent 027c388 commit f5241a4

File tree

11 files changed

+621
-85
lines changed

11 files changed

+621
-85
lines changed

.github/workflows/main.yml

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
name: 'Gitbook Action Build'
2-
on:
3-
push:
4-
branches:
5-
- master # trigger branch
1+
name: build-and-deploy
2+
on: push
63
jobs:
7-
build:
8-
runs-on: ubuntu-latest
4+
deploy:
5+
runs-on: ubuntu-18.04
96
steps:
10-
- name: Checkout action
11-
uses: actions/checkout@v2
12-
# - name: Gitbook Action # https://github.com/ZanderZhao/gitbook-action/releases
13-
# uses: ZanderZhao/[email protected] # -> or ZanderZhao/gitbook-action@master. If not use master click above, use latest please
14-
# with: # or fork this repo and use YourName/gitbook-action@master
15-
# token: ${{ secrets.PERSONAL_TOKEN }} # -> remember add this in settings/secrets as following
16-
# publish_branch: gh-pages
17-
# time_zone: Asia/Shanghai
7+
- name: Git checkout
8+
uses: actions/checkout@v2
9+
10+
- name: Setup mdBook
11+
uses: peaceiris/actions-mdbook@v1
12+
with:
13+
mdbook-version: '0.4.10'
14+
# mdbook-version: 'latest'
15+
16+
# - run: mdbook build
17+
18+
# TODO: set GITHUB_TOKEN_DEPLOY_KEY
19+
#- name: Deploy
20+
# uses: peaceiris/actions-gh-pages@v3
21+
# with:
22+
# deploy_key: ${{ secrets.GITHUB_TOKEN_DEPLOY_KEY }}
23+
# external_repository: KusionStack/kusionstack.github.io
24+
# publish_dir: ./_build
25+
# publish_branch: gh-pages
26+
# user_name: 'github-actions[bot]'
27+
# user_email: 'github-actions[bot]@users.noreply.github.com'

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414

1515
default:
16-
gitbook build
16+
mdbook build
1717

1818
macos:
1919
gitbook build --gitbook=3.2.3

SUMMARY.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# 目录
22

3+
[Go语言定制指南](index.md)
4+
[前言](preface.md)
5+
36
* [第1章 语言基础](ch1-basic/readme.md)
7+
8+
<!--
49
* [1.1 Go语言创世纪](ch1-basic/ch1-01-genesis.md)
510
* [1.2 Hello, World 的革命](ch1-basic/ch1-02-hello-revolution.md)
611
* [1.3 数组、字符串和切片](ch1-basic/ch1-03-array-string-and-slice.md)
@@ -66,3 +71,4 @@
6671
* [附录A: Go语言常见坑](appendix/appendix-a-trap.md)
6772
* [附录B: 有趣的代码片段](appendix/appendix-b-gems.md)
6873
* [附录C: 作者简介](appendix/appendix-c-author.md)
74+
-->

book.json

-20
This file was deleted.

book.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://giscus.app
2+
3+
[book]
4+
title = "Go语言高级编程"
5+
authors = ["柴树杉", "曹春晖"]
6+
description = "Go语言高级编程"
7+
language = "zh"
8+
multilingual = false
9+
src = "."
10+
11+
[build]
12+
build-dir = "book"
13+
14+
[output.html]
15+
additional-css = ["style.css"]
16+
additional-js = ["js/custom.js", "js/bigPicture.js"]
17+
git-repository-url = "https://github.com/chai2010/advanced-go-programming-book"
18+
edit-url-template = "https://github.com/chai2010/advanced-go-programming-book/edit/master/{path}"
19+
git-repository-icon = "fa-github"

index.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Go语言高级编程(Advanced Go Programming)
2+
3+
本书涵盖CGO、Go汇编语言、RPC实现、Web框架实现、分布式系统等高阶主题,针对Go语言有一定经验想深入了解Go语言各种高级用法的开发人员。对于刚学习Go语言的读者,建议先从[《Go语言圣经》](https://github.com/golang-china/gopl-zh)开始系统学习Go语言的基础知识。如果希望了解Go2的最新动向,可以参考[《Go2编程指南》](https://github.com/chai2010/go2-book)
4+
5+
![](cover-20190714.jpg)
6+
7+
- 作者:柴树杉,Github [@chai2010](https://github.com/chai2010),Twitter [@chaishushan](https://twitter.com/chaishushan)
8+
- 作者:曹春晖,Github [@cch123](https://github.com/cch123)
9+
- 网址:https://github.com/chai2010/advanced-go-programming-book
10+
11+
购买链接:
12+
13+
- 京东:https://item.m.jd.com/product/12647494.html
14+
- 异步:https://www.epubit.com/book/detail/40090
15+
16+
如果你喜欢本书,欢迎到豆瓣评论:
17+
18+
[![](douban.png)](https://book.douban.com/subject/34442131/)
19+
20+
- https://book.douban.com/subject/34442131/
21+
22+
23+
## 在线阅读
24+
25+
- https://chai2010.cn/advanced-go-programming-book/
26+
- https://www.gitbook.com/book/chai2010/advanced-go-programming-book/
27+
28+
29+
## 关注微信公众号 (guanggu-coder)
30+
31+
![](weixin-guanggu-coder-logo.png)
32+
33+
34+
## 网易云课堂·光谷码农课堂
35+
36+
https://study.163.com/provider/480000001914454/index.htm
37+
38+
![](163study-go-master.jpg)
39+
40+
## 版权声明
41+
42+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Go语言高级编程</span> 由 <a xmlns:cc="http://creativecommons.org/ns#" href="https://github.com/chai2010/advanced-go-programming-book" property="cc:attributionName" rel="cc:attributionURL">柴树杉,曹春晖</a> 采用 <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享 署名-非商业性使用-禁止演绎 4.0 国际 许可协议</a>进行许可。
43+
44+
严禁任何商业行为使用或引用该文档的全部或部分内容!
45+
46+
欢迎大家提供建议!

js/bigPicture.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/custom.js

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// https://giscus.app
2+
3+
const data_repo = "chai2010/advanced-go-programming-book";
4+
const data_repo_id = "MDEwOlJlcG9zaXRvcnkxMTU4NTc5NTQ=";
5+
const data_category = "General";
6+
const data_category_id = "DIC_kwDOBufaIs4CAwFi";
7+
8+
var initAll = function () {
9+
var path = window.location.pathname;
10+
if (path.endsWith("/print.html")) {
11+
return;
12+
}
13+
14+
var images = document.querySelectorAll("main img")
15+
Array.prototype.forEach.call(images, function (img) {
16+
img.addEventListener("click", function () {
17+
BigPicture({
18+
el: img,
19+
});
20+
});
21+
});
22+
23+
// Un-active everything when you click it
24+
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
25+
el.addEventHandler("click", function () {
26+
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
27+
el.classList.remove("active");
28+
});
29+
el.classList.add("active");
30+
});
31+
});
32+
33+
var updateFunction = function () {
34+
var id = null;
35+
var elements = document.getElementsByClassName("header");
36+
Array.prototype.forEach.call(elements, function (el) {
37+
if (window.pageYOffset >= el.offsetTop) {
38+
id = el;
39+
}
40+
});
41+
42+
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
43+
el.classList.remove("active");
44+
});
45+
46+
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
47+
if (id == null) {
48+
return;
49+
}
50+
if (id.href.localeCompare(el.href) == 0) {
51+
el.classList.add("active");
52+
}
53+
});
54+
};
55+
56+
var pagetoc = document.getElementsByClassName("pagetoc")[0];
57+
var elements = document.getElementsByClassName("header");
58+
Array.prototype.forEach.call(elements, function (el) {
59+
var link = document.createElement("a");
60+
61+
// Indent shows hierarchy
62+
var indent = "";
63+
switch (el.parentElement.tagName) {
64+
case "H1":
65+
return;
66+
case "H3":
67+
indent = "20px";
68+
break;
69+
case "H4":
70+
indent = "40px";
71+
break;
72+
default:
73+
break;
74+
}
75+
76+
link.appendChild(document.createTextNode(el.text));
77+
link.style.paddingLeft = indent;
78+
link.href = el.href;
79+
pagetoc.appendChild(link);
80+
});
81+
updateFunction.call();
82+
83+
// Handle active elements on scroll
84+
window.addEventListener("scroll", updateFunction);
85+
86+
document.getElementById("theme-list").addEventListener("click", function (e) {
87+
var iframe = document.querySelector('.giscus-frame');
88+
if (!iframe) return;
89+
var theme;
90+
if (e.target.className === "theme") {
91+
theme = e.target.id;
92+
} else {
93+
return;
94+
}
95+
96+
// 若当前 mdbook 主题不是 Light 或 Rust ,则将 giscuz 主题设置为 transparent_dark
97+
var giscusTheme = "light"
98+
if (theme != "light" && theme != "rust") {
99+
giscusTheme = "transparent_dark";
100+
}
101+
102+
var msg = {
103+
setConfig: {
104+
theme: giscusTheme
105+
}
106+
};
107+
iframe.contentWindow.postMessage({ giscus: msg }, 'https://giscus.app');
108+
});
109+
110+
pagePath = pagePath.replace("index.md", "");
111+
pagePath = pagePath.replace(".md", "");
112+
if (pagePath.length > 0) {
113+
if (pagePath.charAt(pagePath.length-1) == "/"){
114+
pagePath = pagePath.substring(0, pagePath.length-1);
115+
}
116+
}else {
117+
pagePath = "index";
118+
}
119+
120+
var giscusTheme = "light";
121+
const themeClass = document.getElementsByTagName("html")[0].className;
122+
if (themeClass.indexOf("light") == -1 && themeClass.indexOf("rust") == -1) {
123+
giscusTheme = "transparent_dark";
124+
}
125+
126+
var script = document.createElement("script");
127+
script.type = "text/javascript";
128+
script.src = "https://giscus.app/client.js";
129+
script.async = true;
130+
script.crossOrigin = "anonymous";
131+
script.setAttribute("data-repo", data_repo);
132+
script.setAttribute("data-repo-id", data_repo_id);
133+
script.setAttribute("data-category", data_category);
134+
script.setAttribute("data-category-id", data_category_id);
135+
script.setAttribute("data-mapping", "specific");
136+
script.setAttribute("data-term", pagePath);
137+
script.setAttribute("data-reactions-enabled", "1");
138+
script.setAttribute("data-emit-metadata", "0");
139+
script.setAttribute("data-input-position", "top");
140+
script.setAttribute("data-theme", giscusTheme);
141+
script.setAttribute("data-lang", "zh-CN");
142+
script.setAttribute("data-loading", "lazy");
143+
document.getElementById("giscus-container").appendChild(script);
144+
};
145+
146+
window.addEventListener('load', initAll);

0 commit comments

Comments
 (0)