Simplify admin publishing pipeline

This commit is contained in:
yarnom 2026-06-03 18:18:50 +08:00
parent 13e7e4026d
commit 9186801c7f
37 changed files with 750 additions and 3367 deletions

View file

@ -32,6 +32,13 @@ func run() error {
if err := cfg.Validate(); err != nil {
return err
}
logCloser, err := admin.ConfigureLogging(cfg)
if err != nil {
return err
}
if logCloser != nil {
defer logCloser.Close()
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
@ -49,8 +56,6 @@ func run() error {
return admin.RunMigrations(ctx, db, cfg.MigrationsDir)
case "create-user":
return createUser(ctx, db)
case "import-markdown":
return importMarkdown(ctx, cfg, db)
default:
return fmt.Errorf("unknown command %q", command)
}
@ -75,21 +80,6 @@ func createUser(ctx context.Context, db *pgxpool.Pool) error {
return nil
}
func importMarkdown(ctx context.Context, cfg admin.Config, db *pgxpool.Pool) error {
postsDir := cfg.PostsDir
if len(os.Args) >= 3 {
postsDir = os.Args[2]
}
result, err := admin.NewStore(db).ImportMarkdownPosts(ctx, postsDir)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "imported %d markdown post(s), skipped %d file(s)\n", result.Imported, result.Skipped)
return nil
}
func serve(ctx context.Context, cfg admin.Config, db *pgxpool.Pool) error {
server := &http.Server{
Addr: cfg.Addr,