mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
commit
21047443d6
12
migrate.go
12
migrate.go
@ -7,8 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func migrate(pathToOldData, pathToData string) error {
|
func migrate(pathToOldData, pathToData string) error {
|
||||||
files, _ := ioutil.ReadDir(pathToOldData)
|
files, err := ioutil.ReadDir(pathToOldData)
|
||||||
|
if len(files) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
if f.Mode().IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
fmt.Printf("Migrating %s", f.Name())
|
fmt.Printf("Migrating %s", f.Name())
|
||||||
p := Open(f.Name())
|
p := Open(f.Name())
|
||||||
bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name()))
|
bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name()))
|
||||||
@ -19,7 +25,9 @@ func migrate(pathToOldData, pathToData string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.Save()
|
if err = p.Save(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
5
page.go
5
page.go
@ -76,6 +76,8 @@ func (p *Page) Update(newText string) error {
|
|||||||
return p.Save()
|
return p.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rBracketPage = regexp.MustCompile(`\[\[(.*?)\]\]`)
|
||||||
|
|
||||||
func (p *Page) Render() {
|
func (p *Page) Render() {
|
||||||
if p.IsEncrypted {
|
if p.IsEncrypted {
|
||||||
p.RenderedPage = "<code>" + p.Text.GetCurrent() + "</code>"
|
p.RenderedPage = "<code>" + p.Text.GetCurrent() + "</code>"
|
||||||
@ -83,9 +85,8 @@ func (p *Page) Render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert [[page]] to [page](/page/view)
|
// Convert [[page]] to [page](/page/view)
|
||||||
r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]")
|
|
||||||
currentText := p.Text.GetCurrent()
|
currentText := p.Text.GetCurrent()
|
||||||
for _, s := range r.FindAllString(currentText, -1) {
|
for _, s := range rBracketPage.FindAllString(currentText, -1) {
|
||||||
currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1)
|
currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1)
|
||||||
}
|
}
|
||||||
p.Text.Update(currentText)
|
p.Text.Update(currentText)
|
||||||
|
Loading…
Reference in New Issue
Block a user