Skip to content

Commit be6debd

Browse files
committed
fix(internal/docs): 内嵌的代码 content-type 值输出字符集信息
1 parent f504136 commit be6debd

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

apidoc_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestViewFile(t *testing.T) {
8888
Status(http.StatusAccepted)
8989
srv.Close()
9090

91+
// 覆盖现有的 index.xml
9192
h, err = ViewFile(http.StatusAccepted, "", doctest.Path(a), "", "", false)
9293
a.NotError(err).NotNil(h)
9394
srv = rest.NewServer(t, h, nil)

docs/example/index.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<?xml-stylesheet type="text/xsl" href="../v6/apidoc.xsl"?>
4-
<apidoc apidoc="6.0.0" created="2020-01-08T00:32:45+08:00" version="1.1.1">
4+
<apidoc apidoc="6.0.0" created="2020-01-08T00:44:52+08:00" version="1.1.1">
55
<title>示例文档</title>
66
<description type="html"><![CDATA[
77

internal/docs/make_static.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ const (
2525
// 允许打包的文件后缀名,以及对应的 mime type 值。
2626
// 不采用 mimetype.TypeByExtension,防止出现空值的可能性。
2727
var allowFiles = map[string]string{
28-
".xml": "application/xml",
29-
".xsl": "text/xsl",
30-
".svg": "image/svg+xml",
31-
".css": "text/css",
32-
".js": "application/javascript",
33-
".html": "text/html",
34-
".htm": "text/html",
28+
".xml": "application/xml; charset=utf-8",
29+
".xsl": "text/xsl; charset=utf-8",
30+
".svg": "image/svg+xml; charset=utf-8",
31+
".css": "text/css; charset=utf-8",
32+
".js": "application/javascript; charset=utf-8",
33+
".html": "text/html; charset=utf-8",
34+
".htm": "text/html; charset=utf-8",
3535
}
3636

3737
func main() {

internal/docs/static.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package docs
44

55
var data = []*FileInfo{{
66
Name: "config.xml",
7-
ContentType: "application/xml",
7+
ContentType: "application/xml; charset=utf-8",
88
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
99
1010
<!-- 该文件由工具自动生成,请勿手动修改!-->
@@ -38,11 +38,11 @@ var data = []*FileInfo{{
3838
},
3939
{
4040
Name: "example/index.xml",
41-
ContentType: "application/xml",
41+
ContentType: "application/xml; charset=utf-8",
4242
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
4343
4444
<?xml-stylesheet type="text/xsl" href="../v6/apidoc.xsl"?>
45-
<apidoc apidoc="6.0.0" created="2020-01-07T23:39:48+08:00" version="1.1.1">
45+
<apidoc apidoc="6.0.0" created="2020-01-08T00:44:41+08:00" version="1.1.1">
4646
<title>示例文档</title>
4747
<description type="html"><![CDATA[
4848
@@ -265,7 +265,7 @@ var data = []*FileInfo{{
265265
},
266266
{
267267
Name: "icon.svg",
268-
ContentType: "image/svg+xml",
268+
ContentType: "image/svg+xml; charset=utf-8",
269269
Content: []byte(`<?xml version="1.0" encoding="utf-8" ?>
270270
271271
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" stroke="#f60">
@@ -281,7 +281,7 @@ var data = []*FileInfo{{
281281
},
282282
{
283283
Name: "index.css",
284-
ContentType: "text/css",
284+
ContentType: "text/css; charset=utf-8",
285285
Content: []byte(`@charset "utf-8";
286286
287287
:root {
@@ -482,7 +482,7 @@ footer .wrap {
482482
},
483483
{
484484
Name: "index.js",
485-
ContentType: "application/javascript",
485+
ContentType: "application/javascript; charset=utf-8",
486486
Content: []byte(`'use strict';
487487
488488
window.onload = function() {
@@ -506,7 +506,7 @@ function initGotoTop() {
506506
},
507507
{
508508
Name: "index.xml",
509-
ContentType: "application/xml",
509+
ContentType: "application/xml; charset=utf-8",
510510
Content: []byte(`<?xml version="1.0" encoding="utf-8"?>
511511
<?xml-stylesheet type="text/xsl" href="./index.xsl"?>
512512
@@ -801,7 +801,7 @@ function initGotoTop() {
801801
},
802802
{
803803
Name: "index.xsl",
804-
ContentType: "text/xsl",
804+
ContentType: "text/xsl; charset=utf-8",
805805
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
806806
807807
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
@@ -1009,7 +1009,7 @@ function initGotoTop() {
10091009
},
10101010
{
10111011
Name: "index.zh-hant.xml",
1012-
ContentType: "application/xml",
1012+
ContentType: "application/xml; charset=utf-8",
10131013
Content: []byte(`<?xml version="1.0" encoding="utf-8"?>
10141014
<?xml-stylesheet type="text/xsl" href="./index.xsl"?>
10151015
@@ -1304,7 +1304,7 @@ function initGotoTop() {
13041304
},
13051305
{
13061306
Name: "locales.xml",
1307-
ContentType: "application/xml",
1307+
ContentType: "application/xml; charset=utf-8",
13081308
Content: []byte(`<?xml version="1.0" encoding="utf-8"?>
13091309
13101310
<locales>
@@ -1315,7 +1315,7 @@ function initGotoTop() {
13151315
},
13161316
{
13171317
Name: "types.xml",
1318-
ContentType: "application/xml",
1318+
ContentType: "application/xml; charset=utf-8",
13191319
Content: []byte(`<?xml version="1.0" encoding="utf-8"?>
13201320
13211321
<types>
@@ -1478,7 +1478,7 @@ function initGotoTop() {
14781478
},
14791479
{
14801480
Name: "v5/apidoc.css",
1481-
ContentType: "text/css",
1481+
ContentType: "text/css; charset=utf-8",
14821482
Content: []byte(`@charset "utf-8";
14831483
14841484
:root {
@@ -1879,7 +1879,7 @@ footer .wrap {
18791879
},
18801880
{
18811881
Name: "v5/apidoc.js",
1882-
ContentType: "application/javascript",
1882+
ContentType: "application/javascript; charset=utf-8",
18831883
Content: []byte(`'use strict';
18841884
18851885
window.onload = function () {
@@ -2008,7 +2008,7 @@ function prettyDescription() {
20082008
},
20092009
{
20102010
Name: "v5/apidoc.xsl",
2011-
ContentType: "text/xsl",
2011+
ContentType: "text/xsl; charset=utf-8",
20122012
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
20132013
20142014
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
@@ -2546,7 +2546,7 @@ xsl 2.0 可以直接采用 base-uri(document(''))
25462546
},
25472547
{
25482548
Name: "v5/locales.xsl",
2549-
ContentType: "text/xsl",
2549+
ContentType: "text/xsl; charset=utf-8",
25502550
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
25512551
25522552
<!-- 当前文件实现了简单的翻译功能 -->
@@ -2894,7 +2894,7 @@ exclude-result-prefixes="l">
28942894
},
28952895
{
28962896
Name: "v5/view.html",
2897-
ContentType: "text/html",
2897+
ContentType: "text/html; charset=utf-8",
28982898
Content: []byte(`<!DOCTYPE html>
28992899
<html lang="en">
29002900
@@ -2983,7 +2983,7 @@ exclude-result-prefixes="l">
29832983
},
29842984
{
29852985
Name: "v6/apidoc.css",
2986-
ContentType: "text/css",
2986+
ContentType: "text/css; charset=utf-8",
29872987
Content: []byte(`@charset "utf-8";
29882988
29892989
:root {
@@ -3394,7 +3394,7 @@ footer .wrap {
33943394
},
33953395
{
33963396
Name: "v6/apidoc.js",
3397-
ContentType: "application/javascript",
3397+
ContentType: "application/javascript; charset=utf-8",
33983398
Content: []byte(`'use strict';
33993399
34003400
window.onload = function () {
@@ -3490,7 +3490,7 @@ function prettyDescription() {
34903490
},
34913491
{
34923492
Name: "v6/apidoc.xsl",
3493-
ContentType: "text/xsl",
3493+
ContentType: "text/xsl; charset=utf-8",
34943494
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
34953495
34963496
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
@@ -4070,7 +4070,7 @@ xsl 2.0 可以直接采用 base-uri(document(''))
40704070
},
40714071
{
40724072
Name: "v6/locales.xsl",
4073-
ContentType: "text/xsl",
4073+
ContentType: "text/xsl; charset=utf-8",
40744074
Content: []byte(`<?xml version="1.0" encoding="UTF-8"?>
40754075
40764076
<!-- 当前文件实现了简单的翻译功能 -->
@@ -4418,7 +4418,7 @@ exclude-result-prefixes="l">
44184418
},
44194419
{
44204420
Name: "v6/view.html",
4421-
ContentType: "text/html",
4421+
ContentType: "text/html; charset=utf-8",
44224422
Content: []byte(`<!DOCTYPE html>
44234423
<html lang="en">
44244424

0 commit comments

Comments
 (0)