├── .DS_Store
├── .gitattributes
├── .gitignore
├── LICENSE
├── LICENSE.md
├── converter
├── converter.go
└── util.go
├── effect.png
├── example
├── .DS_Store
└── gogs_zh
│ ├── .DS_Store
│ ├── 07fbf67d05c29c0bca39917e2baee1b0.png
│ ├── 538.html
│ ├── 539.html
│ ├── 540.html
│ ├── 542.html
│ ├── 543.html
│ ├── 544.html
│ ├── 545.html
│ ├── 546.html
│ ├── 547.html
│ ├── 548.html
│ ├── 549.html
│ ├── 550.html
│ ├── 551.html
│ ├── 552.html
│ ├── 553.html
│ ├── 554.html
│ ├── 555.html
│ ├── 556.html
│ ├── 557.html
│ ├── 558.html
│ ├── 559.html
│ ├── 560.html
│ ├── 8b35028d0518c77d8308ff3dd97e97a0.png
│ ├── 99327ac61c6444a0839c551d6fd06e5f.gif
│ ├── a16e019f33ab5660b83b52f2ee5c8a24.png
│ ├── a97fed77a57e0e7788343c4674bb4c45.png
│ ├── config.json
│ ├── d4643fd6157facd3f4178141fb4ab85d.png
│ ├── d92fc8f1c8954dda582909a8d37bc6c6.png
│ ├── e00b4e8899e00091e6ac46d230d53c2f.png
│ ├── editormd.css
│ ├── output
│ ├── book.epub
│ ├── book.mobi
│ └── book.pdf
│ └── statement.html
├── go.mod
├── go.sum
├── main.go
└── readme.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/.DS_Store
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.js linguist-language=go
2 | *.css linguist-language=go
3 | *.html linguist-language=go
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Go template
3 | # Binaries for programs and plugins
4 | #*.exe
5 | *.dll
6 | *.so
7 | *.dylib
8 |
9 | # Test binary, build with `go test -c`
10 | *.test
11 |
12 | # Output of the go coverage tool, specifically when used with LiteIDE
13 | *.out
14 |
15 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
16 | .glide/
17 | ### JetBrains template
18 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
19 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
20 |
21 | # User-specific stuff:
22 | .idea/**/workspace.xml
23 | .idea/**/tasks.xml
24 | .idea/dictionaries
25 |
26 | # Sensitive or high-churn files:
27 | .idea/**/dataSources/
28 | .idea/**/dataSources.ids
29 | .idea/**/dataSources.xml
30 | .idea/**/dataSources.local.xml
31 | .idea/**/sqlDataSources.xml
32 | .idea/**/dynamic.xml
33 | .idea/**/uiDesigner.xml
34 |
35 | # Gradle:
36 | .idea/**/gradle.xml
37 | .idea/**/libraries
38 |
39 | # CMake
40 | cmake-build-debug/
41 |
42 | # Mongo Explorer plugin:
43 | .idea/**/mongoSettings.xml
44 |
45 | ## File-based project format:
46 | *.iws
47 |
48 | ## Plugin-specific files:
49 |
50 | # IntelliJ
51 | out/
52 |
53 | # mpeltonen/sbt-idea plugin
54 | .idea_modules/
55 |
56 | # JIRA plugin
57 | atlassian-ide-plugin.xml
58 |
59 | # Cursive Clojure plugin
60 | .idea/replstate.xml
61 |
62 | # Crashlytics plugin (for Android Studio and IntelliJ)
63 | com_crashlytics_export_strings.xml
64 | crashlytics.properties
65 | crashlytics-build.properties
66 | fabric.properties
67 | ### Windows template
68 | # Windows thumbnail cache files
69 | Thumbs.db
70 | ehthumbs.db
71 | ehthumbs_vista.db
72 |
73 | # Dump file
74 | *.stackdump
75 |
76 | # Folder config file
77 | [Dd]esktop.ini
78 |
79 | # Recycle Bin used on file shares
80 | $RECYCLE.BIN/
81 |
82 | # Windows Installer files
83 | *.cab
84 | *.msi
85 | *.msm
86 | *.msp
87 |
88 | # Windows shortcuts
89 | *.lnk
90 |
91 | .gitignore
92 | .idea/
93 | #example/gogs_zh/output
94 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/converter/converter.go:
--------------------------------------------------------------------------------
1 | // Author:TruthHun
2 | // Email:TruthHun@QQ.COM
3 | // Date:2018-01-21
4 | package converter
5 |
6 | import (
7 | "bytes"
8 | "fmt"
9 | "io/ioutil"
10 | "os"
11 | "path/filepath"
12 | "strings"
13 |
14 | "time"
15 |
16 | "os/exec"
17 |
18 | "errors"
19 |
20 | "github.com/TruthHun/gotil/cryptil"
21 | "github.com/TruthHun/gotil/filetil"
22 | "github.com/TruthHun/gotil/ziptil"
23 | )
24 |
25 | type Converter struct {
26 | BasePath string
27 | Config Config
28 | Debug bool
29 | GeneratedCover string
30 | Callback func(identifier, ebookPath string, err error) // 每本电子书生成后的回调
31 | }
32 |
33 | // 目录结构
34 | type Toc struct {
35 | Id int `json:"id"`
36 | Link string `json:"link"`
37 | Pid int `json:"pid"`
38 | Title string `json:"title"`
39 | }
40 |
41 | // config.json文件解析结构
42 | type Config struct {
43 | Charset string `json:"charset"` //字符编码,默认utf-8编码
44 | Cover string `json:"cover"` //封面图片,或者封面html文件
45 | Timestamp string `json:"date"` //时间日期,如“2018-01-01 12:12:21”,其实是time.Time格式,但是直接用string就好
46 | Description string `json:"description"` //摘要
47 | Footer string `json:"footer"` //pdf的footer
48 | Header string `json:"header"` //pdf的header
49 | Identifier string `json:"identifier"` //即uuid,留空即可
50 | Language string `json:"language"` //语言,如zh、en、zh-CN、en-US等
51 | Creator string `json:"creator"` //作者,即author
52 | Publisher string `json:"publisher"` //出版单位
53 | Contributor string `json:"contributor"` //同Publisher
54 | Title string `json:"title"` //文档标题
55 | Format []string `json:"format"` //导出格式,可选值:pdf、epub、mobi、docx
56 | FontSize string `json:"font_size"` //默认的pdf导出字体大小
57 | PaperSize string `json:"paper_size"` //页面大小
58 | MarginLeft string `json:"margin_left"` //PDF文档左边距,写数字即可,默认72pt
59 | MarginRight string `json:"margin_right"` //PDF文档左边距,写数字即可,默认72pt
60 | MarginTop string `json:"margin_top"` //PDF文档左边距,写数字即可,默认72pt
61 | MarginBottom string `json:"margin_bottom"` //PDF文档左边距,写数字即可,默认72pt
62 | More []string `json:"more"` //更多导出选项[PDF导出选项,具体参考:https://manual.calibre-ebook.com/generated/en/ebook-convert.html#pdf-output-options]
63 | Toc []Toc `json:"toc"` //目录
64 | ///////////////////////////////////////////
65 | Order []string `json:"-"` //这个不需要赋值
66 | }
67 |
68 | var (
69 | output = "output" //文档导出文件夹
70 | ebookConvert = "ebook-convert"
71 | )
72 |
73 | // 根据json配置文件,创建文档转化对象
74 | func NewConverter(configFile string, debug ...bool) (converter *Converter, err error) {
75 | var (
76 | cfg Config
77 | basepath string
78 | db bool
79 | )
80 | if len(debug) > 0 {
81 | db = debug[0]
82 | }
83 |
84 | if cfg, err = parseConfig(configFile); err == nil {
85 | if basepath, err = filepath.Abs(filepath.Dir(configFile)); err == nil {
86 | //设置默认值
87 | if len(cfg.Timestamp) == 0 {
88 | cfg.Timestamp = time.Now().Format("2006-01-02 15:04:05")
89 | }
90 | if len(cfg.Charset) == 0 {
91 | cfg.Charset = "utf-8"
92 | }
93 | converter = &Converter{
94 | Config: cfg,
95 | BasePath: basepath,
96 | Debug: db,
97 | }
98 | }
99 | }
100 | return
101 | }
102 |
103 | // 执行文档转换
104 | func (this *Converter) Convert() (err error) {
105 | if !this.Debug { //调试模式下不删除生成的文件
106 | defer this.converterDefer() //最后移除创建的多余而文件
107 | }
108 |
109 | if err = this.generateMimeType(); err != nil {
110 | return
111 | }
112 | if err = this.generateMetaInfo(); err != nil {
113 | return
114 | }
115 | if err = this.generateTocNcx(); err != nil { //生成目录
116 | return
117 | }
118 | if err = this.generateSummary(); err != nil { //生成文档内目录
119 | return
120 | }
121 | if err = this.generateTitlePage(); err != nil { //生成封面
122 | return
123 | }
124 | if err = this.generateContentOpf(); err != nil { //这个必须是generate*系列方法的最后一个调用
125 | return
126 | }
127 |
128 | //将当前文件夹下的所有文件压缩成zip包,然后直接改名成content.epub
129 | f := this.BasePath + "/content.epub"
130 |
131 | os.Remove(f) //如果原文件存在了,则删除;
132 | if err = ziptil.Zip(f, this.BasePath); err != nil {
133 | return
134 | }
135 |
136 | //创建导出文件夹
137 | os.Mkdir(this.BasePath+"/"+output, os.ModePerm)
138 |
139 | //处理直接压缩后的content.epub文件,将其转成新的content-tmp.epub文件
140 | //再用content-tmp.epub文件替换掉content.epub文件,这样content.epub文件转PDF的时候,就不会出现空白页的情况了
141 | tmp := this.BasePath + "/content-tmp.epub"
142 | if _, err = execCommand(ebookConvert, []string{f, tmp}); err == nil {
143 | // 重命名文件
144 | os.Remove(f)
145 | os.Rename(tmp, f)
146 | }
147 |
148 | // 只生成PDF电子书
149 | formatLen := len(this.Config.Format)
150 | if formatLen == 0 {
151 | err = this.convertToPdf()
152 | return
153 | }
154 |
155 | var errs []string
156 | for _, v := range this.Config.Format {
157 | fmt.Println("\nconvert to " + v)
158 | v = strings.ToLower(v)
159 | switch strings.ToLower(v) {
160 | case "epub", ".epub":
161 | //注意:由于之前已经将其转成content.epub了,所以这里直接复制就好了,不需要再次转一遍
162 | target := this.BasePath + "/" + output + "/book.epub"
163 | b, err := ioutil.ReadFile(f)
164 | if err == nil {
165 | if err = ioutil.WriteFile(target, b, os.ModePerm); err != nil {
166 | errs = append(errs, err.Error())
167 | }
168 | } else {
169 | errs = append(errs, err.Error())
170 | }
171 | if this.Callback != nil {
172 | this.Callback(this.Config.Identifier, target, err)
173 | }
174 | case "mobi", ".mobi":
175 | if err = this.convertToMobi(); err != nil {
176 | errs = append(errs, err.Error())
177 | }
178 | case "pdf", ".pdf":
179 | if err = this.convertToPdf(); err != nil {
180 | errs = append(errs, err.Error())
181 | }
182 | case "docx", ".docx":
183 | if err = this.convertToWord(); err != nil {
184 | errs = append(errs, err.Error())
185 | }
186 | }
187 | }
188 | err = errors.New(strings.Join(errs, "\n"))
189 | return
190 | }
191 |
192 | // 删除生成导出文档而创建的文件
193 | func (this *Converter) converterDefer() {
194 | //删除不必要的文件
195 | os.RemoveAll(this.BasePath + "/META-INF")
196 | os.RemoveAll(this.BasePath + "/content.epub")
197 | os.RemoveAll(this.BasePath + "/mimetype")
198 | os.RemoveAll(this.BasePath + "/toc.ncx")
199 | os.RemoveAll(this.BasePath + "/content.opf")
200 | os.RemoveAll(this.BasePath + "/titlepage.xhtml") //封面图片待优化
201 | os.RemoveAll(this.BasePath + "/summary.html") //文档目录
202 | }
203 |
204 | // 生成metainfo
205 | func (this *Converter) generateMetaInfo() (err error) {
206 | xml := `
207 |
v0.2
:Gogs:用二进制才是真正的部署v0.3
:使用 Gogs 搭建私有 Git 托管服务v0.4
:基于 Gogs 进行协同工作v0.5
:通过 Gogs 的组织功能管理团队
捐赠时间 | 26 |捐赠人 | 27 |金额 | 28 ||
---|---|---|---|
2017-11-23 | 33 |朱同学 | 34 |¥20.00 | 35 ||
2017-11-20 | 38 |余同学 | 39 |¥10.00 | 40 ||
2017-10-28 | 43 |寒子 | 44 |¥6.66 | 45 ||
2017-10-26 | 48 |向同学 | 49 |¥10.00 | 50 ||
2017-10-21 | 53 |向同学 | 54 |¥200.00 | 55 ||
2017-10-12 | 58 |向同学 | 59 |¥5.00 | 60 ||
2017-10-05 | 63 |向同学 | 64 |¥5.00 | 65 ||
2017-09-30 | 68 |向同学 | 69 |¥200.00 | 70 ||
2017-09-14 | 73 |适同学 | 74 |¥101.00 | 75 ||
2017-09-14 | 78 |九梦 | 79 |¥10.00 | 80 ||
2017-09-06 | 83 |朱同学 | 84 |¥98.98 | 85 ||
2017-08-17 | 88 |向同学 | 89 |¥5.00 | 90 ||
2017-07-21 | 93 |老韩 | 94 |¥100.00 | 95 ||
2017-05-26 | 98 |Refactoring | 99 |¥100.00 | 100 ||
2017-04-03 | 103 |胜同学 | 104 |¥100.00 | 105 ||
2017-03-26 | 108 |向同学 | 109 |¥18.00 | 110 ||
2017-03-21 | 113 |陈同学 | 114 |¥100.00 | 115 ||
2017-03-16 | 118 |godlike | 119 |¥200.00 | 120 ||
2017-03-16 | 123 |向同学 | 124 |¥100.00 | 125 ||
2017-02-21 | 128 |智同学 | 129 |¥100.00 | 130 ||
2017-02-14 | 133 |曾同学 | 134 |¥100.00 | 135 ||
2017-02-14 | 138 |自富 | 139 |¥200.00 | 140 ||
2017-02-14 | 143 |刘同学 | 144 |¥100.00 | 145 ||
2017-01-11 | 148 |亚同学 | 149 |¥3.00 | 150 ||
2016-12-29 | 153 |涛同学 | 154 |¥15.00 | 155 ||
2016-12-25 | 158 |明同学 | 159 |¥18.80 | 160 ||
2016-10-18 | 163 |倩同学 | 164 |¥200.00 | 165 ||
2016-10-16 | 168 |nivk | 169 |¥400.00 | 170 ||
2016-10-14 | 173 |东威 | 174 |¥9.99 | 175 ||
2016-09-21 | 178 |悟道人 | 179 |¥50.00 | 180 ||
2016-08-01 | 183 |冒险王 | 184 |¥100.00 | 185 ||
2016-07-25 | 188 |诸葛同学 | 189 |¥50.00 | 190 ||
2016-07-10 | 193 |峰同学 | 194 |¥100.00 | 195 ||
2016-06-30 | 198 |null | 199 |¥20.00 | 200 ||
2016-06-24 | 203 |细同学 | 204 |¥20.00 | 205 ||
2016-06-21 | 208 |ZNing | 209 |¥6.88 | 210 ||
2016-06-16 | 213 |天涯同学 | 214 |¥20.00 | 215 ||
2016-06-11 | 218 |军同学 | 219 |¥200.00 | 220 ||
2016-05-30 | 223 |老K | 224 |¥5.00 | 225 ||
2016-05-16 | 228 |百同学 | 229 |¥100.00 | 230 ||
2016-05-04 | 233 |军同学 | 234 |¥100.00 | 235 ||
2016-04-16 | 238 |秦同学 | 239 |¥50.00 | 240 ||
2016-04-10 | 243 |greatpie | 244 |¥6.66 | 245 ||
2016-04-05 | 248 |kuuyee | 249 |¥500.00 | 250 ||
2016-03-23 | 253 |崔同学 | 254 |¥100.00 | 255 ||
2016-03-19 | 258 |李同学 | 259 |¥100.00 | 260 ||
2016-03-07 | 263 |binzu | 264 |6.66 | 265 ||
2016-02-05 | 268 |huihoo | 269 |¥50.00 | 270 ||
2016-02-02 | 273 |鹏同学 | 274 |¥100.00 | 275 ||
2016-01-31 | 278 |huihoo | 279 |¥100.00 | 280 ||
2015-12-14 | 283 |维同学 | 284 |¥20.00 | 285 ||
2015-11-28 | 288 |无同学 | 289 |¥100.00 | 290 ||
2015-09-17 | 293 |雪同学 | 294 |¥100.00 | 295 ||
2015-09-13 | 298 |匿名 | 299 |¥100.00 | 300 ||
2015-09-11 | 303 |霍同学 | 304 |¥100.00 | 305 ||
2015-08-20 | 308 |马同学 | 309 |¥100.00 | 310 ||
2015-07-19 | 313 |谭同学 | 314 |¥100.00 | 315 ||
2015-07-16 | 318 |军同学 | 319 |¥100.00 | 320 ||
2014-05-05 | 323 |吴同学 | 324 |¥50.00 | 325 ||
2014-05-02 | 328 |李同学 | 329 |¥8.88 | 330 ||
2014-05-02 | 333 |熊同学 | 334 |¥9.99 | 335 ||
2014-05-01 | 338 |艾同学 | 339 |¥0.50 | 340 ||
2014-05-01 | 343 |何同学 | 344 |¥50.00 | 345 ||
2014-05-01 | 348 |codepapa | 349 |¥199.00 | 350 |多出教程 | 351 |
基于 BindDN 和 simple auth 的 LDAP 授权方式共享以下字段:
14 |认证名称 (必填)
16 |主机地址 (必填)
19 |mydomain.com
主机端口 (必填)
22 |636
启用 TLS 加密(可选)
25 |管理员过滤规则(可选)
28 |(objectClass=adminAccount)
uid
名字属性(可选)
37 |givenName
姓氏属性(可选)
40 |sn
邮箱属性 (必填)
43 |基于 BindDN 需要填充以下字段:
47 |绑定 DN(可选)
49 |绑定密码(可选)
52 |用户搜索基准 (必填)
55 |用户过滤规则 (必填)
58 |%s
matching parameter will be substituted with login(&(objectClass=posixAccount)(uid=%s))
%[1]s
should be used instead, eg. when(&(objectClass=Person)(|(uid=%[1]s)(mail=%[1]s)(mobile=%[1]s)))
基于 simple auth 需要填充以下字段:
62 |User DN (必填)
64 |%s
matching parameter will be substituted with login name given on sign-in form.cn=%s,ou=Users,dc=mydomain,dc=com
uid=%s,ou=Users,dc=mydomain,dc=com
用户过滤规则 (必填)
67 |%s
(&(objectClass=posixAccount)(cn=%s))
(&(objectClass=posixAccount)(uid=%s))
验证组成员 需要填充以下字段:
71 |组搜索基准 DN(可选)
73 |ou=group,dc=mydomain,dc=com
组名称过滤(可选)
76 |(|(cn=gogs_users)(cn=admins))
包含用户的组属性(可选)
79 |memberUID
组内用户属性(可选)
82 |uid
To configure this you just need to set the ‘PAM Service Name’ to a filename in /etc/pam.d/
.
If you want it to work with normal Linux passwords, the user running Gogs must have read access to /etc/shadow
.
Gogs 支持通过指定邮箱服务器来对用户进行创建和认证,可以通过配置以下选项启用该功能:
87 |认证名称 (必填)
89 |SMTP 认证类型 (必填)
92 |主机地址 (必填)
95 |smtp.mydomain.com
端口号 (必填)
98 |587
域名白名单
101 |gogs.io,mydomain.com,mydomain2.com
启用 TLS 加密
104 |忽略 TLS 验证
107 |This authentication is activate
110 |In order to login to the Gogs using FreeIPA credentials, you need to create a bind account for Gogs to use:
115 |On the FreeIPA server, create a gogs.ldif
file, replacing dc=example,dc=com with your DN, and providing an appropriately secure password:
dn: uid=gogs,cn=sysaccounts,cn=etc,dc=example,dc=com
changetype: add
objectclass: account
objectclass: simplesecurityobject
uid: gogs
userPassword: secure password
passwordExpirationTime: 20380119031407Z
nsIdleTimeout: 0
Import the LDIF (change localhost to an IPA server if needed), you’ll be prompted for your Directory Manager password:
117 |
ldapmodify -h localhost -p 389 -x -D \
"cn=Directory Manager" -W -f gogs.ldif
ipa group-add --desc="Gogs Users" gogs_users
Note! if you get error about ipa credentials please run kinit admin and give your admin accound password.
118 |Now login to the gogs as an Admin, click on “Authentication” under Admin Panel. Then click New LDAP Source and fill in the details, changing all where appropriate to your own domain as photo below:
119 |您可以不需要修改仓库源码就能注入自定义头部和尾部内容,这对添加分析代码和自定义静态资源非常有用。
14 |了解更多有关 注入自定义头部和尾部。
15 |这里展示如何为您的 Gogs 实例添加自定义 CSS 文件,目录和文件名都是为了方便演示,您可以把文件放在任何能够通过网络访问的目录。
16 |public/css
目录下创建一个名为 custom.css
的文件custom/templates/inject/head.tmpl
文件并添加一行内容 <link rel="stylesheet" href="/css/custom.css">
Gogs 项目从 v0.5.0
版本开始支持应用的本地化,而您只需要鼠标单击就可实现即时语言切换。
在 custom/conf/app/ini
文件中启用它们(默认启用全部):
16 |
[i18n]
LANGS = en-US,zh-CN,zh-HK,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT
NAMES = English,简体中文,繁體中文,Deutsch,Français,Nederlands,Latviešu,Русский,日本語,Español,Português do Brasil,Polski,български,Italiano
到 Crowdin 注册一个用户然后填补未翻译的字段。
17 |有时候您会发现您无法将一个句子准确地从英文翻译到您的语言,没关系,这很正常!只需要使用您的语言将中心思想表达出来就可以,而不需要斤斤计较。
18 |如果您想要测试翻译好的本地化文件,但又不想涉及到 Git 历史的变动,您可以将本地化文件放至 custom/conf/locale/<file>
然后重启 Gogs。
如果您对官方的本地化翻译不够满意,可以修改其中的部分字段并保存到 custom/conf/locale/locale_<lang>.ini
中,然后重启 Gogs。
Gogs 支持针对仓库事件的 Web 钩子服务,您可以在仓库的设置相关页面中找到(/:username/:reponame/settings/hooks
)。所有的事件推送均为 POST 请求,目前支持 Gogs 和 Slack 两种格式的内容。
以下为 Gogs 向 Payload URL 发送的事件信息示例:
15 |
X-Gogs-Delivery: f6266f16-1bf3-46a5-9ea4-602e06ead473
X-Gogs-Event: push
X-Gogs-Signature: 1921679ed6274399b6514721056337f6913b6ff1cb35a24d340e983745d637f1
16 | 17 |
{
"ref": "refs/heads/develop",
"before": "28e1879d029cb852e4844d9c718537df08844e03",
"after": "bffeb74224043ba2feb48d137756c8a9331c449a",
"compare_url": "http://localhost:3000/unknwon/webhooks/compare/28e1879d029cb852e4844d9c718537df08844e03...bffeb74224043ba2feb48d137756c8a9331c449a",
"commits": [
{
"id": "bffeb74224043ba2feb48d137756c8a9331c449a",
"message": "!@#0^%\u003e\u003e\u003e\u003e\u003c\u003c\u003c\u003c\u003e\u003e\u003e\u003e\n",
"url": "http://localhost:3000/unknwon/webhooks/commit/bffeb74224043ba2feb48d137756c8a9331c449a",
"author": {
"name": "Unknwon",
"email": "u@gogs.io",
"username": "unknwon"
},
"committer": {
"name": "Unknwon",
"email": "u@gogs.io",
"username": "unknwon"
},
"timestamp": "2017-03-13T13:52:11-04:00"
}
],
"repository": {
"id": 140,
"owner": {
"id": 1,
"login": "unknwon",
"full_name": "Unknwon",
"email": "u@gogs.io",
"avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
"username": "unknwon"
},
"name": "webhooks",
"full_name": "unknwon/webhooks",
"description": "",
"private": false,
"fork": false,
"html_url": "http://localhost:3000/unknwon/webhooks",
"ssh_url": "ssh://unknwon@localhost:2222/unknwon/webhooks.git",
"clone_url": "http://localhost:3000/unknwon/webhooks.git",
"website": "",
"stars_count": 0,
"forks_count": 1,
"watchers_count": 1,
"open_issues_count": 7,
"default_branch": "master",
"created_at": "2017-02-26T04:29:06-05:00",
"updated_at": "2017-03-13T13:51:58-04:00"
},
"pusher": {
"id": 1,
"login": "unknwon",
"full_name": "Unknwon",
"email": "u@gogs.io",
"avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
"username": "unknwon"
},
"sender": {
"id": 1,
"login": "unknwon",
"full_name": "Unknwon",
"email": "u@gogs.io",
"avatar_url": "https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96",
"username": "unknwon"
}
}
ssh-keygen
到您的 %PATH%
环境变量中请根据您的选择进行安装:
22 |注意事项 您可以使用 etc/mysql.sql
来自动创建名为 gogs
的数据库。如果您选择手动创建,请务必将编码设置为 utf8mb4
。
假设您已经安装 Homebrew:
26 |27 |
$ brew update
$ brew install git
28 |
$ sudo apt-get update
$ sudo apt-get install git
想要使 Gogs 通过 Windows 服务的方式运行,必须满足以下两个条件:
14 |miniwinsvc
构建标签获得内置 Windows 服务支持。miniwinsvc
构建标签并通过 NSSM 注册为服务。在注册成为服务之前,需要确保给予 Gogs 二进制相应目录的读写权限,包括存放仓库的根目录([repository] ROOT
)。
修改 C:\Gogs\custom\conf\app.ini
文件的相应信息:
RUN_USER = COMPUTERNAME$
通过上面的配置将 Gogs 的运行用户设置为本地系统用户。COMPUTERNAME
的值可以通过命令 echo %COMPUTERNAME%
获得,如果该命令的返回值为 USER-PC
则使用 RUN_USER = USER-PC$
:
[server]
DOMAIN = gogs
PROTOCOL = http
HTTP_ADDR = 127.0.1.1
HTTP_PORT = 80
OFFLINE_MODE = true
ROOT_URL = http://gogs/
Moves Gogs’ listen port to 80 on the local interface subnet, and tells the Gogs HTTPd that its virtual host is the “gogs” domain.
This lets you forgo including a port number when browsing, and prevents collision with other localhost services.
The IP address can be anything in the range 127.0.0.2 - 127.254.254.254
, so long as it’s unique to Gogs.
To complete that network route, open Notepad.exe as administrator and include the following in C:\Windows\System32\drivers\etc\hosts
:
# Gogs local HTTPd
127.0.1.1 gogs
The hosts file entry will guarantee that all requests to the “gogs” domain are captured by your localhost interface.
In a web browser, generally, gogs/
in the address bar is sufficient to trigger that route.
Open a command prompt (cmd.exe
) as an Administrator. Run the following command:
C:\> sc create gogs start= auto binPath= "\"C:\gogs\gogs.exe\" web --config \"C:\gogs\custom\conf\app.ini\""
Ensure there is a space after each =
. You can choose to add additional Arguments to further modify your service, or modify it manually in the service management console.
To start the service run following command:
25 |
C:\> net start gogs
You should see following output:
26 |
The gogs service is starting.
The gogs service was started successfully.
Get the nssm.exe needed for your machine (32 or 64 bit; they’re packaged together in Iain’s zip file), and place it in a directory that is in (or will be added to) your %PATH%
environment variable.
Open a command line as administrator and do following command to configure Gogs as a service:
28 |
C:\>nssm install gogs
“NSSM service installer” will appear. Configure it as follows:
29 |Application tab:
30 |C:\gogs\gogs.exe
C:\gogs
web
Details tab:
34 |Gogs
A painless self-hosted Git service.
Automatic (Delayed Start)
Note that we’ve chosen delayed start, so that the service will not impact the early boot time. Gogs will start two minutes after the non-delayed services.
37 |I/O tab:
39 |C:\gogs\log\gogs-nssm.txt
C:\gogs\log\gogs-nssm.txt
That will capture all text output that you would normally receive from Gogs on the command line console, and log it to that file instead.
42 |File rotation tab:
44 |Rotate files
1000000 bytes
Environment tab:
48 |PATH=%PATH%;C:\gogs;C:\Program Files (x86)\Git\bin
That is a guarantee that both gogs.exe
and git.exe
will be on the Gogs service’s path variable during runtime.
Click “Install service”, and you should be confirmed that it succeeded.
53 |If it failed, refer back to the command line console you started, for the error message. When it succeeds, go to command line and do:
54 |
nssm start gogs
You should see:
55 |
gogs: START: The operation completed successfully.
Check that this is true by opening C:\gogs\log\gogs-nssm.txt
. You should see Gogs’ start up procedures, ending with:
timestamp [I] Run Mode: Production
timestamp [I] Listen: http://127.0.1.1:80
Now point your web browser at http://gogs/
and log in.
Gogs is running as a service, and will not need to be run manually, unless something goes wrong. NSSM will attempt to restart the service for you, if the Gogs server crashes.
58 |When you need to restart it after app.ini
changes, go to an administrator command line after the changes, and do:
nssm restart gogs
See the configuration cheat sheet for reference of the custom\conf\app.ini
settings.
An example of the logging and error handling in action:
61 |
[log]
ROOT_PATH = C:\gogs\log
At the time of writing this line, it will cause the following to print in C:\gogs\log\gogs-nssm.txt
:
timestamp [T] Custom path: C:/gogs/custom
timestamp [T] Log path: C:\gogs\log
timestamp [I] Gogs x.y.z
timestamp [log.go:294 Error()] [E] Fail to set logger(file): invalid character 'g' in string escape code
This is what was expected in C:\custom\conf\app.ini
:
ROOT_PATH = C:/gogs/log
And this was the nssm
interaction while solving it:
65 |
C:\>nssm restart gogs
gogs: STOP: The operation completed successfully.
gogs: Unexpected status SERVICE_PAUSED in response to START control.
C:\>nssm start gogs
gogs: START: An instance of the service is already running.
C:\>nssm stop gogs
gogs: STOP: The operation completed successfully.
C:\>nssm start gogs
gogs: Unexpected status SERVICE_PAUSED in response to START control.
C:\>nssm restart gogs
gogs: STOP: The operation completed successfully.
gogs: START: The operation completed successfully.
默认配置都保存在 conf/app.ini
,您 永远不需要 编辑它。该文件从 v0.6.0
版本开始被嵌入到二进制中。
那么,在不允许修改默认配置文件 conf/app.ini
的情况下,怎么才能自定义配置呢?很简单,只要创建 custom/conf/app.ini
就可以!在 custom/conf/app.ini
文件中修改相应选项的值即可。
例如,需要改变仓库根目录的路径:
16 |
[repository]
ROOT = /home/jiahuachen/gogs-repositories
当然,您也可以修改数据库配置:
17 |
[database]
PASSWD = root
乍一看,这么做有些复杂,但是这么做可以有效地保护您的自定义配置不被破坏:
18 |custom/conf/app.ini
文件中将选项 security -> INSTALL_LOCK
的值设置为 true
。您可以使用超能的 make
命令:
23 |
$ make
$ ./gogs web
脚本均放置在 scripts
目录,但请在仓库根目录执行它们
./gogs web
/install
来完成首次运行的配置工作目前只提供最近发布的小版本二进制下载,更多版本下载请前往 GitHub 查看。
14 |所有的版本都支持 MySQL、PostgreSQL、MSSQL 和 TiDB(使用 MySQL 协议)作为数据库,并且均使用构建标签(build tags)cert
进行构建。需要注意的是,不同的版本的支持状态有所不同,请根据实际的 Gogs 提示进行操作。
mws
表示提供内置 Windows 服务支持,如果您使用 NSSM 请使用另外一个版本。cd
进入到刚刚创建的目录。./gogs web
,然后,就没有然后了。templates
目录。系统名称 | 25 |系统类型 | 26 |SQLite | 27 |PAM | 28 |下载(GitHub) | 29 |||
---|---|---|---|---|---|---|
Linux | 34 |386 | 35 |✅ | 36 |✅ | 37 |HTTPS: ZIP \ | 38 |TAR.GZ - CDN: ZIP \ | 39 |TAR.GZ | 40 |
Linux | 43 |amd64 | 44 |✅ | 45 |✅ | 46 |HTTPS: ZIP \ | 47 |TAR.GZ - CDN: ZIP \ | 48 |TAR.GZ | 49 |
Linux | 52 |armv5 | 53 |❌ | 54 |❌ | 55 |HTTPS: ZIP - CDN: ZIP | 56 |||
Raspberry Pi | 59 |v2&v3 / armv6 | 60 |✅ | 61 |✅ | 62 |HTTPS: ZIP - CDN: ZIP | 63 |||
Windows | 66 |386 | 67 |✅ | 68 |❌ | 69 |HTTPS: ZIP \ | 70 |ZIP w/ mws - CDN: ZIP \ | 71 |ZIP w/mws | 72 |
Windows | 75 |amd64 | 76 |✅ | 77 |❌ | 78 |HTTPS: ZIP \ | 79 |ZIP w/ mws - CDN: ZIP \ | 80 |ZIP w/ mws | 81 |
Mac OS | 84 |amd64 | 85 |✅ | 86 |❌ | 87 |HTTPS: ZIP - CDN: ZIP | 88 |
系统名称 | 95 |系统类型 | 96 |SQLite | 97 |PAM | 98 |下载(GitHub) | 99 |||
---|---|---|---|---|---|---|
Linux | 104 |386 | 105 |✅ | 106 |✅ | 107 |HTTPS: ZIP \ | 108 |TAR.GZ - CDN: ZIP \ | 109 |TAR.GZ | 110 |
Linux | 113 |amd64 | 114 |✅ | 115 |✅ | 116 |HTTPS: ZIP \ | 117 |TAR.GZ - CDN: ZIP \ | 118 |TAR.GZ | 119 |
Linux | 122 |armv5 | 123 |❌ | 124 |❌ | 125 |HTTPS: ZIP - CDN: ZIP | 126 |||
Raspberry Pi | 129 |v2 / armv6 | 130 |✅ | 131 |✅ | 132 |HTTPS: ZIP - CDN: ZIP | 133 |||
Windows | 136 |386 | 137 |✅ | 138 |❌ | 139 |HTTPS: ZIP \ | 140 |ZIP w/ mws - CDN: ZIP \ | 141 |ZIP w/mws | 142 |
Windows | 145 |amd64 | 146 |✅ | 147 |❌ | 148 |HTTPS: ZIP \ | 149 |ZIP w/ mws - CDN: ZIP \ | 150 |ZIP w/ mws | 151 |
Mac OS | 154 |amd64 | 155 |✅ | 156 |❌ | 157 |HTTPS: ZIP - CDN: ZIP | 158 |
系统名称 | 165 |系统类型 | 166 |SQLite | 167 |PAM | 168 |下载(GitHub) | 169 |||
---|---|---|---|---|---|---|
Linux | 174 |386 | 175 |✅ | 176 |✅ | 177 |HTTPS: ZIP \ | 178 |TAR.GZ - CDN: ZIP \ | 179 |TAR.GZ | 180 |
Linux | 183 |amd64 | 184 |✅ | 185 |✅ | 186 |HTTPS: ZIP \ | 187 |TAR.GZ - CDN: ZIP \ | 188 |TAR.GZ | 189 |
Linux | 192 |armv5 | 193 |❌ | 194 |❌ | 195 |HTTPS: ZIP - CDN: ZIP | 196 |||
Raspberry Pi | 199 |v2 / armv6 | 200 |✅ | 201 |✅ | 202 |HTTPS: ZIP - CDN: ZIP | 203 |||
Windows | 206 |386 | 207 |✅ | 208 |❌ | 209 |HTTPS: ZIP \ | 210 |ZIP w/ mws - CDN: ZIP \ | 211 |ZIP w/mws | 212 |
Windows | 215 |amd64 | 216 |✅ | 217 |❌ | 218 |HTTPS: ZIP \ | 219 |ZIP w/ mws - CDN: ZIP \ | 220 |ZIP w/ mws | 221 |
Mac OS | 224 |amd64 | 225 |✅ | 226 |❌ | 227 |HTTPS: ZIP - CDN: ZIP | 228 |
系统名称 | 235 |系统类型 | 236 |SQLite | 237 |PAM | 238 |下载(GitHub) | 239 |||
---|---|---|---|---|---|---|
Linux | 244 |386 | 245 |✅ | 246 |✅ | 247 |HTTPS: ZIP \ | 248 |TAR.GZ - CDN: ZIP \ | 249 |TAR.GZ | 250 |
Linux | 253 |amd64 | 254 |✅ | 255 |✅ | 256 |HTTPS: ZIP \ | 257 |TAR.GZ - CDN: ZIP \ | 258 |TAR.GZ | 259 |
Linux | 262 |armv5 | 263 |❌ | 264 |❌ | 265 |HTTPS: ZIP - CDN: ZIP | 266 |||
Linux | 269 |armv6 | 270 |❌ | 271 |❌ | 272 |HTTPS: ZIP - CDN: ZIP | 273 |||
Raspberry Pi | 276 |v2 | 277 |✅ | 278 |✅ | 279 |HTTPS: ZIP - CDN: ZIP | 280 |||
Windows | 283 |386 | 284 |✅ | 285 |❌ | 286 |HTTPS: ZIP \ | 287 |ZIP w/ mws - CDN: ZIP \ | 288 |ZIP w/mws | 289 |
Windows | 292 |amd64 | 293 |✅ | 294 |❌ | 295 |HTTPS: ZIP \ | 296 |ZIP w/ mws - CDN: ZIP \ | 297 |ZIP w/ mws | 298 |
Mac OS | 301 |amd64 | 302 |✅ | 303 |❌ | 304 |HTTPS: ZIP - CDN: ZIP | 305 |
安装完成后可继续参照 [配置与运行]。
309 | 310 |以下均为第三方提供,后果自负!
14 |/etc/default/gogs
)。能可以到 Arch Linux Wiki entry 查看完整说明。
21 | 22 |请通过 gopmfile 查看完整的第三方包依赖列表。一般情况下只有在您为 Gogs 制作构建包的时候才会用到。
16 |如果您的系统已经安装要求版本的 Go 语言,可以跳过此小节。
17 |您可以通过以下方式安装 Go 语言到 /home/git/local/go
目录:
19 |
sudo su - git
cd ~
# create a folder to install 'go'
mkdir local
# Download go (change go$VERSION.$OS-$ARCH.tar.gz to the latest release)
wget https://storage.googleapis.com/golang/go$VERSION.$OS-$ARCH.tar.gz
# expand it to ~/local
tar -C /home/git/local -xzf go$VERSION.$OS-$ARCH.tar.gz
请设置和您系统环境对应的路径:
20 |21 |
sudo su - git
cd ~
echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc
echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc
常用的安装方式:
22 |23 |
# 下载并安装依赖
$ go get -u github.com/gogits/gogs
# 构建主程序
$ cd $GOPATH/src/github.com/gogits/gogs
$ go build
develop
分支版本如果您想要安装 develop
(或其它)分支版本,则可以通过以下命令:
25 |
$ mkdir -p $GOPATH/src/github.com/gogits
$ cd $GOPATH/src/github.com/gogits
# 请确保没有使用 “https://github.com/gogits/gogs.git”
$ git clone --depth=1 -b develop https://github.com/gogits/gogs
$ cd gogs
$ go build
您可以通过以下方式检查 Gogs 是否可以正常工作:
26 |27 |
cd $GOPATH/src/github.com/gogits/gogs
./gogs web
如果您没有发现任何错误信息,则可以使用 Ctrl-C
来终止运行。
Gogs 默认并没有支持一些功能,这些功能需要在构建时明确使用构建标签(build tags)来支持。
29 |目前使用标签构建的功能如下:
30 |sqlite3
:SQLite3 数据库支持pam
:PAM 授权认证支持cert
:生成自定义证书支持miniwinsvc
:Windows 服务内置支持(或者您可以使用 NSSM 来创建服务)例如,您需要支持以上所有功能,则需要先删除 $GOPATH/pkg/{GOOS_GOARCH}/github.com/gogits/gogs
目录,然后执行以下命令:
34 |
$ go get -u -tags "sqlite pam cert" github.com/gogits/gogs
$ cd $GOPATH/src/github.com/gogits/gogs
$ go build -tags "sqlite pam cert"
安装完成后可继续参照 [配置与运行]。
35 | 36 |Gogs 是一款极易搭建的自助 Git 服务。
14 |Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 所有平台,包括 Linux、Mac OS X、Windows 以及 ARM 平台。
15 |/api/v1/repos/search
返回空值 #4522unique constraint violation
#4357更早的变更日志可以在 GitHub 上找到。
42 | 43 |您可以在您第一次启动 Gogs 的时候通过以下方式修改默认的监听端口:
14 |
./gogs web -port 3001
该方法同样会在您填写安装页面时生效,因此请选择一个您希望以后一直给 Gogs 使用的端口号。
15 |在 nginx.conf
文件中,将下面的 server
部分增加至 http
分区内并重载配置:
server {
listen 80;
server_name git.crystalnetwork.us;
location / {
proxy_pass http://localhost:3000;
}
}
如果您想要通过域名的子路径来访问 Gogs 实例,可以将 NGINX 的配置修改为以下形式(特别注意后缀 /
):
server {
listen 80;
server_name git.crystalnetwork.us;
location /gogs/ {
proxy_pass http://localhost:3000/;
}
}
然后在配置文件中设置 [server] ROOT_URL = http://git.crystalnetwork.us/gogs/
。
想要了解如何让 NGINX 支持大文件上传的讨论,可以查看 此贴 。一般 NGINX 会返回 413
错误,在配置文件中加入以下内容可以解决该问题:
client_max_body_size 50m;
可以尝试使用下面的配置模板:
20 |
<VirtualHost *:443>
...
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass /git http://127.0.0.1:3000/
ProxyPassReverse /git http://127.0.0.1:3000/
</VirtualHost>
可以尝试使用下面的配置模板:
21 |
server.modules += ( "mod_proxy_backend_http" )
$HTTP["url"] =~ "^/gogs" {
proxy-core.protocol = "http"
proxy-core.backends = ( "localhost:3000" )
proxy-core.rewrite-request = (
"_uri" => ( "^/gogs/?(.*)" => "/$1" ),
"Host" => ( ".*" => "localhost:3000" ),
)
}
在 custom/conf/app.ini
文件中修改下列配置选项(以下仅为示例):
[server]
PROTOCOL = https
ROOT_URL = https://try.gogs.io/
CERT_FILE = custom/https/cert.pem
KEY_FILE = custom/https/key.pem
如果您想要使用自签名的 HTTPS,则可以使用下列命令来生成所需文件(需要使用构建标签 cert
或直接从官方下载二进制):
$ ./gogs cert -ca=true -duration=8760h0m0s -host=myhost.example.com
如果您需要将 Gogs 运行于内网环境下,只需将 custom/conf/app.ini
文件中的配置选项 server -> OFFLINE_MODE
修改为 true
即可。
在 custom
目录下创建 robots.txt
文件即可。
Gogs 拥有一些由第三方提供的脚本来支持以守护进程形式运行:
26 |在 GitHub 上的 Gogs 仓库有一个 systemd 服务模版文件,您需要做出一定的修改才能够使用它:
29 |User
、Group
、WorkingDirectory
、ExecStart
和 Environment
为相对应的值。其中 WorkingDirectory
为您的 Gogs 实际安装路径根目录。MySQL/MariaDB
、PostgreSQL
、Redis
或 memcached
,请去掉相应 After
属性的注释。当您完成修改后,请将文件保存至 /etc/systemd/system/gogs.service
,然后通过 sudo systemctl enable gogs
命令激活,最后执行 sudo systemctl start gogs
。
您可以通过 sudo systemctl status gogs -l
或 sudo journalctl -b -u gogs
命令检查 Gogs 的运行状态。
ID = 1
则会自动成为管理员,无需邮箱验证。Admin -> Users
面板并设置其它人员为管理员。由于这是一个 可能损坏您系统的高级权限,您必须在用户管理面板(/admin/users/:userid
)为您完全信任的用户单独开启。
纯文本形式的 Gogs 版本存储在文件 templates/.VERSION
中。
../gosrc/src/github.com/gogits/gogs/cmd/cert.go:79: undefined: elliptic.P224
/admin
)执行以下操作:重新生成 '.ssh/authorized_keys' 文件
重新同步所有仓库的 pre-receive、update 和 post-receive 钩子
在使用 SSH 推送时,Gogs 依赖通过执行钩子脚本(Hook Script)来更新仓库和最近活动。但出于某种原因,执行脚本的权限被拒绝了,尤其是在使用挂载(Mount)设备时。
22 |noexec
选项,必要时需要明确指定 exec
选项。vfat
(或者 cifs
)类型的挂载,请确保 uid
、gid
和 fmask
选项允许运行 Gogs 的用户在挂载设备上执行脚本。fatal: 'XX/XX.git' does not appear to be a git repository
~/.ssh/authorized_keys
文件中存在重复的 SSH 密钥,可能是由于您曾经或正在通过同一个系统用户使用 GitLab。repo.NewRepoContext(fail to set git user.email):
cmd
选项。cmd
选项。cache: unknown adaptername "memcache" (forgotten import?)
go get -tags memcache github.com/gogits/gogs
go build -tags memcache
redis
也是一样的步骤。Error 1071: Specified key was too long; max key length is 1000 bytes
解决方案:在使用 config/mysql.sql
创建完数据库后,进入数据库然后执行:
37 |
use gogs;
set global storage_engine=INNODB;
最后,访问 http://localhost:3000/install 即可(感谢 @linc01n)。
39 |Database setting is not correct: This server only supports the insecure old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords
user
数据表不存在。Please log in via your web browser and then try again
continue
。
2014/09/18 15:04:40 [repo.go:115 CreatePost()] [E] CreatePost: initRepository: initRepository(git clone): cygwin warning:
MS-DOS style path detected: C:\Users\user\gogs-repositories\unos\test3.git/.git
Preferred POSIX equivalent is: /cygdrive/c/Users/user/gogs-repositories/unos/test3.git/.git
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Cloning into 'C:\Users\user\AppData\Local\Temp\484264900'...
fatal: '/cygdrive/d/svnroot/research/gogs/C:\Users\user\gogs-repositories\unos\test3.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Resource interpreted as Stylesheet but transferred with MIME type application/x-css
HKEY_CLASSES_ROOT
下的 .css
,并将其 Content Type
的值修改为 text/css
。127.0.0.1
作为主机名而不是 localhost
。Error 1062: Duplicate entry 'Unknown-Mac' for key 'UQE_public_key_name'
public_key
表之前含有唯一索引 UQE_public_key_name
。GLIBC_2.14 not found
sudo apt-get -t testing install libc6-dev
。[Macaron] PANIC: session(start): mkdir data: permission denied
data
子目录。相关下载可以从 二进制安装 页面查看。
14 |首先,确认当前安装的位置:
15 |16 |
# 默认位置在 git 用户下的家目录
$ sudo su - git
$ cd ~
$ pwd
/home/git
$ ls
gogs gogs-repositories
然后将当前目录移动到另一个临时的位置,但不是删除!
17 |18 |
$ mv gogs gogs_old
下载并解压新的二进制:
19 |20 |
# 请根据系统和类型获取相应的二进制版本
$ wget wget https://dl.gogs.io/$VERSION/$OS_$ARCH.tar.gz
$ tar -zxvf $OS_$ARCH.tar.gz
$ ls
gogs gogs_old gogs-repositories $OS_$ARCH.tar.gz
复制 custom
、data
和 log
目录到新解压的目录中:
22 |
$ cp -R gogs_old/custom gogs
$ cp -R gogs_old/data gogs
$ cp -R gogs_old/log gogs
最后,运行并打开浏览器进行测试:
23 |24 |
$ cd gogs
$ ./gogs web
给自己点一个赞!
25 | 26 |升级 Gogs 的一般步骤:
14 |15 |
# 更新源码以及依赖
$ go get -u github.com/gogits/gogs
$ cd $GOPATH/src/github.com/gogits/gogs
# 移除旧的二进制
$ rm gogs
# 或将旧的二进制进行备份
$ mv gogs gogs.$(date +%Y-%m-%d).old
# 重新构建 Gogs
$ go build
其它操作:
16 | 18 | 19 |本文档使用 书栈(BookStack.CN) 构建 - _PAGENUM_ -
", 7 | "header": "_SECTION_
", 8 | "identifier": "", 9 | "language": "zh-CN", 10 | "creator": "书栈(BookStack.CN)", 11 | "publisher": "书栈(BookStack.CN)", 12 | "contributor": "书栈(BookStack.CN)", 13 | "title": "Gogs中文文档", 14 | "format": ["epub", "mobi", "pdf"], 15 | "font_size": "13", 16 | "paper_size": "a4", 17 | "margin_left": "72", 18 | "margin_right": "72", 19 | "margin_top": "72", 20 | "margin_bottom": "72", 21 | "more": [], 22 | "toc": [{ 23 | "id": 709800000, 24 | "link": "statement.html", 25 | "pid": 0, 26 | "title": "致谢" 27 | }, { 28 | "id": 539, 29 | "link": "539.html", 30 | "pid": 538, 31 | "title": "5.1 配置文件手册" 32 | }, { 33 | "id": 545, 34 | "link": "545.html", 35 | "pid": 543, 36 | "title": "4.1 自定义模板" 37 | }, { 38 | "id": 549, 39 | "link": "549.html", 40 | "pid": 548, 41 | "title": "2.1 注册 Windows 服务" 42 | }, { 43 | "id": 554, 44 | "link": "554.html", 45 | "pid": 0, 46 | "title": "1. 简介" 47 | }, { 48 | "id": 555, 49 | "link": "555.html", 50 | "pid": 554, 51 | "title": "1.1 变更日志" 52 | }, { 53 | "id": 540, 54 | "link": "540.html", 55 | "pid": 538, 56 | "title": "5.2 公告与高阶指南" 57 | }, { 58 | "id": 547, 59 | "link": "547.html", 60 | "pid": 543, 61 | "title": "4.2 Web 钩子" 62 | }, { 63 | "id": 548, 64 | "link": "548.html", 65 | "pid": 0, 66 | "title": "2. 下载安装" 67 | }, { 68 | "id": 556, 69 | "link": "556.html", 70 | "pid": 554, 71 | "title": "1.2 常见问题" 72 | }, { 73 | "id": 559, 74 | "link": "559.html", 75 | "pid": 558, 76 | "title": "3.1 二进制升级" 77 | }, { 78 | "id": 546, 79 | "link": "546.html", 80 | "pid": 543, 81 | "title": "4.3 多国语言支持" 82 | }, { 83 | "id": 550, 84 | "link": "550.html", 85 | "pid": 548, 86 | "title": "2.2 配置与运行" 87 | }, { 88 | "id": 557, 89 | "link": "557.html", 90 | "pid": 554, 91 | "title": "1.3 故障排查" 92 | }, { 93 | "id": 558, 94 | "link": "558.html", 95 | "pid": 0, 96 | "title": "3. 版本升级" 97 | }, { 98 | "id": 560, 99 | "link": "560.html", 100 | "pid": 558, 101 | "title": "3.2 源码升级" 102 | }, { 103 | "id": 543, 104 | "link": "543.html", 105 | "pid": 0, 106 | "title": "4. 功能介绍" 107 | }, { 108 | "id": 544, 109 | "link": "544.html", 110 | "pid": 543, 111 | "title": "4.4 授权认证" 112 | }, { 113 | "id": 551, 114 | "link": "551.html", 115 | "pid": 548, 116 | "title": "2.3 二进制安装" 117 | }, { 118 | "id": 538, 119 | "link": "538.html", 120 | "pid": 0, 121 | "title": "5. 高级用法" 122 | }, { 123 | "id": 552, 124 | "link": "552.html", 125 | "pid": 548, 126 | "title": "2.4 包管理安装" 127 | }, { 128 | "id": 542, 129 | "link": "542.html", 130 | "pid": 0, 131 | "title": "6. 捐赠我们" 132 | }, { 133 | "id": 553, 134 | "link": "553.html", 135 | "pid": 548, 136 | "title": "2.5 源码安装" 137 | }] 138 | } -------------------------------------------------------------------------------- /example/gogs_zh/d4643fd6157facd3f4178141fb4ab85d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/d4643fd6157facd3f4178141fb4ab85d.png -------------------------------------------------------------------------------- /example/gogs_zh/d92fc8f1c8954dda582909a8d37bc6c6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/d92fc8f1c8954dda582909a8d37bc6c6.png -------------------------------------------------------------------------------- /example/gogs_zh/e00b4e8899e00091e6ac46d230d53c2f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/e00b4e8899e00091e6ac46d230d53c2f.png -------------------------------------------------------------------------------- /example/gogs_zh/output/book.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/output/book.epub -------------------------------------------------------------------------------- /example/gogs_zh/output/book.mobi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/output/book.mobi -------------------------------------------------------------------------------- /example/gogs_zh/output/book.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TruthHun/converter/3f6d982de99e2dfdb4bea796c8c25bfc7be8359c/example/gogs_zh/output/book.pdf -------------------------------------------------------------------------------- /example/gogs_zh/statement.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |当前文档 《Gogs中文文档》 由 进击的皇虫 使用 书栈(BookStack.CN) 进行构建,生成于 2018-01-21。
19 |书栈(BookStack.CN) 仅提供文档编写、整理、归类等功能,以及对文档内容的生成和导出工具。
20 |文档内容由网友们编写和整理,书栈(BookStack.CN) 难以确认文档内容知识点是否错漏。如果您在阅读文档获取知识的时候,发现文档内容有不恰当的地方,请向我们反馈,让我们共同携手,将知识准确、高效且有效地传递给每一个人。
21 |同时,如果您在日常生活、工作和学习中遇到有价值有营养的知识文档,欢迎分享到 书栈(BookStack.CN) ,为知识的传承献上您的一份力量!
22 |如果当前文档生成时间太久,请到 书栈(BookStack.CN) 获取最新的文档,以跟上知识更新换代的步伐。
23 |文档地址:http://www.bookstack.cn/books/gogs_zh
24 | 25 |书栈开源:https://github.com/TruthHun
26 |分享,让知识传承更久远! 感谢知识的创造者,感谢知识的分享者,也感谢每一位阅读到此处的读者,因为我们都将成为知识的传承者。
27 |本文档使用 书栈(BookStack.CN) 构建 - _PAGENUM_ -
", 88 | "header": "_SECTION_
", 89 | "identifier": "", 90 | "language": "zh-CN", 91 | "creator": "书栈(BookStack.CN)", 92 | "publisher": "书栈(BookStack.CN)", 93 | "contributor": "书栈(BookStack.CN)", 94 | "title": "Gogs中文文档", 95 | "format": ["epub", "mobi", "pdf"], 96 | "font_size": "14", 97 | "paper_size": "a4", 98 | "margin_left": "72", 99 | "margin_right": "72", 100 | "margin_top": "72", 101 | "margin_bottom": "72", 102 | "more": [], 103 | "toc": [{ 104 | "id": 709800000, 105 | "link": "statement.html", 106 | "pid": 0, 107 | "title": "致谢" 108 | }, { 109 | "id": 539, 110 | "link": "539.html", 111 | "pid": 538, 112 | "title": "5.1 配置文件手册" 113 | }, { 114 | "id": 545, 115 | "link": "545.html", 116 | "pid": 543, 117 | "title": "4.1 自定义模板" 118 | }, { 119 | "id": 549, 120 | "link": "549.html", 121 | "pid": 548, 122 | "title": "2.1 注册 Windows 服务" 123 | }, { 124 | "id": 554, 125 | "link": "554.html", 126 | "pid": 0, 127 | "title": "1. 简介" 128 | }, { 129 | "id": 555, 130 | "link": "555.html", 131 | "pid": 554, 132 | "title": "1.1 变更日志" 133 | }, { 134 | "id": 540, 135 | "link": "540.html", 136 | "pid": 538, 137 | "title": "5.2 公告与高阶指南" 138 | }, { 139 | "id": 547, 140 | "link": "547.html", 141 | "pid": 543, 142 | "title": "4.2 Web 钩子" 143 | }, { 144 | "id": 548, 145 | "link": "548.html", 146 | "pid": 0, 147 | "title": "2. 下载安装" 148 | }, { 149 | "id": 556, 150 | "link": "556.html", 151 | "pid": 554, 152 | "title": "1.2 常见问题" 153 | }, { 154 | "id": 559, 155 | "link": "559.html", 156 | "pid": 558, 157 | "title": "3.1 二进制升级" 158 | }, { 159 | "id": 546, 160 | "link": "546.html", 161 | "pid": 543, 162 | "title": "4.3 多国语言支持" 163 | }, { 164 | "id": 550, 165 | "link": "550.html", 166 | "pid": 548, 167 | "title": "2.2 配置与运行" 168 | }, { 169 | "id": 557, 170 | "link": "557.html", 171 | "pid": 554, 172 | "title": "1.3 故障排查" 173 | }, { 174 | "id": 558, 175 | "link": "558.html", 176 | "pid": 0, 177 | "title": "3. 版本升级" 178 | }, { 179 | "id": 560, 180 | "link": "560.html", 181 | "pid": 558, 182 | "title": "3.2 源码升级" 183 | }, { 184 | "id": 543, 185 | "link": "543.html", 186 | "pid": 0, 187 | "title": "4. 功能介绍" 188 | }, { 189 | "id": 544, 190 | "link": "544.html", 191 | "pid": 543, 192 | "title": "4.4 授权认证" 193 | }, { 194 | "id": 551, 195 | "link": "551.html", 196 | "pid": 548, 197 | "title": "2.3 二进制安装" 198 | }, { 199 | "id": 538, 200 | "link": "538.html", 201 | "pid": 0, 202 | "title": "5. 高级用法" 203 | }, { 204 | "id": 552, 205 | "link": "552.html", 206 | "pid": 548, 207 | "title": "2.4 包管理安装" 208 | }, { 209 | "id": 542, 210 | "link": "542.html", 211 | "pid": 0, 212 | "title": "6. 捐赠我们" 213 | }, { 214 | "id": 553, 215 | "link": "553.html", 216 | "pid": 548, 217 | "title": "2.5 源码安装" 218 | }] 219 | } 220 | ``` 221 | 222 | 223 | ### json配置项说明 224 | - `charset` 指定字符集,留空则默认为utf-8编码。选填。 225 | - `cover` 封面图片,一张`800x1068`像素或该尺寸比例的图片,jpg、png或gif格式。如果没有封面,请置空。选填。 226 | - `date` 文档生成日期,年月日时分秒都可以。默认当前日期时间。选填。 227 | - `title` 文档标题。必填。 228 | - `description` 文档描述、摘要。选填。 229 | - `footer`、`header` 生成PDF文档时,文档的底部(footer)和顶部(header)内容,仅对PDF文档有效。选填。 230 | - `identifier` 出版物的标识。留空即可。 231 | - `language` 语言。必填。可选值:zh、en、zh-CN、en-US等。 232 | - `creator`、`publisher`、`contributor` 如果你懒的话,三个都传同一个值,比如示例中的"书栈(BookStack.CN)"。如果真要区分的话,`creator`就是文档作者,比如"进击的皇虫",`publisher`、`contributor`理解为出版单位和构建人。三个配置项,建议填写。 233 | - `format` 导出的文档格式,不传值则默认导出PDF。可选值:epub、pdf、mobi。 234 | - `font_size` 数字,默认字体大小,仅对导出PDF有效。选填。 235 | - `paper_size` 导出文档的页面大小,不区分大小写。默认"A4",选填。可选值: `a0`, `a1`, `a2`, `a3`, `a4`, `a5`, `a6`, `b0`, `b1`, `b2`, `b3`, `b4`,`b5`, `b6`, `legal`, `letter` 236 | - `margin_left`、`margin_right`、`margin_top`、`margin_bottom` 数字,左边距、右边距、上边距、下边距,仅对PDF文档有效。选填,默认72,即表示72pt。 237 | - `more` 更多选项。仅对PDF有效。不建议使用。 238 | - `toc` 重要!!!这个是重中之重,用于生成文档目录的。`id`、`pid`是数字,`pid`表示上级的id。id的值不能重复。`link`表示html链接文件。toc里面的`title`表示目录章节标题。 239 | 240 | (参照示例的`config.json`去配置就好。) 241 | 242 | 243 | ## 使用教程 244 | bin目录下的是当前程序生成的64位的二进制可执行文件。Windows下使用示例: 245 | ``` 246 | converter.exe path/to/config.json 247 | ``` 248 | 执行成功之后,会自动在项目目录下创建个`output`文件夹,并将文件导出到里面。比如导出pdf格式,则会在`output`文件夹下面出现`book.pdf`文件。 249 | 250 | 251 | ### Go语言使用 252 | 引入当前包: 253 | `github.com/TruthHun/converter/converter` 254 | ```golang 255 | if Convert, err:= converter.NewConverter("path/to/config.json");err==nil{ 256 | Convert.Convert() 257 | } 258 | ``` 259 | 260 | 261 | ### 其它语言 262 | 由于目前没封装PHP、Python等的类和包,所以其它语言要使用的话,就是在项目下生成一个config.json(名字随便自己定义),然后调用各自语言的cmd执行: 263 | ``` 264 | /path/to/converter /path/to/config.json 265 | ``` 266 | 267 | ## 原理 268 | HTML导出PDF、epub等文档的原理很简单:根据config.json中的内容,生成epub电子书的基本结构,然后将当前目录下的文件压缩并重命名如`content.epub`,然后再使用`ebook-convert`进行转换,转换命令: 269 | ``` 270 | ebook-convert content.epub output/book.pdf [options] 271 | ``` 272 | 这样,你就可以使用自己熟悉的语言封装一个包,并调用calibre导出文档了。 273 | 274 | 275 | 276 | ## 注意事项 277 | - HTML中不要有使用js代码渲染文档内容,因为js是不会被执行的 278 | 279 | 280 | ## 精神上支持我 281 | 虽然我很缺钱... 282 | 但是得到他人的肯定和认可比什么都重要。 283 | 如果当前项目帮到了你,请给项目一个star,以鼓励我在开源的路上能走的更好、更远。 284 | 附自己业余时间搞的一些站点,支持我,可以点击访问一下: 285 | - IT文库 http://wenku.it 286 | - 书栈(BookStack) http://www.bookstack.cn 287 | 288 | 289 | ## markdown文档如何转成pdf、epub、mobi 290 | 说实话,这个我没仔细去研究过。思路就是将markdown文档转成HTML(毕竟这样比较好控制显示样式),然后再通过当前工具再转成PDF文档等。网上应该有更好的方法,如果大家找到了,麻烦也分享一下。 291 | 292 | 293 | 294 | --------------------------------------------------------------------------------