mirror of
https://github.com/go-shiori/shiori.git
synced 2025-09-08 22:15:58 +08:00
Fix import not working
This commit is contained in:
parent
3b8ce6ce0d
commit
259d1b96ed
1 changed files with 47 additions and 36 deletions
|
@ -40,6 +40,15 @@ func init() {
|
||||||
rootCmd.AddCommand(importCmd)
|
rootCmd.AddCommand(importCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printTagName(s *goquery.Selection) string {
|
||||||
|
tags := []string{}
|
||||||
|
for _, nd := range s.Nodes {
|
||||||
|
tags = append(tags, nd.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(tags, ",")
|
||||||
|
}
|
||||||
|
|
||||||
func importBookmarks(pth string, generateTag bool) error {
|
func importBookmarks(pth string, generateTag bool) error {
|
||||||
// Open file
|
// Open file
|
||||||
srcFile, err := os.Open(pth)
|
srcFile, err := os.Open(pth)
|
||||||
|
@ -54,48 +63,50 @@ func importBookmarks(pth string, generateTag bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch each bookmark categories
|
// Loop each bookmark item
|
||||||
bookmarks := []model.Bookmark{}
|
bookmarks := []model.Bookmark{}
|
||||||
doc.Find("body>dl>dt").Each(func(_ int, el *goquery.Selection) {
|
doc.Find("dt>a").Each(func(_ int, a *goquery.Selection) {
|
||||||
// Create category title
|
// Get related elements
|
||||||
category := el.Find("h3").First().Text()
|
dt := a.Parent()
|
||||||
category = normalizeSpace(category)
|
dl := dt.Parent()
|
||||||
category = strings.ToLower(category)
|
|
||||||
category = strings.Replace(category, " ", "-", -1)
|
|
||||||
|
|
||||||
// Fetch all link in this categories
|
// Get metadata
|
||||||
el.Find("dl>dt").Each(func(_ int, dt *goquery.Selection) {
|
title := a.Text()
|
||||||
// Get bookmark link
|
url, _ := a.Attr("href")
|
||||||
a := dt.Find("a").First()
|
strModified, _ := a.Attr("last_modified")
|
||||||
title := a.Text()
|
intModified, _ := strconv.ParseInt(strModified, 10, 64)
|
||||||
url, _ := a.Attr("href")
|
modified := time.Unix(intModified, 0)
|
||||||
strModified, _ := a.Attr("last_modified")
|
|
||||||
intModified, _ := strconv.ParseInt(strModified, 10, 64)
|
|
||||||
modified := time.Unix(intModified, 0)
|
|
||||||
|
|
||||||
// Get bookmark excerpt
|
// Get bookmark excerpt
|
||||||
excerpt := ""
|
excerpt := ""
|
||||||
if nxt := dt.Next(); nxt.Is("dd") {
|
if dd := dt.Next(); dd.Is("dd") {
|
||||||
excerpt = nxt.Text()
|
excerpt = dd.Text()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create bookmark item
|
// Get category name for this bookmark
|
||||||
bookmark := model.Bookmark{
|
category := ""
|
||||||
URL: url,
|
if dtCategory := dl.Prev(); dtCategory.Is("h3") {
|
||||||
Title: normalizeSpace(title),
|
category = dtCategory.Text()
|
||||||
Excerpt: normalizeSpace(excerpt),
|
category = normalizeSpace(category)
|
||||||
Modified: modified.Format("2006-01-02 15:04:05"),
|
category = strings.ToLower(category)
|
||||||
Tags: []model.Tag{},
|
category = strings.Replace(category, " ", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if generateTag {
|
tags := []model.Tag{}
|
||||||
bookmark.Tags = []model.Tag{
|
if category != "" && generateTag {
|
||||||
{Name: category},
|
tags = []model.Tag{{Name: category}}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bookmarks = append(bookmarks, bookmark)
|
// Add item to list
|
||||||
})
|
bookmark := model.Bookmark{
|
||||||
|
URL: url,
|
||||||
|
Title: normalizeSpace(title),
|
||||||
|
Excerpt: normalizeSpace(excerpt),
|
||||||
|
Modified: modified.Format("2006-01-02 15:04:05"),
|
||||||
|
Tags: tags,
|
||||||
|
}
|
||||||
|
|
||||||
|
bookmarks = append(bookmarks, bookmark)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Save bookmarks to database
|
// Save bookmarks to database
|
||||||
|
|
Loading…
Add table
Reference in a new issue