ExtractName returns the name of the template from YAML front-matter
(filePath string)
| 85 | |
| 86 | // ExtractName returns the name of the template from YAML front-matter |
| 87 | func ExtractName(filePath string) string { |
| 88 | contents, err := os.ReadFile(filePath) |
| 89 | frontmatterBoundaries := detectFrontmatter(contents) |
| 90 | if err == nil && frontmatterBoundaries[0] == 0 { |
| 91 | templateData := struct { |
| 92 | Name string |
| 93 | }{} |
| 94 | if err := yaml.Unmarshal(contents[0:frontmatterBoundaries[1]], &templateData); err == nil && templateData.Name != "" { |
| 95 | return templateData.Name |
| 96 | } |
| 97 | } |
| 98 | return path.Base(filePath) |
| 99 | } |
| 100 | |
| 101 | // ExtractTitle returns the title of the template from YAML front-matter |
| 102 | func ExtractTitle(filePath string) string { |