mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
027f697fdf
Nuke pre-generation. This may come back in the form of a more general caching layer at some later stage. Nuke index generation. This should likely be rethought and re-implemented.
45 lines
1,007 B
Go
45 lines
1,007 B
Go
package markdown
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
// JSONMetadataParser is the MetadataParser for JSON
|
|
type JSONMetadataParser struct {
|
|
metadata Metadata
|
|
}
|
|
|
|
// Parse the metadata
|
|
func (j *JSONMetadataParser) Parse(b []byte) ([]byte, error) {
|
|
b, markdown, err := extractMetadata(j, b)
|
|
if err != nil {
|
|
return markdown, err
|
|
}
|
|
m := make(map[string]interface{})
|
|
|
|
// Read the preceding JSON object
|
|
decoder := json.NewDecoder(bytes.NewReader(b))
|
|
if err := decoder.Decode(&m); err != nil {
|
|
return markdown, err
|
|
}
|
|
j.metadata.load(m)
|
|
|
|
return markdown, nil
|
|
}
|
|
|
|
// Metadata returns parsed metadata. It should be called
|
|
// only after a call to Parse returns without error.
|
|
func (j *JSONMetadataParser) Metadata() Metadata {
|
|
return j.metadata
|
|
}
|
|
|
|
// Opening returns the opening identifier JSON metadata
|
|
func (j *JSONMetadataParser) Opening() []byte {
|
|
return []byte("{")
|
|
}
|
|
|
|
// Closing returns the closing identifier JSON metadata
|
|
func (j *JSONMetadataParser) Closing() []byte {
|
|
return []byte("}")
|
|
}
|