diff --git a/gm_build.go b/gm_build.go index 8888f0c..a58495a 100644 --- a/gm_build.go +++ b/gm_build.go @@ -42,7 +42,15 @@ func buildMd(infile string) { if infile == "" { os.Stdout.Write(html) } else { - outfile := filepath.Join(outdir, infile[:len(infile)-3]+".html") + var outfile string + + if readme && strings.ToLower(filepath.Base(infile)) == "readme.md" { + // if it is a README.md file, we want to name it index.html + outfile = filepath.Join(outdir, infile[:len(infile)-9]+"index.html") + } else { + // otherwise we just change the extension + outfile = filepath.Join(outdir, infile[:len(infile)-3]+".html") + } if os.MkdirAll(filepath.Dir(outfile), os.ModePerm) != nil { check(err, "Problem to reach/create folder:", filepath.Dir(outfile)) } diff --git a/gm_parameters.go b/gm_parameters.go index b0699ad..8f5ef94 100644 --- a/gm_parameters.go +++ b/gm_parameters.go @@ -55,6 +55,7 @@ var ( // build flags outdir string inpatterns []string + readme bool // template flags css string @@ -111,6 +112,7 @@ func SetParameters() { pflag.StringVar(&htmlshell, "html", "", "The html template (file or string).") pflag.StringVarP(&outdir, "out-dir", "o", "", "The build output folder (created if not already existing, not used when serving).") + pflag.BoolVar(&readme, "readme-index", false, "Compile README.md to index.html (not used when serving).") pflag.BoolVar(&localmdlinks, "links-md2html", true, "Replace .md with .html in links to local files (not used when serving).") pflag.BoolVar(&attribute, "gm-attribute", true, "goldmark option: allows to define attributes on some elements.")