Skip to content

Commit 4836f65

Browse files
committed
add option --readme-index
1 parent ef330e7 commit 4836f65

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: gm_build.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ func buildMd(infile string) {
4242
if infile == "" {
4343
os.Stdout.Write(html)
4444
} else {
45-
outfile := filepath.Join(outdir, infile[:len(infile)-3]+".html")
45+
var outfile string
46+
47+
if readme && strings.ToLower(filepath.Base(infile)) == "readme.md" {
48+
// if it is a README.md file, we want to name it index.html
49+
outfile = filepath.Join(outdir, infile[:len(infile)-9]+"index.html")
50+
} else {
51+
// otherwise we just change the extension
52+
outfile = filepath.Join(outdir, infile[:len(infile)-3]+".html")
53+
}
4654
if os.MkdirAll(filepath.Dir(outfile), os.ModePerm) != nil {
4755
check(err, "Problem to reach/create folder:", filepath.Dir(outfile))
4856
}

Diff for: gm_parameters.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
// build flags
5656
outdir string
5757
inpatterns []string
58+
readme bool
5859

5960
// template flags
6061
css string
@@ -111,6 +112,7 @@ func SetParameters() {
111112
pflag.StringVar(&htmlshell, "html", "", "The html template (file or string).")
112113

113114
pflag.StringVarP(&outdir, "out-dir", "o", "", "The build output folder (created if not already existing, not used when serving).")
115+
pflag.BoolVar(&readme, "readme-index", false, "Compile README.md to index.html (not used when serving).")
114116
pflag.BoolVar(&localmdlinks, "links-md2html", true, "Replace .md with .html in links to local files (not used when serving).")
115117

116118
pflag.BoolVar(&attribute, "gm-attribute", true, "goldmark option: allows to define attributes on some elements.")

0 commit comments

Comments
 (0)