added version tracking
This commit is contained in:
parent
6eafe84f35
commit
9d9c4fa7ff
@ -58,10 +58,10 @@ change `main` to your specific repo's branch and you should be good to go!
|
|||||||
- [ ] Webhook support for auto pull on push/update of the git repo
|
- [ ] Webhook support for auto pull on push/update of the git repo
|
||||||
- [x] Git Branch support
|
- [x] Git Branch support
|
||||||
- [ ] add a star/upvote/like feature for pages
|
- [ ] add a star/upvote/like feature for pages
|
||||||
- [ ] edit tracker
|
- [x] edit/version tracker
|
||||||
- [ ] Author
|
- [x] Author
|
||||||
- [ ] last edited
|
- [x] last edited
|
||||||
- [ ] last editor/commit
|
- [ ] last editor/commit [?] maybe working
|
||||||
- [ ] PGP Signed & Verification
|
- [ ] PGP Signed & Verification
|
||||||
- [ ] pgp signed intergration
|
- [ ] pgp signed intergration
|
||||||
- [x] comments using bitcask - generated in comments.db/
|
- [x] comments using bitcask - generated in comments.db/
|
||||||
|
@ -24,6 +24,13 @@
|
|||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
<div style="font-size: 0.3em; text-align: right; margin-bottom: 5px;">
|
||||||
|
{{- if eq .Author .LastModifier -}}
|
||||||
|
Authored: {{ .Author }} @ {{ .AuthoredDate.Format "2006/01/02" }}
|
||||||
|
{{- else -}}
|
||||||
|
Authored: {{ .Author }} @ {{ .AuthoredDate.Format "2006/01/02" }} - Modified: {{ .LastModifier }} @ {{ .LastModifiedDate.Format "2006/01/02" }}
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
<div class="comments">
|
<div class="comments">
|
||||||
<h2>Comments</h2>
|
<h2>Comments</h2>
|
||||||
{{ range .Comments }}
|
{{ range .Comments }}
|
||||||
|
@ -97,3 +97,22 @@ section h2 {
|
|||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reduce font size for authored and modified date */
|
||||||
|
div.content div[style="font-size: 0.8em;"] {
|
||||||
|
font-size: 0.6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add bar under authored and modified date */
|
||||||
|
div.content div[style="font-size: 0.8em;"]:after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
border-bottom: 1px solid #14ee00;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* align authored and modified date to the right */
|
||||||
|
div.content div[style="font-size: 0.8em;"] {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
30
src/git.go
30
src/git.go
@ -4,9 +4,11 @@ import (
|
|||||||
//"fmt"
|
//"fmt"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
git "github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cloneRepository(repoURL, localPath string) error {
|
func cloneRepository(repoURL, localPath string) error {
|
||||||
@ -75,3 +77,31 @@ func readFileFromRepo(localPath string, filePath string) ([]byte, error) {
|
|||||||
|
|
||||||
return []byte(content), nil
|
return []byte(content), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAuthorAndLastModification(localPath, filePath string) (string, time.Time, string, time.Time, error) {
|
||||||
|
repo, err := git.PlainOpen(localPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", time.Time{}, "", time.Time{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
iter, err := repo.Log(&git.LogOptions{FileName: &filePath})
|
||||||
|
if err != nil {
|
||||||
|
return "", time.Time{}, "", time.Time{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var firstCommit *object.Commit
|
||||||
|
var lastCommit *object.Commit
|
||||||
|
|
||||||
|
err = iter.ForEach(func(c *object.Commit) error {
|
||||||
|
if firstCommit == nil {
|
||||||
|
firstCommit = c
|
||||||
|
}
|
||||||
|
lastCommit = c
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", time.Time{}, "", time.Time{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstCommit.Author.Name, firstCommit.Author.When, lastCommit.Author.Name, lastCommit.Author.When, nil
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/prologic/bitcask"
|
"github.com/prologic/bitcask"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
@ -19,6 +20,10 @@ type Page struct {
|
|||||||
Content template.HTML
|
Content template.HTML
|
||||||
Comments []Comment
|
Comments []Comment
|
||||||
Path string
|
Path string
|
||||||
|
Author string
|
||||||
|
AuthoredDate time.Time
|
||||||
|
LastModifier string
|
||||||
|
LastModifiedDate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderPage(w http.ResponseWriter, r *http.Request, localPath, filePath string, commentsDB *bitcask.Bitcask) error {
|
func renderPage(w http.ResponseWriter, r *http.Request, localPath, filePath string, commentsDB *bitcask.Bitcask) error {
|
||||||
@ -32,7 +37,7 @@ func renderPage(w http.ResponseWriter, r *http.Request, localPath, filePath stri
|
|||||||
ext := filepath.Ext(filePath)
|
ext := filepath.Ext(filePath)
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".md":
|
case ".md":
|
||||||
renderMarkdown(w, r, content, commentsDB)
|
renderMarkdown(w, r, content, commentsDB, localPath, filePath) // Updated the call to include localPath and filePath
|
||||||
case ".html", ".css":
|
case ".html", ".css":
|
||||||
renderStatic(w, content, ext)
|
renderStatic(w, content, ext)
|
||||||
default:
|
default:
|
||||||
@ -41,7 +46,7 @@ func renderPage(w http.ResponseWriter, r *http.Request, localPath, filePath stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderMarkdown(w http.ResponseWriter, r *http.Request, content []byte, commentsDB *bitcask.Bitcask) {
|
func renderMarkdown(w http.ResponseWriter, r *http.Request, content []byte, commentsDB *bitcask.Bitcask, localPath, filePath string) {
|
||||||
md := goldmark.New(
|
md := goldmark.New(
|
||||||
goldmark.WithExtensions(
|
goldmark.WithExtensions(
|
||||||
extension.GFM, // GitHub Flavored Markdown
|
extension.GFM, // GitHub Flavored Markdown
|
||||||
@ -51,8 +56,14 @@ func renderMarkdown(w http.ResponseWriter, r *http.Request, content []byte, comm
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
author, authoredDate, lastModifier, lastModifiedDate, err := getAuthorAndLastModification(localPath, filePath)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Error fetching author and last modification date", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var mdBuf bytes.Buffer
|
var mdBuf bytes.Buffer
|
||||||
err := md.Convert(content, &mdBuf)
|
err = md.Convert(content, &mdBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Error converting Markdown", http.StatusInternalServerError)
|
http.Error(w, "Error converting Markdown", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -70,7 +81,15 @@ func renderMarkdown(w http.ResponseWriter, r *http.Request, content []byte, comm
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
page := &Page{Content: template.HTML(mdBuf.String()), Comments: comments, Path: r.URL.Path}
|
page := &Page{
|
||||||
|
Content: template.HTML(mdBuf.String()),
|
||||||
|
Comments: comments,
|
||||||
|
Path: r.URL.Path,
|
||||||
|
Author: author,
|
||||||
|
AuthoredDate: authoredDate,
|
||||||
|
LastModifier: lastModifier,
|
||||||
|
LastModifiedDate: lastModifiedDate,
|
||||||
|
}
|
||||||
t, err := template.New("layout").Parse(string(layout))
|
t, err := template.New("layout").Parse(string(layout))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Error parsing layout", http.StatusInternalServerError)
|
http.Error(w, "Error parsing layout", http.StatusInternalServerError)
|
||||||
|
Loading…
Reference in New Issue
Block a user