render markdown
parent
0030cd90f8
commit
09641b839d
41
main.go
41
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
|
@ -79,23 +80,33 @@ func visitPrompt() error {
|
|||
func visitUser(username string) error {
|
||||
files, err := ioutil.ReadDir(filepath.Join("/home", username))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read user's home directory: %w", err)
|
||||
return fmt.Errorf("user is not accepting visitors (could not read user's home directory: %w)", err)
|
||||
}
|
||||
|
||||
for _, filename := range files {
|
||||
fmt.Println("DEBUG", filename)
|
||||
if isReadme(filename) {
|
||||
if isMarkdown(filename) {
|
||||
// TODO fill in once i know if filename is abs or rel path
|
||||
/*
|
||||
r, _ := glamour.NewTermRenderer(glamour.WithAutoStyle())
|
||||
out, err := r.Render()
|
||||
*/
|
||||
|
||||
}
|
||||
fmt.Println("TODO print raw file")
|
||||
return nil
|
||||
for _, file := range files {
|
||||
if !isReadme(file.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
path := filepath.Join("/home", username, file.Name())
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if isMarkdown(file.Name()) {
|
||||
r, _ := glamour.NewTermRenderer(glamour.WithAutoStyle())
|
||||
out, err := r.RenderBytes(data)
|
||||
if err == nil {
|
||||
fmt.Println(string(out))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Println("TODO non-readme fallback")
|
||||
|
@ -105,7 +116,7 @@ func visitUser(username string) error {
|
|||
|
||||
func isReadme(filename string) bool {
|
||||
fn := strings.ToLower(filename)
|
||||
return strings.HasPrefix(fn, "readme")
|
||||
return strings.HasPrefix(fn, "readme") || strings.HasPrefix(fn, "welcome")
|
||||
}
|
||||
|
||||
func isMarkdown(filename string) bool {
|
||||
|
|
Loading…
Reference in New Issue