MCPcopy
hub / github.com/cli/cli / ExtractTitle

Function ExtractTitle

pkg/githubtemplate/github_template.go:102–114  ·  view source on GitHub ↗

ExtractTitle returns the title of the template from YAML front-matter

(filePath string)

Source from the content-addressed store, hash-verified

100
101// ExtractTitle returns the title of the template from YAML front-matter
102func ExtractTitle(filePath string) string {
103 contents, err := os.ReadFile(filePath)
104 frontmatterBoundaries := detectFrontmatter(contents)
105 if err == nil && frontmatterBoundaries[0] == 0 {
106 templateData := struct {
107 Title string
108 }{}
109 if err := yaml.Unmarshal(contents[0:frontmatterBoundaries[1]], &templateData); err == nil && templateData.Title != "" {
110 return templateData.Title
111 }
112 }
113 return ""
114}
115
116// ExtractContents returns the template contents without the YAML front-matter
117func ExtractContents(filePath string) []byte {

Callers 2

TitleMethod · 0.92
TestExtractTitleFunction · 0.85

Calls 1

detectFrontmatterFunction · 0.85

Tested by 1

TestExtractTitleFunction · 0.68