Browse Source

render markdown

trunk
vilmibm 1 year ago
parent
commit
09641b839d
1 changed files with 24 additions and 13 deletions
  1. +24
    -13
      main.go

+ 24
- 13
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()
*/
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("TODO print raw file")
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…
Cancel
Save