From 94503e379572d72c7337ff07961f746bb1d3d39f Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 3 Apr 2023 13:01:54 -0400 Subject: [PATCH] use file metadata for edit date rather than git --- main.go | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/main.go b/main.go index b4185b412d0a9b6ea9e984274da14827f89de6d2..755e6be2773a55f927272f13e5850c664eeaf983 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,6 @@ import ( "gioui.org/unit" "gioui.org/widget/material" "github.com/adrg/frontmatter" - "github.com/go-git/go-git/v5" flag "github.com/spf13/pflag" "gopkg.in/yaml.v3" ) @@ -55,7 +54,7 @@ func main() { postTitle, postDate, postContent := getPostInfo(*flagInput) postReadTime := getReadTime(postContent) siteTitle := getSiteTitle() - dateEdited := getGitDate(*flagInput) + dateEdited := getEditDate(*flagInput) collection := fontCollection() @@ -403,33 +402,14 @@ func getSiteTitle() string { return t.Title } -// Get the date the post was last edited -func getGitDate(input string) string { - if _, err := os.Stat(input); os.IsNotExist(err) { - fmt.Println("Error: Input file does not exist") - os.Exit(1) - } - - repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) - if err != nil { - fmt.Println("Error: Could not open git repository") - fmt.Println(err) - os.Exit(1) - } - - commitIter, err := repo.Log(&git.LogOptions{FileName: &input}) - if err != nil { - fmt.Println("Error: Could not get git history") - fmt.Println(err) - os.Exit(1) - } - - commit, err := commitIter.Next() +// Get the date the post was last edited using the file metadata +func getEditDate(input string) string { + fileInfo, err := os.Stat(input) if err != nil { - fmt.Println("Error: Could not get git history") + fmt.Println("Error: Could not get file info") fmt.Println(err) os.Exit(1) } - return commit.Committer.When.Format("2006-01-02") + return fileInfo.ModTime().Format("2006-01-02") }