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.
41 lines
924 B
Go
41 lines
924 B
Go
package markdown
|
|
|
|
import (
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
// YAMLMetadataParser is the MetadataParser for YAML
|
|
type YAMLMetadataParser struct {
|
|
metadata Metadata
|
|
}
|
|
|
|
// Parse the metadata
|
|
func (y *YAMLMetadataParser) Parse(b []byte) ([]byte, error) {
|
|
b, markdown, err := extractMetadata(y, b)
|
|
if err != nil {
|
|
return markdown, err
|
|
}
|
|
|
|
m := make(map[string]interface{})
|
|
if err := yaml.Unmarshal(b, &m); err != nil {
|
|
return markdown, err
|
|
}
|
|
y.metadata.load(m)
|
|
return markdown, nil
|
|
}
|
|
|
|
// Metadata returns parsed metadata. It should be called
|
|
// only after a call to Parse returns without error.
|
|
func (y *YAMLMetadataParser) Metadata() Metadata {
|
|
return y.metadata
|
|
}
|
|
|
|
// Opening returns the opening identifier YAML metadata
|
|
func (y *YAMLMetadataParser) Opening() []byte {
|
|
return []byte("---")
|
|
}
|
|
|
|
// Closing returns the closing identifier YAML metadata
|
|
func (y *YAMLMetadataParser) Closing() []byte {
|
|
return []byte("---")
|
|
}
|