A big revamp for mindflow and RSS. First of all, now RSS is 100% valid and has actual links instead of just a link to a post in a mindflow. Also, on mindflow page each post that has a URL field set has it displayed as Link: ... .
This commit is contained in:
parent
906f73c8a6
commit
85a3a9692e
@ -42,7 +42,7 @@ func (h *MindflowApiHandlers) NewPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
category.ID, _ = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
category.ID, _ = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
post, err = mindflow.NewPost(*category, r.FormValue("title"), r.FormValue("body"))
|
post, err = mindflow.NewPost(*category, r.FormValue("title"), r.FormValue("url"), r.FormValue("body"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -67,6 +67,7 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
body := cleanupNewlines(r.FormValue("body"))
|
body := cleanupNewlines(r.FormValue("body"))
|
||||||
|
url := r.FormValue("url")
|
||||||
|
|
||||||
category.ID, err = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
category.ID, err = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,7 +75,7 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
post, err = mindflow.NewPost(category, r.FormValue("title"), body)
|
post, err = mindflow.NewPost(category, r.FormValue("title"), url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -122,7 +122,8 @@ func (s *SQLiteMindflow) NewPost(post *mindflow.Post) error {
|
|||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
r, err := tx.Stmt(stmtPostNew).Exec(post.Category.ID, post.Date.UTC().Unix(), post.Title, post.Body)
|
r, err := tx.Stmt(stmtPostNew).Exec(post.Category.ID, post.Date.UTC().Unix(),
|
||||||
|
post.Title, post.URL, post.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -144,7 +145,8 @@ func (s *SQLiteMindflow) EditPost(post *mindflow.Post) error {
|
|||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
_, err = tx.Stmt(stmtPostEdit).Exec(post.Category.ID, post.Title, post.Body, post.ID)
|
_, err = tx.Stmt(stmtPostEdit).Exec(post.Category.ID, post.Title, post.URL,
|
||||||
|
post.Body, post.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -187,7 +189,8 @@ func (s *SQLiteMindflow) Posts() (posts []mindflow.Post, err error) {
|
|||||||
var post mindflow.Post
|
var post mindflow.Post
|
||||||
var date_unix int64
|
var date_unix int64
|
||||||
|
|
||||||
if err = rows.Scan(&post.ID, &post.Category.ID, &post.Category.Name, &date_unix, &post.Title, &post.Body); err != nil {
|
if err = rows.Scan(&post.ID, &post.Category.ID, &post.Category.Name,
|
||||||
|
&date_unix, &post.Title, &post.URL, &post.Body); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,5 +2,6 @@ UPDATE OR REPLACE `post`
|
|||||||
SET
|
SET
|
||||||
`category_id` = ?,
|
`category_id` = ?,
|
||||||
`title` = ?,
|
`title` = ?,
|
||||||
|
`url` = ?,
|
||||||
`body` = ?
|
`body` = ?
|
||||||
WHERE `post_id` = ?;
|
WHERE `post_id` = ?;
|
@ -4,6 +4,7 @@ SELECT
|
|||||||
`category`.`name` AS `category`,
|
`category`.`name` AS `category`,
|
||||||
`post`.`date`,
|
`post`.`date`,
|
||||||
`post`.`title`,
|
`post`.`title`,
|
||||||
|
`post`.`url`,
|
||||||
`post`.`body`
|
`post`.`body`
|
||||||
FROM `post`
|
FROM `post`
|
||||||
LEFT JOIN `category`
|
LEFT JOIN `category`
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
INSERT INTO `post`
|
INSERT INTO `post`
|
||||||
(`category_id`, `date`, `title`, `body`)
|
(`category_id`, `date`, `title`, `url`, `body`)
|
||||||
VALUES
|
VALUES
|
||||||
(?, ?, ?, ?);
|
(?, ?, ?, ?, ?);
|
@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `post` (
|
|||||||
`category_id` INTEGER NOT NULL,
|
`category_id` INTEGER NOT NULL,
|
||||||
`date` INTEGER NOT NULL,
|
`date` INTEGER NOT NULL,
|
||||||
`title` TEXT NOT NULL,
|
`title` TEXT NOT NULL,
|
||||||
|
`url` TEXT NOT NULL DEFAULT "",
|
||||||
`body` TEXT NOT NULL,
|
`body` TEXT NOT NULL,
|
||||||
PRIMARY KEY (`post_id`),
|
PRIMARY KEY (`post_id`),
|
||||||
FOREIGN KEY (`category_id`)
|
FOREIGN KEY (`category_id`)
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.arav.su/Arav/dwelling-home/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
@ -24,10 +26,11 @@ type Post struct {
|
|||||||
Category Category
|
Category Category
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Title string
|
Title string
|
||||||
|
URL string
|
||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPost(category Category, title, body string) (*Post, error) {
|
func NewPost(category Category, title, url, body string) (*Post, error) {
|
||||||
if title == "" || body == "" {
|
if title == "" || body == "" {
|
||||||
return nil, errors.New("empty title or body is not allowed")
|
return nil, errors.New("empty title or body is not allowed")
|
||||||
}
|
}
|
||||||
@ -35,6 +38,7 @@ func NewPost(category Category, title, body string) (*Post, error) {
|
|||||||
Category: category,
|
Category: category,
|
||||||
Date: time.Now().UTC(),
|
Date: time.Now().UTC(),
|
||||||
Title: title,
|
Title: title,
|
||||||
|
URL: url,
|
||||||
Body: body}, nil
|
Body: body}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +48,22 @@ func (p *Post) PostID() string {
|
|||||||
return fmt.Sprint(name, "-", p.Date.UTC().Format("20060102-150405"))
|
return fmt.Sprint(name, "-", p.Date.UTC().Format("20060102-150405"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Post) PostURL(host string, rss bool) string {
|
||||||
|
if p.URL != "" {
|
||||||
|
if p.URL[0] == ':' {
|
||||||
|
lastColon := strings.IndexByte(p.URL[1:], ':')
|
||||||
|
service := p.URL[1 : lastColon+1]
|
||||||
|
return strings.Replace(p.URL, p.URL[:lastColon+2],
|
||||||
|
util.GetServiceByHost(host, service), 1)
|
||||||
|
} else if rss && p.URL[0] == '/' {
|
||||||
|
return util.GetServiceByHost(host, "") + p.URL
|
||||||
|
}
|
||||||
|
} else if p.URL == "" && rss {
|
||||||
|
return util.GetServiceByHost(host, "") + "/mindflow#" + p.PostID()
|
||||||
|
}
|
||||||
|
return p.URL
|
||||||
|
}
|
||||||
|
|
||||||
type Mindflow interface {
|
type Mindflow interface {
|
||||||
NewPost(post *Post) error
|
NewPost(post *Post) error
|
||||||
EditPost(post *Post) error
|
EditPost(post *Post) error
|
||||||
|
@ -18,7 +18,7 @@ form#add {
|
|||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
"c c"
|
"c c"
|
||||||
"t t"
|
"t u"
|
||||||
"b b"
|
"b b"
|
||||||
"a a";
|
"a a";
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
@ -28,6 +28,7 @@ form#add {
|
|||||||
|
|
||||||
form#add select { grid-area: c; }
|
form#add select { grid-area: c; }
|
||||||
form#add input[name="title"] { grid-area: t; }
|
form#add input[name="title"] { grid-area: t; }
|
||||||
|
form#add input[name="url"] { grid-area: u; }
|
||||||
form#add textarea[name="body"] { grid-area: b; }
|
form#add textarea[name="body"] { grid-area: b; }
|
||||||
form#add button[type="submit"] { grid-area: a; }
|
form#add button[type="submit"] { grid-area: a; }
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ function edit_post(e) {
|
|||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.append("category", get_field(e.target, "category"))
|
data.append("category", get_field(e.target, "category"))
|
||||||
data.append("title", get_field(e.target, "title"))
|
data.append("title", get_field(e.target, "title"))
|
||||||
|
data.append("url", get_field(e.target, "url"))
|
||||||
data.append("body", get_field(e.target, "body"))
|
data.append("body", get_field(e.target, "body"))
|
||||||
fetch(`/api/mindflow/${get_field(e.target, "post-id")}`, {method: "PATCH", body: data})
|
fetch(`/api/mindflow/${get_field(e.target, "post-id")}`, {method: "PATCH", body: data})
|
||||||
.catch(e => console.log(e))
|
.catch(e => console.log(e))
|
||||||
|
@ -31,6 +31,9 @@ block content
|
|||||||
header
|
header
|
||||||
a(href=`#${post.PostID()}`)
|
a(href=`#${post.PostID()}`)
|
||||||
h3= post.Category.Name + ": " + post.Title
|
h3= post.Category.Name + ": " + post.Title
|
||||||
|
if (post.URL != "")
|
||||||
|
p Link:
|
||||||
|
a(href=post.PostURL(r.Host, false)) #{post.PostURL(r.Host, false)}
|
||||||
each line in strings.Split(post.Body, "\n")
|
each line in strings.Split(post.Body, "\n")
|
||||||
p!= line
|
p!= line
|
||||||
footer
|
footer
|
||||||
|
@ -37,6 +37,7 @@ block content
|
|||||||
each category in categories
|
each category in categories
|
||||||
option(value=category.ID) #{category.Name}
|
option(value=category.ID) #{category.Name}
|
||||||
input(type='text', placeholder='Title' name='title' required='')
|
input(type='text', placeholder='Title' name='title' required='')
|
||||||
|
input(type='text', placeholder='URL' name='url')
|
||||||
textarea(placeholder='Body post' name='body' required='')
|
textarea(placeholder='Body post' name='body' required='')
|
||||||
button(type="submit") Add
|
button(type="submit") Add
|
||||||
section
|
section
|
||||||
@ -55,6 +56,7 @@ block content
|
|||||||
option(value=category.ID) #{category.Name}
|
option(value=category.ID) #{category.Name}
|
||||||
input(type='hidden', name='post-id' value=post.ID)
|
input(type='hidden', name='post-id' value=post.ID)
|
||||||
input(type='text', placeholder='Title' name='title' value=post.Title required='')
|
input(type='text', placeholder='Title' name='title' value=post.Title required='')
|
||||||
|
input(type='text', placeholder='URL' name='url' value=post.URL)
|
||||||
textarea(placeholder='Body post' name='body' required='')!= post.Body
|
textarea(placeholder='Body post' name='body' required='')!= post.Body
|
||||||
button(name='edit-post') Edit
|
button(name='edit-post') Edit
|
||||||
button(name='delete-post') Delete
|
button(name='delete-post') Delete
|
||||||
|
@ -14,7 +14,7 @@ rss(version='2.0')
|
|||||||
category= post.Category.Name
|
category= post.Category.Name
|
||||||
guid!= `${post.PostID()}`
|
guid!= `${post.PostID()}`
|
||||||
pubDate= util.ToClientTimezone(post.Date, r).Format(time.RFC1123Z)
|
pubDate= util.ToClientTimezone(post.Date, r).Format(time.RFC1123Z)
|
||||||
| <link>#{host}/mindflow##{post.PostID()}</link>
|
| <link>#{post.PostURL(r.Host, true)}</link>
|
||||||
author!= author
|
author!= author
|
||||||
description
|
description
|
||||||
| <![CDATA[
|
| <![CDATA[
|
||||||
|
Loading…
Reference in New Issue
Block a user