render markdown

trunk
vilmibm 2020-10-27 17:27:59 +00:00
parent 0030cd90f8
commit 09641b839d
1 changed files with 26 additions and 15 deletions

41
main.go
View File

@ -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 {