From 92ced80c603378f6be2c08eafb08145693d5f0cc Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 2 Apr 2024 17:15:54 +0100 Subject: [PATCH] Fix import task --- Taskfile.yml | 6 ++++-- data/interactions/notes/twitter/5653892614.json | 1 + tools/{import/omnivore => }/.gitignore | 0 tools/import/omnivore/main.go | 13 +++++++++++-- tools/import/webmentionio/.gitignore | 1 - 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 data/interactions/notes/twitter/5653892614.json rename tools/{import/omnivore => }/.gitignore (100%) delete mode 100644 tools/import/webmentionio/.gitignore diff --git a/Taskfile.yml b/Taskfile.yml index 61ad2229..9843095a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -24,5 +24,7 @@ tasks: - hugo --cacheDir /tmp/hugo/cache --gc --minify --baseURL "${DOMAIN}" - npm_config_yes=true npx pagefind@latest import: - cmds: - - cd ./tools/import/omnivore && go run . + dir: tools/ + cmds: + - go run ./import/omnivore ../ + - go run ./import/webmentionio diff --git a/data/interactions/notes/twitter/5653892614.json b/data/interactions/notes/twitter/5653892614.json new file mode 100644 index 00000000..ec8a5996 --- /dev/null +++ b/data/interactions/notes/twitter/5653892614.json @@ -0,0 +1 @@ +{"interactions":[{"guid":"webmentions.io#1799435","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112183980587832116#favorited-by-112139367222387976","author":{"name":"shellsharks","url":"https://shellsharks.social/@shellsharks"},"timestamp":"2024-03-30T12:41:28Z"},{"guid":"webmentions.io#1799436","emoji":"💬","url":"https://hachyderm.io/@byjp/112183987371889835","comment":"Perhaps, now my generation lives in a world where more of us can connect with the informality and emotion of our younger selves, we’ll see these digital generations have more empathy for the generations after us than has been easy for those that went before us?","author":{"name":"JP","url":"https://hachyderm.io/@byjp"},"timestamp":"2024-03-30T09:43:19Z"}]} diff --git a/tools/import/omnivore/.gitignore b/tools/.gitignore similarity index 100% rename from tools/import/omnivore/.gitignore rename to tools/.gitignore diff --git a/tools/import/omnivore/main.go b/tools/import/omnivore/main.go index 9feeaf9d..d16d7710 100644 --- a/tools/import/omnivore/main.go +++ b/tools/import/omnivore/main.go @@ -15,6 +15,7 @@ import ( "strings" "time" + "github.com/joho/godotenv" "gopkg.in/yaml.v2" ) @@ -28,6 +29,11 @@ var ignoreLabels = []string{ } func main() { + if err := godotenv.Load(); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + apiKey, ok := os.LookupEnv("OMNIVORE_API_KEY") if !ok || len(apiKey) == 0 { fmt.Fprint(os.Stderr, "OMNIVORE_API_KEY is not set") @@ -42,8 +48,9 @@ func main() { outputDir := path.Join(rootDir, "content/bookmarks") if !isDir(outputDir) { fmt.Printf( - "Usage: %s [directory]\n 'directory' should be the root of your hugo blog (default: ./)\n", + "Usage: %s [directory]\n [directory] should be the root of your hugo blog (current: %s)\n", path.Base(os.Args[0]), + rootDir, ) os.Exit(1) } @@ -91,7 +98,9 @@ func outputArticle(article Article, outputDir string) error { fm.Date = article.BookmarkDate.Format(time.RFC3339) } - fm.Title = article.Title + if len(fm.Title) == 0 { + fm.Title = article.Title + } fm.BookmarkOf = article.OriginalURL fm.Tags = removeDupes(append(fm.Tags, article.Tags...)) diff --git a/tools/import/webmentionio/.gitignore b/tools/import/webmentionio/.gitignore deleted file mode 100644 index 2eea525d..00000000 --- a/tools/import/webmentionio/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.env \ No newline at end of file