summaryrefslogtreecommitdiff
path: root/main.go
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2025-09-03 22:22:44 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2025-09-03 22:22:44 +0700
commit01e74276577b46dcebb8917f6d23ec150a70ad70 (patch)
treed56610b8d6dd99fac17122c463a7b663039db38b /main.go
parent007368ef290d935312a5cd2883b07cc53c38cea3 (diff)
downloadarticlator-01e74276577b46dcebb8917f6d23ec150a70ad70.tar.gz
articlator-01e74276577b46dcebb8917f6d23ec150a70ad70.zip
feat: new draft and prod mode
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/main.go b/main.go
index 7c50824..04b0a4d 100644
--- a/main.go
+++ b/main.go
@@ -25,7 +25,7 @@ func main() {
slog.SetLogLoggerLevel(cfg.LogLevel)
slog.Info("starting metadata extractor...")
- storageClient, err := storage.NewStorageClientMap[cfg.Storage.Type](&cfg.Storage)
+ storageClient, err := storage.NewStorageClientMap[cfg.Storage.Type](&cfg.Storage, &cfg.DraftMode)
if err != nil {
slog.Error("fail to initialize input client", slog.String("error", err.Error()))
os.Exit(1)
@@ -52,15 +52,15 @@ func main() {
go func(index int, inputName string) {
defer wg.Done()
defer func() { <-semaphore }()
- if !storageClient.FileHasChanged(file) {
- generalLogger.Debug("skipped a file because it has not changed since last parse", slog.String("file", file))
+ if cfg.DraftMode.Enabled && !storageClient.CompareDraftAndProd(inputName) {
+ generalLogger.Debug("skip a draft because prod object is identical to it", slog.String("file", inputName))
return
}
- generalLogger.Debug("processing a file", slog.String("file", file))
+ generalLogger.Debug("processing a file", slog.String("file", inputName))
- reader, sz, err := storageClient.GetReader(file)
+ reader, sz, err := storageClient.GetReader(inputName)
if err != nil {
- generalLogger.Warn("fail to get reader for a file", slog.String("file", file), slog.String("error", err.Error()))
+ generalLogger.Warn("fail to get reader for a file", slog.String("file", inputName), slog.String("error", err.Error()))
return
}
defer reader.Close()
@@ -68,27 +68,27 @@ func main() {
content := make([]byte, sz)
ln, err := reader.Read(content)
if err != nil {
- generalLogger.Warn("fail to read content from a file", slog.String("file", file), slog.String("error", err.Error()))
+ generalLogger.Warn("fail to read content from a file", slog.String("file", inputName), slog.String("error", err.Error()))
return
}
generalLogger.Debug("read content from a file",
- slog.String("file", file),
+ slog.String("file", inputName),
slog.Int64("expected_size", sz),
slog.Int("output_size", ln))
metadata, _, err := frontmatter.ParseFrontmatter(content)
if err != nil {
- generalLogger.Warn("fail to parse frontmatter of a file", slog.String("file", file), slog.String("error", err.Error()))
+ generalLogger.Warn("fail to parse frontmatter of a file", slog.String("file", inputName), slog.String("error", err.Error()))
return
}
if metadata == nil {
- generalLogger.Info("skip a file due to it not having metadata", slog.String("file", file))
+ generalLogger.Info("skip a file due to it not having metadata", slog.String("file", inputName))
return
}
- if err = storageClient.WriteMetadata(file, metadata); err != nil {
- generalLogger.Warn("fail to write metadata to a file", slog.String("file", file), slog.String("error", err.Error()))
+ if err = storageClient.WriteMetadata(inputName, metadata); err != nil {
+ generalLogger.Warn("fail to write metadata to a file", slog.String("file", inputName), slog.String("error", err.Error()))
}
}(i, file)
}