временная реализация RSS

This commit is contained in:
lost+skunk 2024-07-05 11:08:32 +03:00
parent 68248094e8
commit 8b839f9406
6 changed files with 135 additions and 33 deletions

View File

@ -60,6 +60,9 @@ func Router() {
}
p, _ := strconv.Atoi(arg("p"))
skunky.Page = p
if arg("atom") == "true" {
skunky.atom = true
}
// пути
switch path[1] {

View File

@ -200,15 +200,55 @@ func (s skunkyart) NavBase(c dlist) string {
func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...dlist) string {
var list strings.Builder
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(`"><div class="block"><img src="`)
list.WriteString(`"><img src="`)
list.WriteString(url)
list.WriteString(`" width="15%"></a><br><a href="`)
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("/")
@ -231,8 +271,16 @@ func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...dlist) s
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]))
}
return list.String()
}

View File

@ -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,8 +175,10 @@ func (s skunkyart) GRUser() {
s.ReturnHTTPError(400)
}
if !s.atom {
s.ExecuteTemplate("html/gruser.htm", &s)
}
}
// посты
func (s skunkyart) Deviation(author, postname string) {
@ -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 {

43
atom.xml Normal file
View File

@ -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>

View File

@ -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}}">

View File

@ -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">