Switch to one file per mod and added additional options for go parts
This commit is contained in:
parent
30f42db6a6
commit
1d52b0784c
|
|
@ -16,12 +16,39 @@ type goFilePart struct {
|
||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g goFilePart) FirstMeta(name string) string {
|
||||||
|
for _, meta := range g.Meta {
|
||||||
|
if meta.Name == name {
|
||||||
|
return meta.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type goFileDocs struct {
|
type goFileDocs struct {
|
||||||
Parts []goFilePart
|
Parts []goFilePart
|
||||||
}
|
}
|
||||||
|
|
||||||
type allGoFileDocs struct {
|
func (g goFileDocs) PartsWithMeta(name string) []goFilePart {
|
||||||
Files []goFileDocs
|
var parts []goFilePart
|
||||||
|
for _, part := range g.Parts {
|
||||||
|
if part.FirstMeta(name) != "" {
|
||||||
|
parts = append(parts, part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g goFileDocs) FirstPartWithMeta(name string) goFilePart {
|
||||||
|
parts := g.PartsWithMeta(name)
|
||||||
|
if len(parts) > 0 {
|
||||||
|
return parts[0]
|
||||||
|
}
|
||||||
|
return goFilePart{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g goFileDocs) HasDocs() bool {
|
||||||
|
return len(g.Parts) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGoFileDocs(r io.Reader) (goFileDocs, error) {
|
func parseGoFileDocs(r io.Reader) (goFileDocs, error) {
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,6 @@ func (pb PathBuilder) File(file string) Option {
|
||||||
func (pb PathBuilder) GoFiles(dir, templateFile string) Option {
|
func (pb PathBuilder) GoFiles(dir, templateFile string) Option {
|
||||||
return Option{
|
return Option{
|
||||||
configSitemap: func(sm *siteMap) error {
|
configSitemap: func(sm *siteMap) error {
|
||||||
var allDocs allGoFileDocs
|
|
||||||
|
|
||||||
tmplBytes, err := os.ReadFile(templateFile)
|
tmplBytes, err := os.ReadFile(templateFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -57,6 +55,11 @@ func (pb PathBuilder) GoFiles(dir, templateFile string) Option {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !info.IsDir() && info.Mode().IsRegular() {
|
if !info.IsDir() && info.Mode().IsRegular() {
|
||||||
|
relPath, err := filepath.Rel(dir, strings.TrimSuffix(path, filepath.Ext(path)))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
absName, err := filepath.Abs(path)
|
absName, err := filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -72,20 +75,23 @@ func (pb PathBuilder) GoFiles(dir, templateFile string) Option {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
allDocs.Files = append(allDocs.Files, goFileDoc)
|
|
||||||
|
if !goFileDoc.HasDocs() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sm.Pages = append(sm.Pages, sitePage{
|
||||||
|
Path: relPath,
|
||||||
|
Source: mdTemplateSource{
|
||||||
|
Template: tmpl,
|
||||||
|
Data: goFileDoc,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.Pages = append(sm.Pages, sitePage{
|
|
||||||
Path: pb.path,
|
|
||||||
Source: mdTemplateSource{
|
|
||||||
Template: tmpl,
|
|
||||||
Data: allDocs,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue