render markdown
parent
0030cd90f8
commit
09641b839d
41
main.go
41
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
@ -79,23 +80,33 @@ func visitPrompt() error {
|
||||||
func visitUser(username string) error {
|
func visitUser(username string) error {
|
||||||
files, err := ioutil.ReadDir(filepath.Join("/home", username))
|
files, err := ioutil.ReadDir(filepath.Join("/home", username))
|
||||||
if err != nil {
|
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 {
|
for _, file := range files {
|
||||||
fmt.Println("DEBUG", filename)
|
if !isReadme(file.Name()) {
|
||||||
if isReadme(filename) {
|
continue
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
fmt.Println("TODO non-readme fallback")
|
||||||
|
@ -105,7 +116,7 @@ func visitUser(username string) error {
|
||||||
|
|
||||||
func isReadme(filename string) bool {
|
func isReadme(filename string) bool {
|
||||||
fn := strings.ToLower(filename)
|
fn := strings.ToLower(filename)
|
||||||
return strings.HasPrefix(fn, "readme")
|
return strings.HasPrefix(fn, "readme") || strings.HasPrefix(fn, "welcome")
|
||||||
}
|
}
|
||||||
|
|
||||||
func isMarkdown(filename string) bool {
|
func isMarkdown(filename string) bool {
|
||||||
|
|
Loading…
Reference in New Issue