Skip to content

Commit d2a755f

Browse files
committed
add generator for readme
Signed-off-by: cuisongliu <cuisongliu@qq.com>
1 parent b4606fb commit d2a755f

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
lines changed

generator/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Do() {
6464
goRunData[markdown.Apps] = got.Apps
6565
}
6666

67-
if err = markdown.NewReadme().Generator(syncDir); err != nil {
67+
if err = markdown.NewReadme(syncHub).Generator(syncDir); err != nil {
6868
logger.Fatal("markdown.NewReadme().Generator error %s", err.Error())
6969
return
7070
}

generator/markdown/readme.md.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ limitations under the License.
1717
package markdown
1818

1919
import (
20+
"fmt"
2021
"os"
2122
"path"
23+
"strings"
2224
)
2325

2426
const readmeTemplate = `# Cluster Image Directory
@@ -29,14 +31,24 @@ Welcome to our documentation folder, where we list four distinct types of cluste
2931
- [Sealos Images](./sealos.md)
3032
- [Laf Images](./laf.md)
3133
- [Application Images](./apps.md)
34+
35+
Please navigate to the above links to access the detailed documentation for each image category.
36+
37+
## Image Repository
38+
39+
The images in this documentation are hosted on our dedicated image repository: %s
40+
3241
`
3342

34-
type readme struct{}
43+
type readme struct {
44+
addr string
45+
}
3546

3647
func (r *readme) Generator(dir string) error {
37-
return os.WriteFile(path.Join(dir, "README.md"), []byte(readmeTemplate), 0644)
48+
return os.WriteFile(path.Join(dir, "README.md"), []byte(fmt.Sprintf(readmeTemplate, "`"+r.addr+"`")), 0644)
3849
}
3950

40-
func NewReadme() Template {
41-
return &readme{}
51+
func NewReadme(addr string) Template {
52+
registryArr := strings.Split(addr, "/")
53+
return &readme{addr: registryArr[0]}
4254
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2023 cuisongliu@qq.com.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package markdown
18+
19+
import "testing"
20+
21+
func Test_readme_Generator(t *testing.T) {
22+
type fields struct {
23+
addr string
24+
}
25+
type args struct {
26+
dir string
27+
}
28+
tests := []struct {
29+
name string
30+
fields fields
31+
args args
32+
wantErr bool
33+
}{
34+
{
35+
name: "default",
36+
fields: fields{
37+
addr: "docker.io",
38+
},
39+
args: args{
40+
dir: "../../tmp",
41+
},
42+
wantErr: false,
43+
},
44+
}
45+
for _, tt := range tests {
46+
t.Run(tt.name, func(t *testing.T) {
47+
r := &readme{
48+
addr: tt.fields.addr,
49+
}
50+
if err := r.Generator(tt.args.dir); (err != nil) != tt.wantErr {
51+
t.Errorf("Generator() error = %v, wantErr %v", err, tt.wantErr)
52+
}
53+
})
54+
}
55+
}

tmp/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Cluster Image Directory
2+
3+
Welcome to our documentation folder, where we list four distinct types of cluster images: Rootfs Images, Sealos-related Images, Laf-related Images, and Images for various applications.
4+
5+
- [Rootfs Images](./rootfs.md)
6+
- [Sealos Images](./sealos.md)
7+
- [Laf Images](./laf.md)
8+
- [Application Images](./apps.md)
9+
10+
Please navigate to the above links to access the detailed documentation for each image category.
11+
12+
## Image Repository
13+
14+
The images in this documentation are hosted on our dedicated image repository: `docker.io`
15+

0 commit comments

Comments
 (0)