5 Commits
v1.0 ... v1.5

Author SHA1 Message Date
bel
72894cd5cc Make header on dirs and files floating fixed 2019-12-07 11:21:47 -07:00
bel
f0a1c21678 Update wrapper for bigger font 2019-12-07 11:03:30 -07:00
bel
807072a77f Unittest and exec file proof on search 2019-12-01 14:16:45 -07:00
bel
081d50328f Fix no configured user 2019-12-01 13:25:49 -07:00
bel
4e2b7b3c85 Dont list hidden files and hopefully search files by ext only .md 2019-11-24 05:09:29 +00:00
22 changed files with 59 additions and 21 deletions

8
Dockerfile Normal file → Executable file
View File

@@ -1,11 +1,8 @@
FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29
RUN apk update && apk add --no-cache ca-certificates git
FROM golang:1.13-alpine as certs
RUN apk update && apk add --no-cache ca-certificates
FROM busybox:glibc
RUN mkdir -p /var/log RUN mkdir -p /var/log
WORKDIR /main WORKDIR /main
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY . . COPY . .
@@ -13,4 +10,3 @@ ENV GOPATH=""
ENV MNT="/mnt/" ENV MNT="/mnt/"
ENTRYPOINT ["/main/exec-notes-server"] ENTRYPOINT ["/main/exec-notes-server"]
CMD [] CMD []

4
TODO Normal file → Executable file
View File

@@ -30,10 +30,10 @@ x main test -
x TOC levels x TOC levels
x delete pages x delete pages
x search x search
FTS x FTS
https://stackoverflow.com/questions/26709971/could-this-be-more-efficient-in-go https://stackoverflow.com/questions/26709971/could-this-be-more-efficient-in-go
x move auth as flag in router x move auth as flag in router
x . and ../** as roots cause bugs in listing and loading and linking x . and ../** as roots cause bugs in listing and loading and linking
x `create` at root is a 400, base= in URL (when `create` input is empty) x `create` at root is a 400, base= in URL (when `create` input is empty)
x versioning
delete top-level pages delete top-level pages
versioning

View File

@@ -5,6 +5,9 @@ type Paths []Path
func (p Paths) List(full ...bool) string { func (p Paths) List(full ...bool) string {
content := "<ul>\n" content := "<ul>\n"
for _, path := range p { for _, path := range p {
if len(path.Base) > 0 && path.Base[0] == '.' {
continue
}
if len(full) > 0 && full[0] { if len(full) > 0 && full[0] {
content += path.FullLI() + "\n" content += path.FullLI() + "\n"
} else { } else {

0
main.go Normal file → Executable file
View File

0
main_test.go Normal file → Executable file
View File

0
notes/delete.go Normal file → Executable file
View File

0
notes/delete_test.go Normal file → Executable file
View File

0
notes/notes.go Normal file → Executable file
View File

0
notes/notes_test.go Normal file → Executable file
View File

10
notes/search.go Normal file → Executable file
View File

@@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"local/notes-server/filetree" "local/notes-server/filetree"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -19,11 +20,20 @@ func (n *Notes) Search(phrase string) (string, error) {
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
if size := info.Size(); size < 1 || size > (5*1024*1024) {
return nil
}
ok, err := grepFile(walked, []byte(phrase)) ok, err := grepFile(walked, []byte(phrase))
if err != nil && err.Error() == "bufio.Scanner: token too long" {
err = nil
}
if err == nil && ok { if err == nil && ok {
p := filetree.NewPathFromLocal(path.Dir(walked)) p := filetree.NewPathFromLocal(path.Dir(walked))
files.Push(p, info) files.Push(p, info)
} }
if err != nil {
log.Printf("failed to scan %v: %v", walked, err)
}
return err return err
}, },
) )

10
notes/search_test.go Normal file → Executable file
View File

@@ -42,3 +42,13 @@ func TestSearch(t *testing.T) {
t.Fatal(v, result) t.Fatal(v, result)
} }
} }
func TestSearchBigFiles(t *testing.T) {
n := New()
n.root = "/usr/local/bin"
_, err := n.Search("this file")
if err != nil {
t.Fatal(err)
}
}

View File

@@ -1,3 +0,0 @@
asdf
this contains my search string

View File

@@ -1,5 +1,18 @@
asdf # h1
searchString
hi
here is my new line ## h2
hi
### h3
hi
#### h4
hi
* bullet
* 1

0
server/.notes/notes.go Normal file → Executable file
View File

12
server/html.go Normal file → Executable file
View File

@@ -22,8 +22,8 @@ func h1(content string) string {
return h("1", content) return h("1", content)
} }
func h2(content string) string { func h2(content string, style ...string) string {
return h("2", content) return h("2", content, style...)
} }
func h3(content string) string { func h3(content string) string {
@@ -38,6 +38,10 @@ func h5(content string) string {
return h("5", content) return h("5", content)
} }
func h(level, content string) string { func h(level, content string, style ...string) string {
return fmt.Sprintf("\n<h%s>\n%s\n</h%s>\n", level, content, level) s := ""
if len(style) > 0 {
s = fmt.Sprintf("style=%q", style[0])
}
return fmt.Sprintf("\n<h%s %s>\n%s\n</h%s>\n", level, s, content, level)
} }

View File

@@ -39,7 +39,7 @@ func TestBlock(t *testing.T) {
func TestH(t *testing.T) { func TestH(t *testing.T) {
s := strings.ReplaceAll(strings.TrimSpace(h2("hi")), "\n", ".") s := strings.ReplaceAll(strings.TrimSpace(h2("hi")), "\n", ".")
if ok, err := regexp.MatchString("<h2>.*hi.*<.h2>", s); err != nil { if ok, err := regexp.MatchString("<h2[ ]*>.*hi.*<.h2>", s); err != nil {
t.Fatal(err, s) t.Fatal(err, s)
} else if !ok { } else if !ok {
t.Fatal(ok, s) t.Fatal(ok, s)

4
server/notes.go Normal file → Executable file
View File

@@ -22,9 +22,9 @@ func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
} }
func notesHead(w http.ResponseWriter, p filetree.Path) { func notesHead(w http.ResponseWriter, p filetree.Path) {
fmt.Fprintln(w, h2(p.MultiLink())) fmt.Fprintln(w, h2(p.MultiLink(), "margin: 0; position: fixed; padding: .25em; background-color: #202b38; width: 100%; top: 0;"))
fmt.Fprintf(w, ` fmt.Fprintf(w, `
<form action=%q method="post"> <form action=%q method="post" style="padding-top: 2.5em">
<input type="text" name="keywords"></input> <input type="text" name="keywords"></input>
<button type="submit">Search</button> <button type="submit">Search</button>
</form> </form>

0
versions/.versions.go Normal file → Executable file
View File

0
versions/.versions_test.go Normal file → Executable file
View File

2
versions/versions.go Normal file → Executable file
View File

@@ -13,6 +13,8 @@ type Versions struct {
func New() (*Versions, error) { func New() (*Versions, error) {
v := &Versions{} v := &Versions{}
v.cmd("git", "init") v.cmd("git", "init")
v.cmd("git", "config", "user.email", "user@user.user")
v.cmd("git", "config", "user.name", "user")
return v, nil return v, nil
} }

0
versions/versions_test.go Normal file → Executable file
View File

3
wrapper.html Normal file → Executable file
View File

@@ -18,6 +18,9 @@
img { img {
max-height: 400px; max-height: 400px;
} }
body {
font-size: 125%;
}
</style> </style>
</header> </header>
<body height="100%"> <body height="100%">