diff options
author | Pacien | 2013-09-20 19:30:26 +0200 |
---|---|---|
committer | Pacien | 2013-09-20 19:30:26 +0200 |
commit | f8c9b52222ce183676d26f3e953b57572b7d4d3b (patch) | |
tree | bd5be5bf21d58a60fdbecf2263e2036c90adc977 | |
parent | 4cf35e639fb30843e50df44bf992ecf14c3b487a (diff) | |
download | foldaweb-f8c9b52222ce183676d26f3e953b57572b7d4d3b.tar.gz |
Add ability to hide folders in the output
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | main.go | 15 |
2 files changed, 14 insertions, 2 deletions
@@ -40,6 +40,7 @@ You can also pass custom settings via command line arguments: | |||
40 | -sourceDir="./source": Path to the source directory. | 40 | -sourceDir="./source": Path to the source directory. |
41 | -outputDir="./out": Path to the output directory. | 41 | -outputDir="./out": Path to the output directory. |
42 | -parsableExts="html, txt, md": Parsable file extensions separated by commas. | 42 | -parsableExts="html, txt, md": Parsable file extensions separated by commas. |
43 | -skipPrefix="_": Folders with this prefix will be hidden in the output. | ||
43 | -saveAs="index.html": Save compiled files as named. | 44 | -saveAs="index.html": Save compiled files as named. |
44 | -startWith="index": Name without extension of the first file that will by parsed. | 45 | -startWith="index": Name without extension of the first file that will by parsed. |
45 | -wordSeparator="-": Word separator used to replace spaces in URLs. | 46 | -wordSeparator="-": Word separator used to replace spaces in URLs. |
@@ -39,6 +39,7 @@ type generator struct { | |||
39 | sourceDir, outputDir string | 39 | sourceDir, outputDir string |
40 | startWith, saveAs string | 40 | startWith, saveAs string |
41 | wordSeparator string | 41 | wordSeparator string |
42 | skipPrefix string | ||
42 | parsableExts []string | 43 | parsableExts []string |
43 | 44 | ||
44 | // go routine sync | 45 | // go routine sync |
@@ -69,6 +70,7 @@ func newGenerator() (g generator) { | |||
69 | flag.StringVar(&g.startWith, "startWith", "index", "Name without extension of the first file that will by parsed.") | 70 | flag.StringVar(&g.startWith, "startWith", "index", "Name without extension of the first file that will by parsed.") |
70 | flag.StringVar(&g.saveAs, "saveAs", "index.html", "Save compiled files as named.") | 71 | flag.StringVar(&g.saveAs, "saveAs", "index.html", "Save compiled files as named.") |
71 | flag.StringVar(&g.wordSeparator, "wordSeparator", "-", "Word separator used to replace spaces in URLs.") | 72 | flag.StringVar(&g.wordSeparator, "wordSeparator", "-", "Word separator used to replace spaces in URLs.") |
73 | flag.StringVar(&g.skipPrefix, "skipPrefix", "_", "Folders with this prefix will be hidden in the output.") | ||
72 | var parsableExts string | 74 | var parsableExts string |
73 | flag.StringVar(&parsableExts, "parsableExts", "html, txt, md", "Parsable file extensions separated by commas.") | 75 | flag.StringVar(&parsableExts, "parsableExts", "html, txt, md", "Parsable file extensions separated by commas.") |
74 | 76 | ||
@@ -94,7 +96,15 @@ func (g *generator) sourcePath(filePath string) string { | |||
94 | } | 96 | } |
95 | 97 | ||
96 | func (g *generator) outputPath(filePath string) string { | 98 | func (g *generator) outputPath(filePath string) string { |
97 | return path.Join(g.outputDir, g.sanitizePath(filePath)) | 99 | pathElements := strings.Split(filePath, "/") |
100 | var finalFilePath string | ||
101 | for _, element := range pathElements { | ||
102 | if !strings.HasPrefix(element, g.skipPrefix) { | ||
103 | finalFilePath = path.Join(finalFilePath, element) | ||
104 | } | ||
105 | } | ||
106 | fmt.Println(finalFilePath) | ||
107 | return path.Join(g.outputDir, g.sanitizePath(finalFilePath)) | ||
98 | } | 108 | } |
99 | 109 | ||
100 | func (g *generator) isFileParsable(fileName string) bool { | 110 | func (g *generator) isFileParsable(fileName string) bool { |
@@ -191,7 +201,8 @@ func (g *generator) generate(page page) { | |||
191 | } | 201 | } |
192 | 202 | ||
193 | // Generate the page at the current directory | 203 | // Generate the page at the current directory |
194 | if containsParsableFiles { | 204 | _, currentDir := path.Split(currentDirPath) |
205 | if containsParsableFiles && !strings.HasPrefix(currentDir, g.skipPrefix) { | ||
195 | page.body = []byte(mustache.Render(string(g.mergeParts(page.parts)), g.contextualize(page))) | 206 | page.body = []byte(mustache.Render(string(g.mergeParts(page.parts)), g.contextualize(page))) |
196 | 207 | ||
197 | err := fcmd.WriteFile(g.outputPath(path.Join(page.dirPath, g.saveAs)), page.body) | 208 | err := fcmd.WriteFile(g.outputPath(path.Join(page.dirPath, g.saveAs)), page.body) |