krz/skunky-art

Alternative privacy frontend for DeviantArt.

clone: git clone https://gitbay.org/krz/skunky-art.git

8b839f94063704782872cc11251975cfeae4584c

unsigned

author: lost+skunk <skunky@ebloid.ru> · 2024-07-05T08:08:32Z

временная реализация RSS
 app/router.go   |   3 ++
 app/util.go     | 102 +++++++++++++++++++++++++++++++++++++++++---------------
 app/wraper.go   |  14 ++++++--
 atom.xml        |  43 ++++++++++++++++++++++++
 html/gruser.htm |   4 +--
 html/list.htm   |   2 +-
 6 files changed, 135 insertions(+), 33 deletions(-)

diff --git a/app/router.go b/app/router.go
index 4da2f7d..d7f48b8 100644
--- a/app/router.go
+++ b/app/router.go
@@ -60,6 +60,9 @@ func Router() {
 		}
 		p, _ := strconv.Atoi(arg("p"))
 		skunky.Page = p
+		if arg("atom") == "true" {
+			skunky.atom = true
+		}
 
 		// пути
 		switch path[1] {
diff --git a/app/util.go b/app/util.go
index cda0ffc..0d36fd8 100644
--- a/app/util.go
+++ b/app/util.go
@@ -200,39 +200,87 @@ func (s skunkyart) NavBase(c dlist) string {
 
 func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...dlist) string {
 	var list strings.Builder
-	list.WriteString(`<div class="content">`)
+	if !s.atom {
+		list.WriteString(`<div class="content">`)
+	} else {
+		list.WriteString(`<?xml version="1.0" encoding="UTF-8"?><feed xmlns:media="http://search.yahoo.com/mrss" xmlns="http://www.w3.org/2005/Atom">`)
+		list.WriteString(`<title>SkunkyArt</title>`)
+		// list.WriteString(`<link rel="alternate" href="HOMEPAGE_URL"/><link href="FEED_URL" rel="self"/>`)
+	}
 	for _, data := range devs {
 		url := devianter.UrlFromMedia(data.Media)
+		if s.atom {
+			id := strconv.Itoa(data.ID)
+			list.WriteString(`<entry><author><name>`)
+			list.WriteString(data.Author.Username)
+			list.WriteString(`</name></author><title>`)
+			list.WriteString(data.Title)
+			list.WriteString(`</title><link rel="alternate" type="text/html" href="`)
+			list.WriteString(CFG.Base_uri)
+			list.WriteString("/post/")
+			list.WriteString(data.Author.Username)
+			list.WriteString("/atom-")
+			list.WriteString(id)
+			list.WriteString(`"/><id>`)
+			list.WriteString(id)
+			list.WriteString(`</id><published>`)
+			list.WriteString(data.PublishedTime.UTC().Format("Mon, 02 Jan 2006 15:04:05 -0700"))
+			list.WriteString(`</published>`)
+			list.WriteString(`<media:group><media:title>`)
+			list.WriteString(data.Title)
+			list.WriteString(`</media:title><media:thumbinal url="`)
+			list.WriteString(url)
+			list.WriteString(`"/></media:group><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><a href="`)
+			list.WriteString(data.Url)
+			list.WriteString(`"><img src="`)
+			list.WriteString(url)
+			list.WriteString(`"/></a><p>`)
+			list.WriteString(ParseDescription(data.TextContent))
+			list.WriteString(`</p></div></content></entry>`)
+		} else {
+			list.WriteString(`<div class="block">`)
+			if url != "" {
+				list.WriteString(`<a title="open/download" href="`)
+				list.WriteString(url)
+				list.WriteString(`"><img src="`)
+				list.WriteString(url)
+				list.WriteString(`" width="15%"></a>`)
+			} else {
+				list.WriteString(`<h1>[ TEXT ]</h1>`)
+			}
+			list.WriteString(`<br><a href="`)
+			list.WriteString("/post/")
+			list.WriteString(data.Author.Username)
+			list.WriteString("/")
+			list.WriteString(data.Url[27:][strings.Index(data.Url[27:], "/art/")+5:])
+			list.WriteString(`">`)
+			list.WriteString(data.Author.Username)
+			list.WriteString(" - ")
+			list.WriteString(data.Title)
 
-		list.WriteString(`<a title="open/download" href="`)
-		list.WriteString(url)
-		list.WriteString(`"><div class="block"><img src="`)
-		list.WriteString(url)
-		list.WriteString(`" width="15%"></a><br><a href="`)
-		list.WriteString("/post/")
-		list.WriteString(data.Author.Username)
-		list.WriteString("/")
-		list.WriteString(data.Url[27:][strings.Index(data.Url[27:], "/art/")+5:])
-		list.WriteString(`">`)
-		list.WriteString(data.Author.Username)
-		list.WriteString(" - ")
-		list.WriteString(data.Title)
-
-		// шильдики нсфв, аи и ежедневного поста
-		if data.NSFW {
-			list.WriteString(` [<span class="nsfw">NSFW</span>]`)
-		}
-		if data.AI {
-			list.WriteString(" [🤖]")
-		}
-		if data.DD {
-			list.WriteString(` [<span class="dd">DD</span>]`)
+			// шильдики нсфв, аи и ежедневного поста
+			if data.NSFW {
+				list.WriteString(` [<span class="nsfw">NSFW</span>]`)
+			}
+			if data.AI {
+				list.WriteString(" [🤖]")
+			}
+			if data.DD {
+				list.WriteString(` [<span class="dd">DD</span>]`)
+			}
+
+			list.WriteString("</a></div>")
 		}
+	}
 
-		list.WriteString("</a></div>")
+	if s.atom {
+		list.WriteString("</feed>")
+		s.Writer.Write([]byte(list.String()))
+		return ""
+	} else {
+		list.WriteString("</div>")
+		list.WriteString(s.NavBase(content[0]))
 	}
-	list.WriteString("</div>")
-	list.WriteString(s.NavBase(content[0]))
 
 	return list.String()
 }
diff --git a/app/wraper.go b/app/wraper.go
index f3f025d..757602c 100644
--- a/app/wraper.go
+++ b/app/wraper.go
@@ -20,6 +20,7 @@ type skunkyart struct {
 	Type      rune
 	Query     string
 	Page      int
+	atom      bool
 	Templates struct {
 		GroupUser struct {
 			GR           devianter.GRuser
@@ -64,6 +65,7 @@ func (s skunkyart) GRUser() {
 	switch s.Type {
 	case 'a':
 		g := group.GR
+		s.atom = false
 		for _, x := range g.Gruser.Page.Modules {
 			switch x.Name {
 			case "about", "group_about":
@@ -173,7 +175,9 @@ func (s skunkyart) GRUser() {
 		s.ReturnHTTPError(400)
 	}
 
-	s.ExecuteTemplate("html/gruser.htm", &s)
+	if !s.atom {
+		s.ExecuteTemplate("html/gruser.htm", &s)
+	}
 }
 
 // посты
@@ -217,13 +221,17 @@ func (s skunkyart) Deviation(author, postname string) {
 
 func (s skunkyart) DD() {
 	dd := devianter.DailyDeviationsFunc(s.Page)
-	s.ExecuteTemplate("html/list.htm", s.DeviationList(dd.Deviations, dlist{
+	ddparsed := s.DeviationList(dd.Deviations, dlist{
 		Pages: 0,
 		More:  dd.HasMore,
-	}))
+	})
+	if !s.atom {
+		s.ExecuteTemplate("html/list.htm", &ddparsed)
+	}
 }
 
 func (s skunkyart) Search() {
+	s.atom = false
 	var e error
 	ss := &s.Templates.Search
 	switch s.Type {
diff --git a/atom.xml b/atom.xml
new file mode 100644
index 0000000..784f37d
--- /dev/null
+++ b/atom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
+  <link rel="self" href="https://inv.clovius.club/feed/channel/UCuxpxCCevIlF-k-K5YU8XPA"/>
+  <id>yt:channel:UCuxpxCCevIlF-k-K5YU8XPA</id>
+  <yt:channelId>UCuxpxCCevIlF-k-K5YU8XPA</yt:channelId>
+  <icon>https://yt3.googleusercontent.com/ytc/AIdro_n7bKr9iusclFjvYw3U8UR74iTCoMcdGTKI3h55SOG8mSsY=s900-c-k-c0x00ffffff-no-rj</icon>
+  <title>Test</title>
+  <link rel="alternate" href="https://skunky.ebloid.ru"/>
+  <author>
+    <name>lost+skunk</name>
+    <uri>https://skunky.ebloid.ru</uri>
+  </author>
+  <image>
+    <url>https://ebloid.ru/_matrix/media/v3/download/ebloid.ru/enfAtfdjzCQMRNBgLXmiURfJ?allow_redirect=true</url>
+    <title>lost+skunk</title>
+    <link rel="self" href="https://skunky.ebloid.ru"/>
+  </image>
+  <entry>
+    <title>Test</title>
+    <link rel="alternate" href="https://2ip.ua"/>
+    <author>
+      <name>lost+skunk</name>
+      <uri>https://skunky.ebloid.ru</uri>
+    </author>
+    <content type="xhtml">
+      <div xmlns="http://www.w3.org/1999/xhtml">
+        <a href="https://2ip.ua">
+          <img src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/526e735c-e3da-4542-a339-72ccdf827a00/dh3mfuq-5bd6472c-68f4-428d-bb90-8d461fc21410.jpg/v1/fill/w_1920,h_1080/image.gif?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTA4MCIsInBhdGgiOiJcL2ZcLzUyNmU3MzVjLWUzZGEtNDU0Mi1hMzM5LTcyY2NkZjgyN2EwMFwvZGgzbWZ1cS01YmQ2NDcyYy02OGY0LTQyOGQtYmI5MC04ZDQ2MWZjMjE0MTAuanBnIiwid2lkdGgiOiI8PTE5MjAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.S_1DGdd29F5l6Y46Q_bumtGlEEUf_WawZsmF8kBygBs"/>
+        </a>
+        <p>test</p>
+      </div>
+    </content>
+    <published>2024-07-04T00:37:55+00:00</published>
+    <media:group>
+      <media:title>GM Just Announced Their Shutting Down Production in America and Firing Their Workers</media:title>
+      <media:thumbnail url="https://ebloid.ru/_matrix/media/v3/download/ebloid.ru/enfAtfdjzCQMRNBgLXmiURfJ?allow_redirect=true" width="320" height="180"/>
+      <media:description>test</media:description>
+    </media:group>
+    <media:community>
+      <media:statistics views="91247"/>
+    </media:community>
+  </entry>
+</feed>
diff --git a/html/gruser.htm b/html/gruser.htm
index 9035a88..89347aa 100644
--- a/html/gruser.htm
+++ b/html/gruser.htm
@@ -13,8 +13,8 @@
     <main>
         <header>
             <h1><a href="/">HOME</a> | <a href="/dd">DD</a>
-            | <a href="?q={{.Templates.GroupUser.GR.Owner.Username}}&type={{if eq .Type 'a'}}gallery">Gallery</a></h1>{{else}}about">About</a></h1>
-            {{end}}
+            | <a href="?q={{.Templates.GroupUser.GR.Owner.Username}}&type={{if eq .Type 'a'}}gallery">Gallery{{else}}about">About{{end}}</a>
+             | <a href="?q={{.Templates.GroupUser.GR.Owner.Username}}&type=gallery&atom=true">RSS</a></h1>
              <form method="get" action="/search">
                 <input type="gallery" name="q" placeholder="Search for ..." autocomplete="off" autocapitalize="none" spellcheck="false">
                 <input type="hidden" name="usr" value="{{.Templates.GroupUser.GR.Owner.Username}}">
diff --git a/html/list.htm b/html/list.htm
index 42bd2a5..23d48e5 100644
--- a/html/list.htm
+++ b/html/list.htm
@@ -6,7 +6,7 @@
     </head>
     <main>
         <header>
-            <h1><a href="/">HOME</a> | <a href="/dd">DD</a></h1>
+            <h1><a href="/">HOME</a> | <a href="/dd">DD</a> | <a href="?atom=true">RSS</a></h1>
             <form method="get" action="/search">
                 <input type="text" name="q" placeholder="Search for ..." autocomplete="off" autocapitalize="none" spellcheck="false">
                 <select name="type">