Phase 6 part 5, step 2: start a new site
Sites → New site fills an empty Gitea repository with the theme, a hugo.toml in the site's brand and a starter home page: checked that the repository is empty and builds with Hugo, then the first commit is pushed to its default branch. The site joins the profile, and a First pages card builds its Home, About, Contact and product pages with the page builder; About and Contact join the top menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -735,3 +735,55 @@ func hugoError(out string) string {
|
||||
}
|
||||
return pick
|
||||
}
|
||||
|
||||
// InitPush makes the first commit of an empty repository: the files,
|
||||
// committed on branch and pushed. The working copy is left at dir, ready
|
||||
// for Sync. dir must not exist yet.
|
||||
func InitPush(ctx context.Context, r *Repo, files map[string]string, message string) error {
|
||||
if _, err := os.Stat(r.Dir); err == nil {
|
||||
return fmt.Errorf("%s already exists", r.Dir)
|
||||
}
|
||||
if err := os.MkdirAll(r.Dir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
ok := false
|
||||
defer func() {
|
||||
if !ok {
|
||||
os.RemoveAll(r.Dir)
|
||||
}
|
||||
}()
|
||||
if _, err := r.git(ctx, "init", "--quiet", "--initial-branch", r.Branch); err != nil {
|
||||
return err
|
||||
}
|
||||
for rel, body := range files {
|
||||
p, err := r.inside(rel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(p, []byte(body), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
{"add", "-A"},
|
||||
{"commit", "--quiet", "-m", message},
|
||||
{"remote", "add", "origin", r.CloneURL},
|
||||
{"push", "--quiet", "origin", "HEAD:refs/heads/" + r.Branch},
|
||||
{"fetch", "--quiet", "origin"},
|
||||
} {
|
||||
if _, err := r.git(ctx, args...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ok = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildDir builds a Hugo site in dir into a temporary folder, returned for
|
||||
// reading; the caller removes it.
|
||||
func BuildDir(ctx context.Context, dir string) (string, error) {
|
||||
return (&Repo{Dir: dir}).Build(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user