Skip to content

Commit aed2b35

Browse files
committed
return empty when not on filesystem closes #113
1 parent a87ad79 commit aed2b35

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

quiki.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -113,34 +113,22 @@ func runPageAndExit(page *wikifier.Page) {
113113
if err != nil {
114114
log.Fatal(err)
115115
}
116-
printPageResultAndExit(page.RelPath(), page.HTML(), page.Warnings)
116+
fmt.Println(page.HTML())
117+
os.Exit(0)
117118
}
118119

119120
// runs a wiki page
120121
func runWikiPageAndExit(w *wiki.Wiki, pagePath string) {
121122
res := w.DisplayPage(pagePath)
122123
switch r := res.(type) {
123124
case wiki.DisplayPage:
124-
printPageResultAndExit(r.Path, r.Content, r.Warnings)
125+
fmt.Println(r.Content)
125126
case wiki.DisplayError:
126127
log.Fatal(r.Error)
127128
case wiki.DisplayRedirect:
128129
log.Fatal("Redirect: " + r.Redirect)
129130
default:
130131
log.Fatal("unsupported response type from wiki.DisplayPage()")
131132
}
132-
}
133-
134-
// prints the page result and exits
135-
func printPageResultAndExit(path string, html wikifier.HTML, warnings []wikifier.Warning) {
136-
137-
// print warnings to stderr
138-
for _, w := range warnings {
139-
log.Printf("%s:%d:%d: %s", path, w.Pos.Line, w.Pos.Column, w.Message)
140-
}
141-
142-
// print html to stdout
143-
fmt.Println(html)
144-
145133
os.Exit(0)
146134
}

wikifier/page.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ func (p *Page) Name() string {
288288
return p.RelName()
289289
}
290290

291+
if path == "" {
292+
return ""
293+
}
294+
291295
// make relative to page directory
292296
if name, err := filepath.Rel(dir, path); err == nil {
293297

@@ -333,7 +337,11 @@ func (p *Page) Prefix() string {
333337
// Path returns the absolute path to the page as resolved.
334338
// If the path does not resolve, returns an empty string.
335339
func (p *Page) Path() string {
336-
return pageAbs(p.RelPath())
340+
relPath := p.RelPath()
341+
if relPath == "" {
342+
return ""
343+
}
344+
return pageAbs(relPath)
337345
}
338346

339347
// RelName returns the unresolved page filename, with or without extension.
@@ -348,6 +356,9 @@ func (p *Page) RelName() string {
348356

349357
dir := pageAbs(p.Opt.Dir.Page)
350358
path := p.RelPath() // this is what makes it different from Name()
359+
if path == "" {
360+
return ""
361+
}
351362

352363
// make relative to page directory
353364
if name, err := filepath.Rel(dir, path); err == nil {
@@ -377,6 +388,9 @@ func (p *Page) RelPath() string {
377388
if p.FilePath != "" {
378389
return p.FilePath
379390
}
391+
if p.name == "" {
392+
return ""
393+
}
380394
return filepath.Join(p.Opt.Dir.Page, p.name)
381395
}
382396

0 commit comments

Comments
 (0)