From cbafaa54d79d73fd1cc56ecba540d4f763591100 Mon Sep 17 00:00:00 2001 From: lost+skunk Date: Fri, 14 Jun 2024 20:04:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB=D1=8C=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8=D0=B8,=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D1=82=D1=8B=20=D0=B8=20=D0=B5=D0=B6=D0=B5?= =?UTF-8?q?=D0=B4=D0=BD=D0=B5=D0=B2=D0=BD=D1=8B=D0=B5=20=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ app/router.go | 2 + app/wraper.go | 125 ++++++++++++++++++++++++++++++++++++++++---- config.example.json | 12 +++++ css/skunky.css | 5 ++ html/list.htm | 21 ++++++++ html/search.htm | 1 - main.go | 8 ++- 8 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 .gitignore create mode 100644 config.example.json create mode 100644 html/list.htm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4686488 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +**/cache +**/config.json +**/skunkyart diff --git a/app/router.go b/app/router.go index b4af3f1..e53f3ce 100644 --- a/app/router.go +++ b/app/router.go @@ -60,6 +60,8 @@ func Router() { skunky.Deviation(url[:slash], url[slash+1:]) case "search": skunky.Search() + case "dd": + skunky.DD() case "media": skunky.Emojitar(url) case "about": diff --git a/app/wraper.go b/app/wraper.go index d8a459f..e252530 100644 --- a/app/wraper.go +++ b/app/wraper.go @@ -47,7 +47,77 @@ func (s skunkyart) httperr(status int) { wr(s.Writer, msg.String()) } -func (s skunkyart) DeviationList(devs []devianter.Deviation) string { +// навигация по страницам +type dlist struct { + Pages int + More bool +} + +// FIXME: на некоротрых артах первая страница может вызывать полное отсутствие панели навигации. +func (s skunkyart) NavBase(c dlist) string { + // TODO: сделать понятнее + // навигация по страницам + var list strings.Builder + list.WriteString("
") + p := s.Page + + // функция для генерации ссылок + prevrev := func(msg string, page int, onpage bool) { + if !onpage { + list.WriteString(``) + list.WriteString(msg) + list.WriteString(" ") + } else { + list.WriteString(strconv.Itoa(page)) + list.WriteString(" ") + } + } + + // вперёд-назад + if p > 1 { + prevrev("<= Prev |", p-1, false) + } else { + p = 1 + } + + if c.Pages > 0 { + // назад + for x := p - 6; x < p && x > 0; x++ { + prevrev(strconv.Itoa(x), x, false) + } + + // вперёд + for x := p; x <= p+6; x++ { + if x == p { + prevrev("", x, true) + x++ + } + + if x > p { + prevrev(strconv.Itoa(x), x, false) + } + } + } + + // вперёд-назад + if c.More { + prevrev("| Next =>", p+1, false) + } + + return list.String() +} + +func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...dlist) string { var list strings.Builder list.WriteString(`
`) for _, data := range devs { @@ -81,6 +151,8 @@ func (s skunkyart) DeviationList(devs []devianter.Deviation) string { list.WriteString("
") } list.WriteString("") + list.WriteString(s.NavBase(content[0])) + return list.String() } @@ -102,7 +174,6 @@ func (s skunkyart) Deviation(author, postname string) { // время публикации post.StringTime = post.Post.Deviation.PublishedTime.UTC().String() - println(post.Post.Description) // хештэги for _, x := range post.Post.Deviation.Extended.Tags { var tag strings.Builder @@ -115,34 +186,52 @@ func (s skunkyart) Deviation(author, postname string) { post.Tags += tag.String() } + // FIXME: первый комментарий не отображается. // генерация комментов var cmmts strings.Builder - var replied map[int]string - _ = replied + replied := make(map[int]string) c := devianter.CommentsFunc(id, post.Post.Comments.Cursor, s.Page, 1) cmmts.WriteString("
Comments: ") cmmts.WriteString(strconv.Itoa(c.Total)) cmmts.WriteString("") for _, x := range c.Thread { - cmmts.WriteString(`

0 { + cmmts.WriteString(` reply`) + } + cmmts.WriteString(`">

") + cmmts.WriteString(`">`) cmmts.WriteString(x.User.Username) cmmts.WriteString(" ") + if x.Parent > 0 { + cmmts.WriteString(` In reply to `) + if replied[x.Parent] == "" { + cmmts.WriteString("???") + } else { + cmmts.WriteString(replied[x.Parent]) + } + cmmts.WriteString("") + } + cmmts.WriteString(" [") cmmts.WriteString(x.Posted.UTC().String()) - cmmts.WriteString("

") + cmmts.WriteString("]

") cmmts.WriteString(x.Comment) cmmts.WriteString("

👍: ") cmmts.WriteString(strconv.Itoa(x.Likes)) @@ -150,7 +239,12 @@ func (s skunkyart) Deviation(author, postname string) { cmmts.WriteString(strconv.Itoa(x.Replies)) cmmts.WriteString("

\n") } + cmmts.WriteString(s.NavBase(dlist{ + Pages: 0, + More: c.HasMore, + })) cmmts.WriteString("
") + post.Comments = cmmts.String() s.exe("html/deviantion.htm", &post) @@ -159,6 +253,14 @@ func (s skunkyart) Deviation(author, postname string) { } } +func (s skunkyart) DD() { + dd := devianter.DailyDeviationsFunc(s.Page) + s.exe("html/list.htm", s.DeviationList(dd.Deviations, dlist{ + Pages: 0, + More: dd.HasMore, + })) +} + func (s skunkyart) Search() { // тут всё и так понятно if s.Type == 'a' || s.Type == 't' || s.Type == 'g' { @@ -170,7 +272,10 @@ func (s skunkyart) Search() { var e error srch.Search, e = devianter.SearchFunc(s.Query, s.Page, s.Type) err(e) - srch.List = s.DeviationList(srch.Search.Results) + srch.List = s.DeviationList(srch.Search.Results, dlist{ + Pages: srch.Search.Pages, + More: srch.Search.HasMore, + }) s.exe("html/search.htm", &srch) } else { diff --git a/config.example.json b/config.example.json new file mode 100644 index 0000000..1d979bd --- /dev/null +++ b/config.example.json @@ -0,0 +1,12 @@ +{ + "listen": "0.0.0.0:3003", + "base_uri": null, + "cache": { + "enabled": true, + "path": "cache", + "lifetime": null, + "max_size": 10000 + }, + "proxy": false, + "nsfw": false +} \ No newline at end of file diff --git a/css/skunky.css b/css/skunky.css index ef281ce..4a4af0d 100644 --- a/css/skunky.css +++ b/css/skunky.css @@ -47,6 +47,11 @@ form input, button, select { .msg:hover { background-color: #134134; } +.reply { + border-radius: 0px 2px 2px 0px; + border-left: #258268 solid; + margin-left: 40px; +} .dd { color: rgb(160, 0, 147); } diff --git a/html/list.htm b/html/list.htm new file mode 100644 index 0000000..42bd2a5 --- /dev/null +++ b/html/list.htm @@ -0,0 +1,21 @@ + + + + SkunkyArt + + +
+
+

HOME | DD

+
+ + + +
+
+ {{.}} +
+ \ No newline at end of file diff --git a/html/search.htm b/html/search.htm index 4ef9fbd..8ab9438 100644 --- a/html/search.htm +++ b/html/search.htm @@ -21,7 +21,6 @@

Total resuls: {{.Search.Total}}

{{end}} {{.List}} - {{.Search.Pages}} {{else}}

No results :(

{{end}} diff --git a/main.go b/main.go index 412f4fa..eab427b 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,13 @@ package main -import "skunkyart/app" +import ( + "skunkyart/app" + + "git.macaw.me/skunky/devianter" +) func main() { + devianter.UpdateCSRF() + app.Router() }