@@ -289,11 +289,11 @@ func buildContent() {
289
289
buildIndexPage (pages , tagMap )
290
290
}
291
291
292
+ // buildIndexPage creates the main index.md page that is the root of the site
292
293
func buildIndexPage (pages []* Page , tagMap * TagMap ) {
293
294
Info (statusIdxBuild )
294
295
295
296
content := ""
296
- prevPage := & Page {}
297
297
298
298
// Write the tag list into the top of the index
299
299
for _ , tag := range tagMap .SortedTagNames () {
@@ -304,28 +304,12 @@ func buildIndexPage(pages []*Page, tagMap *TagMap) {
304
304
)
305
305
}
306
306
307
- // Write the page list into the middle of the index
308
- // This is sorted by month, in reverse-chronological order
309
- for _ , page := range pages {
310
- if ! page .IsContentPage () {
311
- continue
312
- }
313
-
314
- // This breaks the page list up by month
315
- if prevPage .CreatedMonth () != page .CreatedMonth () {
316
- content += "\n \n "
317
- }
318
-
319
- content += fmt .Sprintf ("* %s\n " , page .Link ())
320
-
321
- prevPage = page
322
- }
323
-
307
+ // Write the page list into the middle of the page
308
+ content += pagesToHTMLUnorderedList (pages )
324
309
content += fmt .Sprintf ("\n " )
325
310
326
311
// Write the footer content into the bottom of the index
327
312
content += fmt .Sprintf ("\n " )
328
- content += fmt .Sprintf ("\n " )
329
313
content += footer ()
330
314
331
315
// And write the file to disk
@@ -339,6 +323,8 @@ func buildIndexPage(pages []*Page, tagMap *TagMap) {
339
323
if err != nil {
340
324
Fail (err )
341
325
}
326
+
327
+ ll .Print (fmt .Sprintf ("%s %s\n " , Blue ("\t ->" ), filePath ))
342
328
}
343
329
344
330
// buildTagPages creates the tag pages, with links to posts tagged with those names
@@ -357,13 +343,8 @@ func buildTagPages(pages []*Page) *TagMap {
357
343
358
344
content := fmt .Sprintf ("## %s\n \n " , tagName )
359
345
360
- for _ , tag := range tagMap .Get (tagName ) {
361
- for _ , page := range tag .Pages {
362
- if page .IsContentPage () {
363
- content += fmt .Sprintf ("* %s\n " , page .Link ())
364
- }
365
- }
366
- }
346
+ // Write the page list into the middle of the page
347
+ content += pagesToHTMLUnorderedList (tagMap .PagesFor (tagName ))
367
348
368
349
// Write the footer content into the bottom of the page
369
350
content += fmt .Sprintf ("\n " )
@@ -456,6 +437,30 @@ func loadPages() []*Page {
456
437
return pages
457
438
}
458
439
440
+ // pagesToHTMLUnorderedList creates the unordered list of page links that appear
441
+ // on the index and tag pages
442
+ func pagesToHTMLUnorderedList (pages []* Page ) string {
443
+ content := ""
444
+ prevPage := & Page {}
445
+
446
+ for _ , page := range pages {
447
+ if ! page .IsContentPage () {
448
+ continue
449
+ }
450
+
451
+ // This breaks the page list up by month
452
+ if prevPage .CreatedMonth () != page .CreatedMonth () {
453
+ content += "\n "
454
+ }
455
+
456
+ content += fmt .Sprintf ("* %s\n " , page .Link ())
457
+
458
+ prevPage = page
459
+ }
460
+
461
+ return content
462
+ }
463
+
459
464
// push pushes up to the remote git repo
460
465
func push () {
461
466
Info (statusRepoPush )
@@ -717,6 +722,23 @@ func (tm *TagMap) Len() int {
717
722
return len (tm .Tags )
718
723
}
719
724
725
+ // PagesFor returns a flattened slice of pages for a given tag name, sorted
726
+ // in reverse-chronological order
727
+ func (tm * TagMap ) PagesFor (tagName string ) []* Page {
728
+ pages := []* Page {}
729
+ tags := tm .Get (tagName )
730
+
731
+ for _ , tag := range tags {
732
+ pages = append (pages , tag .Pages ... )
733
+
734
+ sort .Slice (pages , func (i , j int ) bool {
735
+ return pages [i ].CreatedAt ().After (pages [j ].CreatedAt ())
736
+ })
737
+ }
738
+
739
+ return pages
740
+ }
741
+
720
742
// SortedTagNames returns the tag names in alphabetical order
721
743
func (tm * TagMap ) SortedTagNames () []string {
722
744
tagArr := make ([]string , tm .Len ())
0 commit comments