Improve saving of pages for blocks
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
7199e0c1da
commit
71838ee0af
33
file.go
33
file.go
|
@ -34,6 +34,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
||||
|
@ -281,8 +282,14 @@ func (fp *FilePages) save(msg saveMessage) error {
|
|||
summary := msg.summary
|
||||
author := msg.author
|
||||
|
||||
page.Name = strings.Replace(p, " ", "_", -1)
|
||||
page.Title = strings.Replace(p, "_", " ", -1)
|
||||
if p[0] != '_' {
|
||||
page.Name = strings.Replace(p, " ", "_", -1)
|
||||
page.Title = strings.Replace(p, "_", " ", -1)
|
||||
} else {
|
||||
page.Name = p
|
||||
page.Title = p
|
||||
}
|
||||
spew.Dump(page)
|
||||
|
||||
sw.Start("create blocks")
|
||||
err := saveBlocksFromPage(fp.dirname, page)
|
||||
|
@ -365,7 +372,7 @@ func saveWithNewIDs(dirname string, listItems []ListItemV2, pageName string) ([]
|
|||
}
|
||||
|
||||
func saveBlocksFromPage(dirname string, page Page) error {
|
||||
log.Println("Processing: ", page.Name)
|
||||
log.Printf("Processing: %q\n", page.Name)
|
||||
var listItems []ListItem
|
||||
err := json.NewDecoder(strings.NewReader(page.Content)).Decode(&listItems)
|
||||
if err != nil {
|
||||
|
@ -394,6 +401,7 @@ func saveBlocksFromPage(dirname string, page Page) error {
|
|||
title = parentBlock.Text
|
||||
}
|
||||
|
||||
rootParentID := page.Name
|
||||
var parent = ListItem{
|
||||
Text: title,
|
||||
Indented: -1,
|
||||
|
@ -427,7 +435,11 @@ func saveBlocksFromPage(dirname string, page Page) error {
|
|||
}
|
||||
}
|
||||
|
||||
blocks[item.ID] = Block{item.Text, []string{}, parent.ID}
|
||||
blocks[item.ID] = Block{
|
||||
Text: item.Text,
|
||||
Children: []string{},
|
||||
Parent: parent.ID,
|
||||
}
|
||||
if block, e := blocks[parent.ID]; e {
|
||||
block.Children = append(block.Children, item.ID)
|
||||
blocks[parent.ID] = block
|
||||
|
@ -437,17 +449,18 @@ func saveBlocksFromPage(dirname string, page Page) error {
|
|||
prev = &listItems[i]
|
||||
}
|
||||
|
||||
log.Printf("Loading parent block: %s", parent.ID)
|
||||
f, err := os.Open(filepath.Join(dirname, BlocksDirectory, parent.ID))
|
||||
// TODO: found out if this is still necessary
|
||||
log.Printf("Loading parent block: %q", rootParentID)
|
||||
f, err := os.Open(filepath.Join(dirname, BlocksDirectory, rootParentID))
|
||||
if err == nil {
|
||||
var parentBlock Block
|
||||
err = json.NewDecoder(f).Decode(&parentBlock)
|
||||
if err == nil {
|
||||
if pb, e := blocks[parent.ID]; e {
|
||||
if pb, e := blocks[rootParentID]; e {
|
||||
pb.Text = parentBlock.Text
|
||||
pb.Parent = parentBlock.Parent
|
||||
blocks[parent.ID] = pb
|
||||
log.Printf("Text=%s, Parent=%s", parentBlock.Text, parentBlock.Parent)
|
||||
blocks[rootParentID] = pb
|
||||
log.Printf("Text=%q, Parent=%q", parentBlock.Text, parentBlock.Parent)
|
||||
}
|
||||
}
|
||||
f.Close()
|
||||
|
@ -457,7 +470,7 @@ func saveBlocksFromPage(dirname string, page Page) error {
|
|||
}
|
||||
|
||||
for id, block := range blocks {
|
||||
log.Println("Writing to ", id)
|
||||
log.Printf("Writing to %q\n", id)
|
||||
f, err := os.OpenFile(filepath.Join(dirname, BlocksDirectory, id), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
|
7
main.go
7
main.go
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/blevesearch/bleve"
|
||||
"p83.nl/go/ekster/pkg/util"
|
||||
"p83.nl/go/indieauth"
|
||||
"p83.nl/go/wiki/link"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -169,6 +170,7 @@ type editPage struct {
|
|||
pageBaseInfo
|
||||
Session *Session
|
||||
Title string
|
||||
TitleHTML template.HTML
|
||||
Content string
|
||||
Name string
|
||||
Editor template.HTML
|
||||
|
@ -388,7 +390,7 @@ func prepareDays(repo PagesRepository, t time.Time) []Day {
|
|||
|
||||
var days []Day
|
||||
|
||||
curDate := t.AddDate(0, 0, -(t.Day()-1))
|
||||
curDate := t.AddDate(0, 0, -(t.Day() - 1))
|
||||
preDays := int(curDate.Weekday())
|
||||
if preDays == 0 {
|
||||
preDays = 7
|
||||
|
@ -609,10 +611,13 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
parents[i], parents[j] = parents[j], parents[i]
|
||||
}
|
||||
|
||||
htmlTitle := link.FormatHtmlTitle(title)
|
||||
|
||||
data := editPage{
|
||||
pageBaseInfo: pageBase,
|
||||
Session: sess,
|
||||
Title: title,
|
||||
TitleHTML: htmlTitle,
|
||||
Content: pageText,
|
||||
Editor: editor,
|
||||
Name: page,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{{ end }}
|
||||
</ol>
|
||||
</nav>
|
||||
<h1 class="title">{{ .Title }}</h1>
|
||||
<h1 class="title">{{ .TitleHTML }}</h1>
|
||||
<form action="/save/" method="post">
|
||||
<input type="hidden" name="p" value="{{ .Name }}"/>
|
||||
{{ .Editor }}
|
||||
|
|
Loading…
Reference in New Issue
Block a user