Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
d1eb2ea9
Commit
d1eb2ea9
authored
Jul 26, 2015
by
Maxime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed metadata variables type:
from map[string]interface{} to map[string]string
parent
453d3eb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
11 deletions
+31
-11
middleware/markdown/metadata.go
middleware/markdown/metadata.go
+27
-7
middleware/markdown/metadata_test.go
middleware/markdown/metadata_test.go
+1
-1
middleware/markdown/process.go
middleware/markdown/process.go
+3
-3
No files found.
middleware/markdown/metadata.go
View file @
d1eb2ea9
...
...
@@ -13,9 +13,9 @@ import (
var
(
parsers
=
[]
MetadataParser
{
&
JSONMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
interface
{}
)}},
&
TOMLMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
interface
{}
)}},
&
YAMLMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
interface
{}
)}},
&
JSONMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
string
)}},
&
TOMLMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
string
)}},
&
YAMLMetadataParser
{
metadata
:
Metadata
{
Variables
:
make
(
map
[
string
]
string
)}},
}
)
...
...
@@ -28,7 +28,7 @@ type Metadata struct {
Template
string
// Variables to be used with Template
Variables
map
[
string
]
interface
{}
Variables
map
[
string
]
string
}
// load loads parsed values in parsedMap into Metadata
...
...
@@ -40,7 +40,7 @@ func (m *Metadata) load(parsedMap map[string]interface{}) {
m
.
Template
,
_
=
template
.
(
string
)
}
if
variables
,
ok
:=
parsedMap
[
"variables"
];
ok
{
m
.
Variables
,
_
=
variables
.
(
map
[
string
]
interface
{}
)
m
.
Variables
,
_
=
variables
.
(
map
[
string
]
string
)
}
}
...
...
@@ -76,6 +76,15 @@ func (j *JSONMetadataParser) Parse(b []byte) ([]byte, error) {
if
err
:=
decoder
.
Decode
(
&
m
);
err
!=
nil
{
return
b
,
err
}
if
vars
,
ok
:=
m
[
"variables"
]
.
(
map
[
string
]
interface
{});
ok
{
vars1
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
vars
{
if
val
,
ok
:=
v
.
(
string
);
ok
{
vars1
[
k
]
=
val
}
}
m
[
"variables"
]
=
vars1
}
j
.
metadata
.
load
(
m
)
...
...
@@ -120,6 +129,15 @@ func (t *TOMLMetadataParser) Parse(b []byte) ([]byte, error) {
if
err
:=
toml
.
Unmarshal
(
b
,
&
m
);
err
!=
nil
{
return
markdown
,
err
}
if
vars
,
ok
:=
m
[
"variables"
]
.
(
map
[
string
]
interface
{});
ok
{
vars1
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
vars
{
if
val
,
ok
:=
v
.
(
string
);
ok
{
vars1
[
k
]
=
val
}
}
m
[
"variables"
]
=
vars1
}
t
.
metadata
.
load
(
m
)
return
markdown
,
nil
}
...
...
@@ -160,10 +178,12 @@ func (y *YAMLMetadataParser) Parse(b []byte) ([]byte, error) {
// convert variables (if present) to map[string]interface{}
// to match expected type
if
vars
,
ok
:=
m
[
"variables"
]
.
(
map
[
interface
{}]
interface
{});
ok
{
vars1
:=
make
(
map
[
string
]
interface
{}
)
vars1
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
vars
{
if
key
,
ok
:=
k
.
(
string
);
ok
{
vars1
[
key
]
=
v
if
val
,
ok
:=
v
.
(
string
);
ok
{
vars1
[
key
]
=
val
}
}
}
m
[
"variables"
]
=
vars1
...
...
middleware/markdown/metadata_test.go
View file @
d1eb2ea9
...
...
@@ -98,7 +98,7 @@ func TestParsers(t *testing.T) {
expected
:=
Metadata
{
Title
:
"A title"
,
Template
:
"default"
,
Variables
:
map
[
string
]
interface
{}
{
"name"
:
"value"
},
Variables
:
map
[
string
]
string
{
"name"
:
"value"
},
}
compare
:=
func
(
m
Metadata
)
bool
{
if
m
.
Title
!=
expected
.
Title
{
...
...
middleware/markdown/process.go
View file @
d1eb2ea9
...
...
@@ -20,13 +20,13 @@ const (
type
MarkdownData
struct
{
middleware
.
Context
Doc
map
[
string
]
interface
{}
Doc
map
[
string
]
string
}
// Process processes the contents of a page in b. It parses the metadata
// (if any) and uses the template (if found).
func
(
md
Markdown
)
Process
(
c
Config
,
requestPath
string
,
b
[]
byte
,
ctx
middleware
.
Context
)
([]
byte
,
error
)
{
var
metadata
=
Metadata
{
Variables
:
make
(
map
[
string
]
interface
{}
)}
var
metadata
=
Metadata
{
Variables
:
make
(
map
[
string
]
string
)}
var
markdown
[]
byte
var
err
error
...
...
@@ -166,7 +166,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte {
}
// Title is first line (length-limited), otherwise filename
title
,
_
:=
metadata
.
Variables
[
"title"
]
.
(
string
)
title
,
_
:=
metadata
.
Variables
[
"title"
]
html
:=
[]
byte
(
htmlTemplate
)
html
=
bytes
.
Replace
(
html
,
[]
byte
(
"{{title}}"
),
[]
byte
(
title
),
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment