// Copyright (c) 2023 Nicolas Paul All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"html/template"
"io"
)
// indextmpl is the HTML template to generate for the index page of the static
// site (route "/").
var indextmpl = template.Must(
template.New("index").Parse(`
{{.Hostname}}
{{.Hostname}}
{{range .Paths}}- {{.}}
{{end}}
`),
)
// executeIndex generates the Index template using the given variables.
// paths is a list of import path (containing both hostname and prefix).
func executeIndex(o io.Writer, hostname string, paths []string) error {
return indextmpl.Execute(o, struct {
Hostname string
Paths []string
}{
Hostname: hostname,
Paths: paths,
})
}
// pathtmpl is the HTML template to generate for the page of a module.
var pathtmpl = template.Must(
template.New("path").Parse(`
{{.Prefix}}
{{.Prefix}}
`),
)
// executePath generates the path template using the given variables.
func executePath(
o io.Writer,
hostname string,
prefix string,
vcs VCS,
repo string,
dir string,
file string,
) error {
return pathtmpl.Execute(o, struct {
Prefix string
Repo string
Dir string
File string
Vcs VCS
}{
Prefix: fmt.Sprintf("%s/%s", hostname, prefix),
Repo: repo,
Vcs: vcs,
Dir: dir,
File: file,
})
}