full import
This commit is contained in:
parent
485ccb9090
commit
cc5ecff2f0
|
@ -10,6 +10,7 @@ import (
|
|||
"path"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var userPath string
|
||||
|
@ -37,6 +38,68 @@ var importCmd = &cobra.Command{
|
|||
panic(err)
|
||||
}
|
||||
|
||||
// import config
|
||||
bytes, err := os.ReadFile(path.Join(userPath, "meta/config.yml"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
v1Config := importer.V1UserConfig{}
|
||||
yaml.Unmarshal(bytes, &v1Config)
|
||||
|
||||
mes := []model.MeLinks{}
|
||||
for _, me := range v1Config.Me {
|
||||
mes = append(mes, model.MeLinks{
|
||||
Name: me.Name,
|
||||
Url: me.Url,
|
||||
})
|
||||
}
|
||||
|
||||
lists := []model.EntryList{}
|
||||
for _, list := range v1Config.Lists {
|
||||
lists = append(lists, model.EntryList{
|
||||
Id: list.Id,
|
||||
Title: list.Title,
|
||||
Include: importer.ConvertTypeList(list.Include, app.Registry),
|
||||
ListType: list.ListType,
|
||||
})
|
||||
}
|
||||
|
||||
headerMenu := []model.MenuItem{}
|
||||
for _, item := range v1Config.HeaderMenu {
|
||||
headerMenu = append(headerMenu, model.MenuItem{
|
||||
Title: item.Title,
|
||||
List: item.List,
|
||||
Url: item.Url,
|
||||
Post: item.Post,
|
||||
})
|
||||
}
|
||||
|
||||
footerMenu := []model.MenuItem{}
|
||||
for _, item := range v1Config.FooterMenu {
|
||||
footerMenu = append(footerMenu, model.MenuItem{
|
||||
Title: item.Title,
|
||||
List: item.List,
|
||||
Url: item.Url,
|
||||
Post: item.Post,
|
||||
})
|
||||
}
|
||||
|
||||
v2Config, _ := app.SiteConfigRepo.Get()
|
||||
v2Config.Title = v1Config.Title
|
||||
v2Config.SubTitle = v1Config.SubTitle
|
||||
v2Config.HeaderColor = v1Config.HeaderColor
|
||||
v2Config.AuthorName = v1Config.AuthorName
|
||||
v2Config.Me = mes
|
||||
v2Config.Lists = lists
|
||||
v2Config.PrimaryListInclude = v1Config.PrimaryListInclude
|
||||
v2Config.HeaderMenu = headerMenu
|
||||
v2Config.FooterMenu = footerMenu
|
||||
|
||||
err = app.SiteConfigRepo.Update(v2Config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, post := range posts {
|
||||
existing, _ := app.EntryService.FindById(post.Id)
|
||||
if existing != nil {
|
||||
|
@ -72,9 +135,23 @@ var importCmd = &cobra.Command{
|
|||
Content: post.Content,
|
||||
})
|
||||
case "bookmark":
|
||||
|
||||
entry = &entrytypes.Bookmark{}
|
||||
entry.SetID(post.Id)
|
||||
entry.SetPublishedAt(&post.Meta.Date)
|
||||
entry.SetMetaData(&entrytypes.BookmarkMetaData{
|
||||
Url: post.Meta.Bookmark.Url,
|
||||
Title: post.Meta.Bookmark.Text,
|
||||
Content: post.Content,
|
||||
})
|
||||
case "reply":
|
||||
|
||||
entry = &entrytypes.Reply{}
|
||||
entry.SetID(post.Id)
|
||||
entry.SetPublishedAt(&post.Meta.Date)
|
||||
entry.SetMetaData(&entrytypes.ReplyMetaData{
|
||||
Url: post.Meta.Reply.Url,
|
||||
Title: post.Meta.Reply.Text,
|
||||
Content: post.Content,
|
||||
})
|
||||
case "photo":
|
||||
entry = &entrytypes.Image{}
|
||||
entry.SetID(post.Id)
|
||||
|
|
|
@ -32,6 +32,8 @@ func App(db infra.Database) *web.WebApp {
|
|||
registry.Register(&entrytypes.Page{})
|
||||
registry.Register(&entrytypes.Recipe{})
|
||||
registry.Register(&entrytypes.Note{})
|
||||
registry.Register(&entrytypes.Bookmark{})
|
||||
registry.Register(&entrytypes.Reply{})
|
||||
|
||||
entryRepo := infra.NewEntryRepository(db, registry)
|
||||
binRepo := infra.NewBinaryFileRepo(db)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package entrytypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
)
|
||||
|
||||
type Bookmark struct {
|
||||
model.EntryBase
|
||||
meta BookmarkMetaData
|
||||
}
|
||||
|
||||
type BookmarkMetaData struct {
|
||||
Title string `owl:"inputType=text"`
|
||||
Url string `owl:"inputType=text"`
|
||||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
func (e *Bookmark) Title() string {
|
||||
return e.meta.Title
|
||||
}
|
||||
|
||||
func (e *Bookmark) Content() model.EntryContent {
|
||||
str, err := render.RenderTemplateToString("entry/Bookmark", e)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return model.EntryContent(str)
|
||||
}
|
||||
|
||||
func (e *Bookmark) MetaData() interface{} {
|
||||
return &e.meta
|
||||
}
|
||||
|
||||
func (e *Bookmark) SetMetaData(metaData interface{}) {
|
||||
e.meta = *metaData.(*BookmarkMetaData)
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package entrytypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
)
|
||||
|
||||
type Reply struct {
|
||||
model.EntryBase
|
||||
meta ReplyMetaData
|
||||
}
|
||||
|
||||
type ReplyMetaData struct {
|
||||
Title string `owl:"inputType=text"`
|
||||
Url string `owl:"inputType=text"`
|
||||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
func (e *Reply) Title() string {
|
||||
return "Re: " + e.meta.Title
|
||||
}
|
||||
|
||||
func (e *Reply) Content() model.EntryContent {
|
||||
str, err := render.RenderTemplateToString("entry/Reply", e)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return model.EntryContent(str)
|
||||
}
|
||||
|
||||
func (e *Reply) MetaData() interface{} {
|
||||
return &e.meta
|
||||
}
|
||||
|
||||
func (e *Reply) SetMetaData(metaData interface{}) {
|
||||
e.meta = *metaData.(*ReplyMetaData)
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package importer
|
||||
|
||||
type V1UserConfig struct {
|
||||
Title string `yaml:"title"`
|
||||
SubTitle string `yaml:"subtitle"`
|
||||
HeaderColor string `yaml:"header_color"`
|
||||
AuthorName string `yaml:"author_name"`
|
||||
Me []V1UserMe `yaml:"me"`
|
||||
PassworHash string `yaml:"password_hash"`
|
||||
Lists []V1PostList `yaml:"lists"`
|
||||
PrimaryListInclude []string `yaml:"primary_list_include"`
|
||||
HeaderMenu []V1MenuItem `yaml:"header_menu"`
|
||||
FooterMenu []V1MenuItem `yaml:"footer_menu"`
|
||||
}
|
||||
|
||||
type V1UserMe struct {
|
||||
Name string `yaml:"name"`
|
||||
Url string `yaml:"url"`
|
||||
}
|
||||
|
||||
type V1PostList struct {
|
||||
Id string `yaml:"id"`
|
||||
Title string `yaml:"title"`
|
||||
Include []string `yaml:"include"`
|
||||
ListType string `yaml:"list_type"`
|
||||
}
|
||||
|
||||
type V1MenuItem struct {
|
||||
Title string `yaml:"title"`
|
||||
List string `yaml:"list"`
|
||||
Url string `yaml:"url"`
|
||||
Post string `yaml:"post"`
|
||||
}
|
|
@ -3,6 +3,8 @@ package importer
|
|||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"owl-blogs/app"
|
||||
entrytypes "owl-blogs/entry_types"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
|
@ -202,3 +204,35 @@ func fileExists(path string) bool {
|
|||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func ConvertTypeList(v1 []string, registry *app.EntryTypeRegistry) []string {
|
||||
v2 := make([]string, len(v1))
|
||||
for i, v1Type := range v1 {
|
||||
switch v1Type {
|
||||
case "article":
|
||||
name, _ := registry.TypeName(&entrytypes.Article{})
|
||||
v2[i] = name
|
||||
case "bookmark":
|
||||
name, _ := registry.TypeName(&entrytypes.Bookmark{})
|
||||
v2[i] = name
|
||||
case "reply":
|
||||
name, _ := registry.TypeName(&entrytypes.Reply{})
|
||||
v2[i] = name
|
||||
case "photo":
|
||||
name, _ := registry.TypeName(&entrytypes.Image{})
|
||||
v2[i] = name
|
||||
case "note":
|
||||
name, _ := registry.TypeName(&entrytypes.Note{})
|
||||
v2[i] = name
|
||||
case "recipe":
|
||||
name, _ := registry.TypeName(&entrytypes.Recipe{})
|
||||
v2[i] = name
|
||||
case "page":
|
||||
name, _ := registry.TypeName(&entrytypes.Page{})
|
||||
v2[i] = name
|
||||
default:
|
||||
v2[i] = v1Type
|
||||
}
|
||||
}
|
||||
return v2
|
||||
}
|
||||
|
|
|
@ -85,6 +85,15 @@
|
|||
<div class="container">
|
||||
<nav>
|
||||
<ul>
|
||||
{{ range $link := .SiteConfig.HeaderMenu }}
|
||||
{{ if $link.List }}
|
||||
<li><a href="/lists/{{ $link.List }}">{{ $link.Title }}</a></li>
|
||||
{{ else if $link.Post }}
|
||||
<li><a href="/posts/{{ $link.Post }}">{{ $link.Title }}</a></li>
|
||||
{{ else }}
|
||||
<li><a href="{{ $link.Url }}">{{ $link.Title }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
@ -93,7 +102,19 @@
|
|||
{{template "main" .Data}}
|
||||
</main>
|
||||
<footer class="container">
|
||||
Powered by <a href='https://golang.org/'>Go</a>
|
||||
<nav>
|
||||
<ul>
|
||||
{{ range $link := .SiteConfig.FooterMenu }}
|
||||
{{ if $link.List }}
|
||||
<li><a href="/lists/{{ $link.List }}">{{ $link.Title }}</a></li>
|
||||
{{ else if $link.Post }}
|
||||
<li><a href="/posts/{{ $link.Post }}">{{ $link.Title }}</a></li>
|
||||
{{ else }}
|
||||
<li><a href="{{ $link.Url }}">{{ $link.Title }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</nav>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Bookmark: <a href="{{.MetaData.Url}}">{{.MetaData.Url}}</a>
|
||||
|
||||
{{.MetaData.Content | markdown }}
|
|
@ -0,0 +1,3 @@
|
|||
Reply to: <a href="{{.MetaData.Url}}">{{.MetaData.Url}}</a>
|
||||
|
||||
{{.MetaData.Content | markdown }}
|
Loading…
Reference in New Issue