From 16d9531fc2360d0f3e7abc81b0753ce81fbf9960 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Tue, 5 Jan 2016 15:40:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20addlinks=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 3 +++ addlinks.go | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8b28164..49f599c 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,9 @@ review: gitbook build go run zh2tw.go . .md$$ zh2tw +fixlink: + go run addlinks.go . .md$$ + cover: composite cover_patch.png cover_bgd.png cover.jpg convert -resize 1800x2360! cover.jpg cover.jpg diff --git a/addlinks.go b/addlinks.go index 061dd91..3c2a728 100644 --- a/addlinks.go +++ b/addlinks.go @@ -117,14 +117,52 @@ func convertFile(path string) (changed bool) { } var _RegexpLinksTable = func() map[*regexp.Regexp]string { + const ( + reHttp = `(https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])?` + reWikiTail = `(\([-A-Za-z0-9+~_]+\))?` + ) + m := make(map[*regexp.Regexp]string) for k, v := range _LinkTable { - reKey := regexp.MustCompile(regexp.QuoteMeta(`[`+k+`]`) + `\(\S*\)`) + reKey := regexp.MustCompile(regexp.QuoteMeta(`[`+k+`]`) + `\(` + reHttp + reWikiTail + `\)`) m[reKey] = fmt.Sprintf("[%s](%s)", k, v) } return m }() var _LinkTable = map[string]string{ + + // 人名 "Alan A. A. Donovan": "https://github.com/adonovan", + "Brian W. Kernighan": "http://www.cs.princeton.edu/~bwk/", + "Robert Griesemer": "http://research.google.com/pubs/author96.html", + "Rob Pike": "http://genius.cat-v.org/rob-pike/", + "Ken Thompson": "http://genius.cat-v.org/ken-thompson/", + + // 图书 + "The C Programming Language": "http://s3-us-west-2.amazonaws.com/belllabs-microsite-dritchie/cbook/index.html", + "The Practice of Programming": "https://en.wikipedia.org/wiki/The_Practice_of_Programming", + + // Go语言 + "Go": "https://golang.org/", + "Google’s Go": "https://golang.org/", + "oracle": "https://godoc.org/golang.org/x/tools/oracle", + "godoc -analysis": "https://godoc.org/golang.org/x/tools/cmd/godoc", + "gorename": "https://godoc.org/golang.org/x/tools/cmd/gorename", + + // 其他语言 + + // 系统 + "Unix": "http://doc.cat-v.org/unix/", + "UNIX": "http://doc.cat-v.org/unix/", + "Linux": "http://www.linux.org/", + "FreeBSD": "https://www.freebsd.org/", + "OpenBSD": "http://www.openbsd.org/", + "Mac OSX": "http://www.apple.com/cn/osx/", + "Mac OS X": "http://www.apple.com/cn/osx/", + "Plan9": "http://plan9.bell-labs.com/plan9/", + "Microsoft Windows": "https://www.microsoft.com/zh-cn/windows/", + + // 其他 + "Bell Labs": "http://www.cs.bell-labs.com/", }