@@ -94,6 +94,21 @@ func getValueFromSource(source string, pattern *regexp.Regexp) string {
94
94
return ""
95
95
}
96
96
97
+ func getArticles (files []os.FileInfo , postsDir string , entryType int ) []sourceFile {
98
+ var articles []sourceFile
99
+
100
+ for _ , postFile := range files {
101
+ name := postFile .Name ()
102
+ ext := name [len (name )- 3 :]
103
+ if ext == ".md" {
104
+ data := parseSourceFile (filepath .Join (postsDir , name ), entryType )
105
+ articles = append (articles , data )
106
+ }
107
+ }
108
+
109
+ return articles
110
+ }
111
+
97
112
func parseSourceFile (path string , entryType int ) sourceFile {
98
113
f , _ := ioutil .ReadFile (path )
99
114
source := string (f )
@@ -206,6 +221,21 @@ func generateArticleHtml(project string, theme string, templateFile string, data
206
221
output = strings .Replace (output , "{{#include " + templateName + "}}" , templateContent , - 1 )
207
222
}
208
223
224
+ extraPath := regexp .MustCompile ("{{#include (.+)}}" )
225
+
226
+ matches := extraPath .FindAllStringSubmatch (output , - 1 )
227
+
228
+ for _ , match := range matches {
229
+ path := filepath .Join (project , "source" , match [1 ])
230
+ f , err := ioutil .ReadFile (path )
231
+
232
+ if err != nil {
233
+ continue
234
+ }
235
+
236
+ output = strings .Replace (output , match [0 ], string (f ), - 1 )
237
+ }
238
+
209
239
for _ , article := range articles {
210
240
output = strings .Replace (output , "{{@" + article .slug + "}}" , createLink (article ), - 1 )
211
241
}
@@ -361,17 +391,10 @@ func buildProject(project string, conf *config) {
361
391
templates [templateFile .Name ()] = string (f )
362
392
}
363
393
364
- var articles []sourceFile
394
+ postsArticles := getArticles (postsFiles , postsDir , POST )
395
+ pagesArticles := getArticles (pagesFiles , pagesDir , PAGE )
365
396
366
- for _ , postFile := range postsFiles {
367
- data := parseSourceFile (filepath .Join (postsDir , postFile .Name ()), POST )
368
- articles = append (articles , data )
369
- }
370
-
371
- for _ , pageFile := range pagesFiles {
372
- data := parseSourceFile (filepath .Join (pagesDir , pageFile .Name ()), PAGE )
373
- articles = append (articles , data )
374
- }
397
+ articles := append (postsArticles , pagesArticles ... )
375
398
376
399
indexData := parseSourceFile (filepath .Join (project , "source" , "index.md" ), INDEX )
377
400
articles = append (articles , indexData )
0 commit comments