65 lines
1 KiB
Go
65 lines
1 KiB
Go
package progdoc
|
|
|
|
import (
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type Option struct {
|
|
configSitemap func(sm *siteMap) error
|
|
}
|
|
|
|
func Meta(meta SiteMeta) Option {
|
|
return Option{
|
|
configSitemap: func(sm *siteMap) error {
|
|
sm.Meta = &meta
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
type PathBuilder struct {
|
|
path string
|
|
}
|
|
|
|
func StaticFile(path, file string) Option {
|
|
return Option{
|
|
configSitemap: func(sm *siteMap) error {
|
|
_, err := os.Stat(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
absName, err := filepath.Abs(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Printf("Static '%s' -> %s", path, file)
|
|
sm.Static = append(sm.Static, siteStatic{
|
|
Path: path,
|
|
Source: fileStaticSource{
|
|
Filename: absName,
|
|
},
|
|
})
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
func inferSourceFromFilename(fname string) (pageSource, error) {
|
|
absName, err := filepath.Abs(fname)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if strings.HasSuffix(absName, ".md") {
|
|
return mdSource{MDFile: absName}, nil
|
|
}
|
|
return nil, errors.New("unsupported file type")
|
|
}
|