• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 13606558454

01 Mar 2025 04:12PM CUT coverage: 74.172%. Remained the same
13606558454

push

github

web-flow
Fix CI for repo changes (#225)

2375 of 3202 relevant lines covered (74.17%)

48.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.15
/internal/format/hugo.go
1
package format
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "os"
7
        "path"
8
        "strings"
9
        "text/template"
10

11
        "github.com/mlange-42/modo/internal/document"
12
        "github.com/mlange-42/modo/internal/util"
13
)
14

15
const landingPageContentHugo = `---
16
title: Landing page
17
type: docs
18
---
19

20
JSON created by mojo doc should be placed next to this file.
21

22
Additional documentation files go here, too.
23
They will be processed for doc-tests and copied to folder 'site/content'.
24
`
25

26
type Hugo struct{}
27

28
func (f *Hugo) Accepts(files []string) error {
×
29
        return nil
×
30
}
×
31

32
func (f *Hugo) ProcessMarkdown(element any, text string, proc *document.Processor) (string, error) {
1✔
33
        b := strings.Builder{}
1✔
34
        err := proc.Template.ExecuteTemplate(&b, "hugo_front_matter.md", element)
1✔
35
        if err != nil {
1✔
36
                return "", err
×
37
        }
×
38
        b.WriteRune('\n')
1✔
39
        b.WriteString(text)
1✔
40
        return b.String(), nil
1✔
41
}
42

43
func (f *Hugo) WriteAuxiliary(p *document.Package, dir string, proc *document.Processor) error {
×
44
        return nil
×
45
}
×
46

47
func (f *Hugo) ToFilePath(p string, kind string) string {
6✔
48
        if kind == "package" || kind == "module" {
10✔
49
                return path.Join(p, "_index.md")
4✔
50
        }
4✔
51
        return p + ".md"
2✔
52
}
53

54
func (f *Hugo) ToLinkPath(p string, kind string) string {
3✔
55
        p = f.ToFilePath(p, kind)
3✔
56
        return fmt.Sprintf("{{< ref \"%s\" >}}", p)
3✔
57
}
3✔
58

59
func (f *Hugo) Input(in string, sources []document.PackageSource) string {
9✔
60
        return in
9✔
61
}
9✔
62

63
func (f *Hugo) Output(out string) string {
10✔
64
        return path.Join(out, "content")
10✔
65
}
10✔
66

67
func (f *Hugo) GitIgnore(in, out string, sources []document.PackageSource) []string {
5✔
68
        return []string{
5✔
69
                "# files generated by 'mojo doc'",
5✔
70
                fmt.Sprintf("/%s/*.json", in),
5✔
71
                "# files generated by Modo",
5✔
72
                fmt.Sprintf("/%s/%s/", out, "content"),
5✔
73
                "# files generated by Hugo",
5✔
74
                fmt.Sprintf("/%s/%s/", out, "public"),
5✔
75
                fmt.Sprintf("/%s/*.lock", out),
5✔
76
                "# test file generated by Modo",
5✔
77
                "/test/",
5✔
78
        }
5✔
79
}
5✔
80

81
func (f *Hugo) CreateDirs(base, in, out string, sources []document.PackageSource, templ *template.Template) error {
5✔
82
        inDir, outDir := path.Join(base, in), path.Join(base, f.Output(out))
5✔
83
        testDir := path.Join(base, "test")
5✔
84
        if err := util.MkDirs(inDir); err != nil {
5✔
85
                return err
×
86
        }
×
87
        if err := os.WriteFile(path.Join(inDir, "_index.md"), []byte(landingPageContentHugo), 0644); err != nil {
5✔
88
                return err
×
89
        }
×
90
        if err := util.MkDirs(outDir); err != nil {
5✔
91
                return err
×
92
        }
×
93
        if err := util.MkDirs(testDir); err != nil {
5✔
94
                return err
×
95
        }
×
96
        return f.createInitialFiles(base, path.Join(base, out), templ)
5✔
97
}
98

99
func (f *Hugo) createInitialFiles(docDir, hugoDir string, templ *template.Template) error {
5✔
100
        config, err := document.GetGitOrigin(docDir)
5✔
101
        if err != nil {
5✔
102
                return err
×
103
        }
×
104

105
        files := [][]string{
5✔
106
                {"hugo.yaml", "hugo.yaml"},
5✔
107
                {"hugo.mod", "go.mod"},
5✔
108
                {"hugo.sum", "go.sum"},
5✔
109
        }
5✔
110
        for _, f := range files {
20✔
111
                outFile := path.Join(hugoDir, f[1])
15✔
112
                exists, _, err := util.FileExists(outFile)
15✔
113
                if err != nil {
15✔
114
                        return err
×
115
                }
×
116
                if exists {
15✔
117
                        fmt.Printf("WARNING: Hugo file %s already exists, skip creating\n", outFile)
×
118
                        return nil
×
119
                }
×
120
        }
121

122
        for _, f := range files {
20✔
123
                outFile := path.Join(hugoDir, f[1])
15✔
124
                b := bytes.Buffer{}
15✔
125
                if err := templ.ExecuteTemplate(&b, f[0], &config); err != nil {
15✔
126
                        return err
×
127
                }
×
128
                if err := os.WriteFile(outFile, b.Bytes(), 0644); err != nil {
15✔
129
                        return err
×
130
                }
×
131
        }
132
        return nil
5✔
133
}
134

135
func (f *Hugo) Clean(out, tests string) error {
1✔
136
        if err := emptyDir(out); err != nil {
1✔
137
                return err
×
138
        }
×
139
        return emptyDir(tests)
1✔
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc