@@ -14,6 +14,7 @@ import (
14
14
"code.gitea.io/gitea/modules/markup/markdown"
15
15
"code.gitea.io/gitea/modules/setting"
16
16
api "code.gitea.io/gitea/modules/structs"
17
+ "code.gitea.io/gitea/modules/util"
17
18
18
19
"gopkg.in/yaml.v2"
19
20
)
@@ -95,14 +96,27 @@ func unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
95
96
}{}
96
97
97
98
if typ := it .Type (); typ == api .IssueTemplateTypeMarkdown {
98
- templateBody , err := markdown .ExtractMetadata (string (content ), it )
99
- if err != nil {
100
- return nil , err
101
- }
102
- it .Content = templateBody
103
- if it .About == "" {
104
- if _ , err := markdown .ExtractMetadata (string (content ), compatibleTemplate ); err == nil && compatibleTemplate .About != "" {
105
- it .About = compatibleTemplate .About
99
+ if templateBody , err := markdown .ExtractMetadata (string (content ), it ); err != nil {
100
+ // The only thing we know here is that we can't extract metadata from the content,
101
+ // it's hard to tell if metadata doesn't exist or metadata isn't valid.
102
+ // There's an example template:
103
+ //
104
+ // ---
105
+ // # Title
106
+ // ---
107
+ // Content
108
+ //
109
+ // It could be a valid markdown with two horizontal lines, or an invalid markdown with wrong metadata.
110
+
111
+ it .Content = string (content )
112
+ it .Name = filepath .Base (it .FileName )
113
+ it .About , _ = util .SplitStringAtByteN (it .Content , 80 )
114
+ } else {
115
+ it .Content = templateBody
116
+ if it .About == "" {
117
+ if _ , err := markdown .ExtractMetadata (string (content ), compatibleTemplate ); err == nil && compatibleTemplate .About != "" {
118
+ it .About = compatibleTemplate .About
119
+ }
106
120
}
107
121
}
108
122
} else if typ == api .IssueTemplateTypeYaml {
0 commit comments