diff options
| author | Fuwn <[email protected]> | 2021-07-19 18:54:23 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-19 18:54:23 +0000 |
| commit | a6189caa2511b3521c9683b4f8b82713bf999b5d (patch) | |
| tree | a57cf70b7ab02e92f7ca55743a9b5a66f35858f2 | |
| parent | refactor(route): replace -1 with ReplaceAll (diff) | |
| download | space-a6189caa2511b3521c9683b4f8b82713bf999b5d.tar.xz space-a6189caa2511b3521c9683b4f8b82713bf999b5d.zip | |
feat(blog): sort blog by article creation dates
| -rw-r--r-- | content/pages/blog/tech/2021-07-15-hello-world.gmi (renamed from content/pages/blog/tech/hello-world.gmi) | 0 | ||||
| -rw-r--r-- | route.go | 27 |
2 files changed, 25 insertions, 2 deletions
diff --git a/content/pages/blog/tech/hello-world.gmi b/content/pages/blog/tech/2021-07-15-hello-world.gmi index de47594..de47594 100644 --- a/content/pages/blog/tech/hello-world.gmi +++ b/content/pages/blog/tech/2021-07-15-hello-world.gmi @@ -22,7 +22,13 @@ func createRoute(route string, template string, content string) { Content: GetContent(content), Quote: utilities.GetRandomQuote(), Hits: database.Get(route), - // SystemInfo: fmt.Sprintf("Host: %s %s, Uptime: %d seconds, Routes: %d", strings.Title(hostInformation.Platform), strings.Title(hostInformation.OS), int64(time.Since(startTime).Seconds()), len(g.Routes())), + /* SystemInfo: fmt.Sprintf( + "Host: %s %s, Uptime: %d seconds, Routes: %d", + strings.Title(hostInformation.Platform), + strings.Title(hostInformation.OS), + int64(time.Since(startTime).Seconds()), + len(g.Routes()), + ), */ Copyright: utilities.GetCopyright(), }) }) @@ -73,10 +79,27 @@ func createBlogRoute(baseRoute string, postPath string, name string) { contents, _ := contentFilesystem.ReadDir("content/" + postPath) files := fmt.Sprintf("# %s (%d)\n\n", strings.ToUpper(name), len(contents)) + + // Reverse contents so that the oldest file is at the bottom + // + // https://stackoverflow.com/a/19239850 + for i, j := 0, len(contents)-1; i < j; i, j = i+1, j-1 { + contents[i], contents[j] = contents[j], contents[i] + } + // Could be useful later: + // https://golangcode.com/sorting-an-array-of-numeric-items/ for _, file := range contents { + // Temporary, until it causes problems... fileNameNoExt := strings.ReplaceAll(file.Name(), ".gmi", "") - files += fmt.Sprintf("=> %s %s\n", baseRoute+"/"+fileNameNoExt, fileNameNoExt) + fileDate := fileNameNoExt[0:10] + fileNameNoExtTitle := strings.Title(fileNameNoExt[11:]) + + files += fmt.Sprintf( + "=> %s %s\n", + baseRoute+"/"+fileNameNoExt, + fmt.Sprintf("%s %s", fileDate, fileNameNoExtTitle), + ) createRoute(baseRoute+"/"+fileNameNoExt, "default.gmi", "pages"+baseRoute+"/"+file.Name()) } files = utilities.TrimLastChar(files) |