diff --git a/flow/layouts/projects.html b/flow/layouts/projects.html index 7e550c1..ef78f46 100644 --- a/flow/layouts/projects.html +++ b/flow/layouts/projects.html @@ -9,8 +9,7 @@ diff --git a/flow/lib/project_list.rb b/flow/lib/project_list.rb new file mode 100644 index 0000000..8a3b4e4 --- /dev/null +++ b/flow/lib/project_list.rb @@ -0,0 +1,9 @@ +def project_list + out = +'' + + @config[:projects].each do |project| + out << "
  • #{project[:name]}
  • \n" + end + + out +end diff --git a/flow/nanoc.yaml b/flow/nanoc.yaml index 78c0c26..48af89d 100644 --- a/flow/nanoc.yaml +++ b/flow/nanoc.yaml @@ -28,11 +28,11 @@ environments: base_url: https://dananglin.me.uk projects: - pelican: - repository_url: https://codeflow.dananglin.me.uk/apollo/pelican.git - branch: flow-website-support - documentation_root: docs - spruce: - repository_url: https://codeflow.dananglin.me.uk/apollo/spruce.git - branch: flow-website-support - documentation_root: docs +- name: pelican + repository_url: https://codeflow.dananglin.me.uk/apollo/pelican.git + branch: flow-website-support + documentation_root: docs +- name: spruce + repository_url: https://codeflow.dananglin.me.uk/apollo/spruce.git + branch: flow-website-support + documentation_root: docs diff --git a/magefiles/projects.go b/magefiles/projects.go index cb47602..9784909 100644 --- a/magefiles/projects.go +++ b/magefiles/projects.go @@ -16,10 +16,11 @@ import ( ) type projectsConfig struct { - Projects map[string]project `yaml:"projects"` + Projects []project `yaml:"projects"` } type project struct { + Name string `yaml:"name"` RepositoryURL string `yaml:"repository_url"` Commit string `yaml:"commit"` Tag string `yaml:"tag"` @@ -42,16 +43,16 @@ func Projects() error { return fmt.Errorf("unable to parse the projects configuration; %w", err) } - for name, details := range projects.Projects { - clonedDirectory, err := cloneProject(name, details) + for _, project := range projects.Projects { + clonedDirectory, err := cloneProject(project) if err != nil { - return fmt.Errorf("unable to clone %q; %w", name, err) + return fmt.Errorf("unable to clone %q; %w", project.Name, err) } - documentationDir := filepath.Join(clonedDirectory, details.DocumentationRoot) + documentationDir := filepath.Join(clonedDirectory, project.DocumentationRoot) - if err := copyDocumentation(documentationDir, name); err != nil { - return fmt.Errorf("unable to copy the documentation from %q; %w", name, err) + if err := copyDocumentation(documentationDir, project.Name); err != nil { + return fmt.Errorf("unable to copy the documentation from %q; %w", project.Name, err) } } @@ -77,20 +78,20 @@ func parseProjectsConfig() (projectsConfig, error) { return config, nil } -func cloneProject(projectName string, projectDetails project) (string, error) { - slog.Info("Cloning the project repository.", "repository", projectDetails.RepositoryURL) +func cloneProject(p project) (string, error) { + slog.Info("Cloning the project repository.", "repository", p.RepositoryURL) var ( reference plumbing.ReferenceName singleBranch bool depth int ) - if projectDetails.Tag != "" { - reference = plumbing.NewTagReferenceName(projectDetails.Tag) + if p.Tag != "" { + reference = plumbing.NewTagReferenceName(p.Tag) singleBranch = false depth = 1 - } else if projectDetails.Branch != "" { - reference = plumbing.NewBranchReferenceName(projectDetails.Branch) + } else if p.Branch != "" { + reference = plumbing.NewBranchReferenceName(p.Branch) singleBranch = true depth = 1 } else { @@ -99,13 +100,13 @@ func cloneProject(projectName string, projectDetails project) (string, error) { depth = 0 } - cloneDir, err := os.MkdirTemp("", projectName) + cloneDir, err := os.MkdirTemp("", p.Name) if err != nil { return "", fmt.Errorf("unable to create the temporary clone directory; %w", err) } options := git.CloneOptions{ - URL: projectDetails.RepositoryURL, + URL: p.RepositoryURL, Progress: nil, ReferenceName: reference, SingleBranch: singleBranch, @@ -117,7 +118,7 @@ func cloneProject(projectName string, projectDetails project) (string, error) { return "", fmt.Errorf("unable to clone the repository; %w", err) } - if projectDetails.Commit == "" { + if p.Commit == "" { return cloneDir, nil } @@ -127,12 +128,12 @@ func cloneProject(projectName string, projectDetails project) (string, error) { } checkoutOptions := git.CheckoutOptions{ - Hash: plumbing.NewHash(projectDetails.Commit), + Hash: plumbing.NewHash(p.Commit), Create: false, } if err := worktree.Checkout(&checkoutOptions); err != nil { - return "", fmt.Errorf("unable to checkout %q; %w", projectDetails.Commit, err) + return "", fmt.Errorf("unable to checkout %q; %w", p.Commit, err) } slog.Info("Project cloned successfully.") @@ -141,7 +142,9 @@ func cloneProject(projectName string, projectDetails project) (string, error) { } func copyDocumentation(inputDirectory, projectName string) error { - slog.Info("Copying documentation.", "project", projectName, "directory", inputDirectory) + outputDirectory := filepath.Join(projectsDirectory, projectName) + + slog.Info("Copying documentation.", "project", projectName, "source", inputDirectory, "destination", outputDirectory) defer os.RemoveAll(inputDirectory) @@ -154,7 +157,6 @@ func copyDocumentation(inputDirectory, projectName string) error { return nil } - outputDirectory := filepath.Join(projectsDirectory, projectName) if err := os.MkdirAll(outputDirectory, 0o750); err != nil { return fmt.Errorf("unable to create %q; %w", outputDirectory, err)