mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
media: Add PDF MIME type
This commit is contained in:
parent
425c7d90f0
commit
cdc73526a8
3 changed files with 208 additions and 8 deletions
|
@ -169,7 +169,6 @@ func (m Type) IsText() bool {
|
||||||
switch m.SubType {
|
switch m.SubType {
|
||||||
case "javascript", "json", "rss", "xml", "svg", TOMLType.SubType, YAMLType.SubType:
|
case "javascript", "json", "rss", "xml", "svg", TOMLType.SubType, YAMLType.SubType:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -239,6 +238,9 @@ var (
|
||||||
TrueTypeFontType = newMediaType("font", "ttf", []string{"ttf"})
|
TrueTypeFontType = newMediaType("font", "ttf", []string{"ttf"})
|
||||||
OpenTypeFontType = newMediaType("font", "otf", []string{"otf"})
|
OpenTypeFontType = newMediaType("font", "otf", []string{"otf"})
|
||||||
|
|
||||||
|
// Common document types
|
||||||
|
PDFType = newMediaType("application", "pdf", []string{"pdf"})
|
||||||
|
|
||||||
// Common video types
|
// Common video types
|
||||||
AVIType = newMediaType("video", "x-msvideo", []string{"avi"})
|
AVIType = newMediaType("video", "x-msvideo", []string{"avi"})
|
||||||
MPEGType = newMediaType("video", "mpeg", []string{"mpg", "mpeg"})
|
MPEGType = newMediaType("video", "mpeg", []string{"mpg", "mpeg"})
|
||||||
|
@ -282,6 +284,7 @@ var DefaultTypes = Types{
|
||||||
GPPType,
|
GPPType,
|
||||||
OpenTypeFontType,
|
OpenTypeFontType,
|
||||||
TrueTypeFontType,
|
TrueTypeFontType,
|
||||||
|
PDFType,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -51,6 +51,7 @@ func TestDefaultTypes(t *testing.T) {
|
||||||
{XMLType, "application", "xml", "xml", "application/xml", "application/xml"},
|
{XMLType, "application", "xml", "xml", "application/xml", "application/xml"},
|
||||||
{TOMLType, "application", "toml", "toml", "application/toml", "application/toml"},
|
{TOMLType, "application", "toml", "toml", "application/toml", "application/toml"},
|
||||||
{YAMLType, "application", "yaml", "yaml", "application/yaml", "application/yaml"},
|
{YAMLType, "application", "yaml", "yaml", "application/yaml", "application/yaml"},
|
||||||
|
{PDFType, "application", "pdf", "pdf", "application/pdf", "application/pdf"},
|
||||||
{TrueTypeFontType, "font", "ttf", "ttf", "font/ttf", "font/ttf"},
|
{TrueTypeFontType, "font", "ttf", "ttf", "font/ttf", "font/ttf"},
|
||||||
{OpenTypeFontType, "font", "otf", "otf", "font/otf", "font/otf"},
|
{OpenTypeFontType, "font", "otf", "otf", "font/otf", "font/otf"},
|
||||||
} {
|
} {
|
||||||
|
@ -62,7 +63,7 @@ func TestDefaultTypes(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Assert(len(DefaultTypes), qt.Equals, 30)
|
c.Assert(len(DefaultTypes), qt.Equals, 31)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetByType(t *testing.T) {
|
func TestGetByType(t *testing.T) {
|
||||||
|
@ -118,7 +119,8 @@ func TestGetFirstBySuffix(t *testing.T) {
|
||||||
c.Assert(found, qt.Equals, true)
|
c.Assert(found, qt.Equals, true)
|
||||||
c.Assert(f, qt.Equals, SuffixInfo{
|
c.Assert(f, qt.Equals, SuffixInfo{
|
||||||
Suffix: suffix,
|
Suffix: suffix,
|
||||||
FullSuffix: "." + suffix})
|
FullSuffix: "." + suffix,
|
||||||
|
})
|
||||||
c.Assert(t, qt.Equals, expectedType)
|
c.Assert(t, qt.Equals, expectedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +128,6 @@ func TestGetFirstBySuffix(t *testing.T) {
|
||||||
check("json", JSONType)
|
check("json", JSONType)
|
||||||
check("geojson", geoJSON)
|
check("geojson", geoJSON)
|
||||||
check("gjson", geoJSON)
|
check("gjson", geoJSON)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromTypeString(t *testing.T) {
|
func TestFromTypeString(t *testing.T) {
|
||||||
|
@ -150,7 +151,6 @@ func TestFromTypeString(t *testing.T) {
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
c.Assert(f, qt.Equals, Type{MainType: "text", SubType: "xml", mimeSuffix: ""})
|
c.Assert(f, qt.Equals, Type{MainType: "text", SubType: "xml", mimeSuffix: ""})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromStringAndExt(t *testing.T) {
|
func TestFromStringAndExt(t *testing.T) {
|
||||||
|
@ -178,7 +178,6 @@ func TestFromExtensionMultipleSuffixes(t *testing.T) {
|
||||||
c.Assert(found, qt.Equals, true)
|
c.Assert(found, qt.Equals, true)
|
||||||
c.Assert(ftp.String(), qt.Equals, "image/svg+xml")
|
c.Assert(ftp.String(), qt.Equals, "image/svg+xml")
|
||||||
c.Assert(found, qt.Equals, true)
|
c.Assert(found, qt.Equals, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromContent(t *testing.T) {
|
func TestFromContent(t *testing.T) {
|
||||||
|
@ -189,7 +188,8 @@ func TestFromContent(t *testing.T) {
|
||||||
mtypes := DefaultTypes
|
mtypes := DefaultTypes
|
||||||
|
|
||||||
for _, filename := range files {
|
for _, filename := range files {
|
||||||
c.Run(filepath.Base(filename), func(c *qt.C) {
|
name := filepath.Base(filename)
|
||||||
|
c.Run(name, func(c *qt.C) {
|
||||||
content, err := ioutil.ReadFile(filename)
|
content, err := ioutil.ReadFile(filename)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
ext := strings.TrimPrefix(paths.Ext(filename), ".")
|
ext := strings.TrimPrefix(paths.Ext(filename), ".")
|
||||||
|
@ -252,7 +252,6 @@ func TestDecodeTypes(t *testing.T) {
|
||||||
|
|
||||||
_, found = tt.GetByType("application/hugo+hg")
|
_, found = tt.GetByType("application/hugo+hg")
|
||||||
c.Assert(found, qt.Equals, true)
|
c.Assert(found, qt.Equals, true)
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
198
media/testdata/resource.pdf
vendored
Normal file
198
media/testdata/resource.pdf
vendored
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
%PDF-1.3
|
||||||
|
%âãÏÓ
|
||||||
|
|
||||||
|
1 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Catalog
|
||||||
|
/Outlines 2 0 R
|
||||||
|
/Pages 3 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
2 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Outlines
|
||||||
|
/Count 0
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
3 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Pages
|
||||||
|
/Count 2
|
||||||
|
/Kids [ 4 0 R 6 0 R ]
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
4 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Page
|
||||||
|
/Parent 3 0 R
|
||||||
|
/Resources <<
|
||||||
|
/Font <<
|
||||||
|
/F1 9 0 R
|
||||||
|
>>
|
||||||
|
/ProcSet 8 0 R
|
||||||
|
>>
|
||||||
|
/MediaBox [0 0 612.0000 792.0000]
|
||||||
|
/Contents 5 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
5 0 obj
|
||||||
|
<< /Length 1074 >>
|
||||||
|
stream
|
||||||
|
2 J
|
||||||
|
BT
|
||||||
|
0 0 0 rg
|
||||||
|
/F1 0027 Tf
|
||||||
|
57.3750 722.2800 Td
|
||||||
|
( A Simple PDF File ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 688.6080 Td
|
||||||
|
( This is a small demonstration .pdf file - ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 664.7040 Td
|
||||||
|
( just for use in the Virtual Mechanics tutorials. More text. And more ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 652.7520 Td
|
||||||
|
( text. And more text. And more text. And more text. ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 628.8480 Td
|
||||||
|
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 616.8960 Td
|
||||||
|
( text. And more text. Boring, zzzzz. And more text. And more text. And ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 604.9440 Td
|
||||||
|
( more text. And more text. And more text. And more text. And more text. ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 592.9920 Td
|
||||||
|
( And more text. And more text. ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 569.0880 Td
|
||||||
|
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 557.1360 Td
|
||||||
|
( text. And more text. And more text. Even more. Continued on page 2 ...) Tj
|
||||||
|
ET
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
|
||||||
|
6 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Page
|
||||||
|
/Parent 3 0 R
|
||||||
|
/Resources <<
|
||||||
|
/Font <<
|
||||||
|
/F1 9 0 R
|
||||||
|
>>
|
||||||
|
/ProcSet 8 0 R
|
||||||
|
>>
|
||||||
|
/MediaBox [0 0 612.0000 792.0000]
|
||||||
|
/Contents 7 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
7 0 obj
|
||||||
|
<< /Length 676 >>
|
||||||
|
stream
|
||||||
|
2 J
|
||||||
|
BT
|
||||||
|
0 0 0 rg
|
||||||
|
/F1 0027 Tf
|
||||||
|
57.3750 722.2800 Td
|
||||||
|
( Simple PDF File 2 ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 688.6080 Td
|
||||||
|
( ...continued from page 1. Yet more text. And more text. And more text. ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 676.6560 Td
|
||||||
|
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 664.7040 Td
|
||||||
|
( text. Oh, how boring typing this stuff. But not as boring as watching ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 652.7520 Td
|
||||||
|
( paint dry. And more text. And more text. And more text. And more text. ) Tj
|
||||||
|
ET
|
||||||
|
BT
|
||||||
|
/F1 0010 Tf
|
||||||
|
69.2500 640.8000 Td
|
||||||
|
( Boring. More, a little more text. The end, and just as well. ) Tj
|
||||||
|
ET
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
|
||||||
|
8 0 obj
|
||||||
|
[/PDF /Text]
|
||||||
|
endobj
|
||||||
|
|
||||||
|
9 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Font
|
||||||
|
/Subtype /Type1
|
||||||
|
/Name /F1
|
||||||
|
/BaseFont /Helvetica
|
||||||
|
/Encoding /WinAnsiEncoding
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
10 0 obj
|
||||||
|
<<
|
||||||
|
/Creator (Rave \(http://www.nevrona.com/rave\))
|
||||||
|
/Producer (Nevrona Designs)
|
||||||
|
/CreationDate (D:20060301072826)
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
xref
|
||||||
|
0 11
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000019 00000 n
|
||||||
|
0000000093 00000 n
|
||||||
|
0000000147 00000 n
|
||||||
|
0000000222 00000 n
|
||||||
|
0000000390 00000 n
|
||||||
|
0000001522 00000 n
|
||||||
|
0000001690 00000 n
|
||||||
|
0000002423 00000 n
|
||||||
|
0000002456 00000 n
|
||||||
|
0000002574 00000 n
|
||||||
|
|
||||||
|
trailer
|
||||||
|
<<
|
||||||
|
/Size 11
|
||||||
|
/Root 1 0 R
|
||||||
|
/Info 10 0 R
|
||||||
|
>>
|
||||||
|
|
||||||
|
startxref
|
||||||
|
2714
|
||||||
|
%%EOF
|
Loading…
Reference in a new issue