generated from templates/go-generic
WIP: New Flow website built with Nanoc and Mage #1
4 changed files with 40 additions and 30 deletions
|
@ -9,8 +9,7 @@
|
|||
<div id="sidebar">
|
||||
<h2>Projects</h2>
|
||||
<ul>
|
||||
<li><a href="/projects/spruce/">Spruce</a></li>
|
||||
<li><a href="/projects/pelican/">Pelican</a></li>
|
||||
<%= project_list %>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
|
9
flow/lib/project_list.rb
Normal file
9
flow/lib/project_list.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
def project_list
|
||||
out = +''
|
||||
|
||||
@config[:projects].each do |project|
|
||||
out << "<li><a href=\"/projects/#{project[:name]}/\">#{project[:name]}</a></li>\n"
|
||||
end
|
||||
|
||||
out
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue