This commit is contained in:
parent
636f23d834
commit
5d5f537df9
34
file.go
34
file.go
|
@ -165,7 +165,7 @@ func gitRevision(dirname, page, version string) string {
|
|||
}
|
||||
|
||||
func (fp *FilePages) RecentChanges() ([]Change, error) {
|
||||
cmd := exec.Command("git", "log", "--format=--1--%nDate: %aI%n--2--", "--name-only")
|
||||
cmd := exec.Command("git", "log", "--format=--1--%nDate: %aI%n--2--%n%b%n--3--", "--name-only")
|
||||
cmd.Dir = fp.dirname
|
||||
cmd.Stderr = os.Stderr
|
||||
buf := bytes.Buffer{}
|
||||
|
@ -181,29 +181,34 @@ func (fp *FilePages) RecentChanges() ([]Change, error) {
|
|||
|
||||
scanner := bufio.NewScanner(&buf)
|
||||
|
||||
first := false
|
||||
second := false
|
||||
state := 0
|
||||
|
||||
var changes []Change
|
||||
|
||||
var change Change
|
||||
|
||||
body := ""
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if line == "--1--" {
|
||||
second = false
|
||||
first = true
|
||||
state = 1
|
||||
|
||||
body = ""
|
||||
continue
|
||||
}
|
||||
|
||||
if line == "--2--" {
|
||||
first = false
|
||||
second = true
|
||||
state = 2
|
||||
continue
|
||||
}
|
||||
|
||||
if first && strings.HasPrefix(line, "Date: ") {
|
||||
if line == "--3--" {
|
||||
state = 3
|
||||
continue
|
||||
}
|
||||
|
||||
if state == 1 && strings.HasPrefix(line, "Date: ") {
|
||||
line = line[6:]
|
||||
changeTime, err := time.Parse(time.RFC3339, line)
|
||||
if err != nil {
|
||||
|
@ -213,13 +218,22 @@ func (fp *FilePages) RecentChanges() ([]Change, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if second {
|
||||
if state == 2 {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
body = body + line
|
||||
continue
|
||||
}
|
||||
|
||||
if state == 3 {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
change.Page = line
|
||||
}
|
||||
|
||||
change.Body = body
|
||||
changes = append(changes, change)
|
||||
}
|
||||
|
||||
|
|
1
main.go
1
main.go
|
@ -43,6 +43,7 @@ type Revision struct {
|
|||
type Change struct {
|
||||
Page string
|
||||
Date time.Time
|
||||
Body string
|
||||
}
|
||||
|
||||
type PagesRepository interface {
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
<tr>
|
||||
<td>{{ $change.Date }}</td>
|
||||
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
|
||||
<td>{{ $change.Body }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue
Block a user