This commit is contained in:
partisan 2024-08-22 22:10:47 +02:00
parent d69f561c55
commit 5892c0af38
3 changed files with 72 additions and 29 deletions

View file

@ -5,13 +5,9 @@ Spitfire Browser is a fast, secure, and elegant web browser built on Firefox. Th
## TO-DO: ## TO-DO:
- [ ] Add screenshots - [ ] Add screenshots
- [ ] Add search-engine test - [ ] Add search-engine test
- [ ] Add working downloads - [ ] Add working downloads
- [X] Add blog/updates - [X] Add blog/updates
- [ ] Add config file - [ ] Add config file
### Blog entries should be fromated this way: ### Blog entries should be fromated this way:
@ -31,6 +27,14 @@ a: AUTHOR
Vivamus luctus egestas leo. Phasellus faucibus molestie nisl. Etiam commodo dui eget wisi. Donec vitae arcu. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam neque. Suspendisse sagittis ultrices augue. Suspendisse nisl. Etiam sapien elit, consequat eget, tristique non, venenatis quis, ante. Phasellus rhoncus. Maecenas libero. Vivamus luctus egestas leo. Phasellus faucibus molestie nisl. Etiam commodo dui eget wisi. Donec vitae arcu. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam neque. Suspendisse sagittis ultrices augue. Suspendisse nisl. Etiam sapien elit, consequat eget, tristique non, venenatis quis, ante. Phasellus rhoncus. Maecenas libero.
``` ```
*default path:*
```
/data/news/1.md
/data/news/2.md
...
```
### Based on: ### Based on:
Stellar by HTML5 UP Stellar by HTML5 UP

26
main.go
View file

@ -116,6 +116,32 @@ func main() {
renderTemplate(w, "download-linux.html", nil) renderTemplate(w, "download-linux.html", nil)
}) })
// Route for generating the RSS feed for all blogs
http.HandleFunc("/rss", func(w http.ResponseWriter, r *http.Request) {
siteURL := fmt.Sprintf("http://%s", r.Host) // or you can use a fixed base URL
generateAtomFeed(w, blogs, siteURL)
})
// Route for generating the RSS feed for a specific blog
http.HandleFunc("/rss/", func(w http.ResponseWriter, r *http.Request) {
pathParts := strings.Split(r.URL.Path, "/")
if len(pathParts) < 3 {
http.NotFound(w, r)
return
}
blogName := pathParts[2]
for _, blog := range blogs {
if blog.Name == blogName {
siteURL := fmt.Sprintf("http://%s", r.Host) // or you can use a fixed base URL
generateBlogAtomFeed(w, blog, siteURL)
return
}
}
http.NotFound(w, r)
})
// Define route handlers // Define route handlers
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" { if r.URL.Path == "/" {

59
rss.go
View file

@ -6,62 +6,75 @@ import (
"time" "time"
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
"github.com/russross/blackfriday/v2" // Import the Markdown library
) )
func generateRSSFeed(w http.ResponseWriter, blogs []Blog, siteURL string) { func generateAtomFeed(w http.ResponseWriter, blogs []Blog, siteURL string) {
feed := &feeds.Feed{ feed := &feeds.Feed{
Title: "My Blog", Title: "Spitfire News",
Link: &feeds.Link{Href: siteURL}, Link: &feeds.Link{Href: siteURL},
Description: "A blog about various topics.", Description: "Blog about Spitfire browser news/updates.", // Blog subtitle (Atom uses "subtitle" for description)
Author: &feeds.Author{Name: "Your Name", Email: "your-email@example.com"}, Author: &feeds.Author{Name: "Internet Addict", Email: "noone@none.no"},
Created: time.Now(), Created: time.Now(),
} }
for _, blog := range blogs { for _, blog := range blogs {
for _, entry := range blog.Entries { for _, entry := range blog.Entries {
// Convert Markdown content to HTML
htmlContent := blackfriday.Run([]byte(entry.Content))
feed.Items = append(feed.Items, &feeds.Item{ feed.Items = append(feed.Items, &feeds.Item{
Title: fmt.Sprintf("Entry %d", entry.Number), // Use entry number as title Title: entry.Title,
Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number)}, Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number), Rel: "alternate"},
Description: entry.Content, Description: entry.Description, // This can be used as the summary
Created: entry.Date, Author: &feeds.Author{Name: entry.Author},
Id: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number),
Updated: entry.Date,
Content: string(htmlContent),
}) })
} }
} }
rss, err := feed.ToRss() atom, err := feed.ToAtom()
if err != nil { if err != nil {
http.Error(w, "Error generating RSS feed", http.StatusInternalServerError) http.Error(w, "Error generating Atom feed", http.StatusInternalServerError)
return return
} }
w.Header().Set("Content-Type", "application/rss+xml") w.Header().Set("Content-Type", "application/atom+xml")
w.Write([]byte(rss)) w.Write([]byte(atom))
} }
func generateBlogRSSFeed(w http.ResponseWriter, blog Blog, siteURL string) { func generateBlogAtomFeed(w http.ResponseWriter, blog Blog, siteURL string) {
feed := &feeds.Feed{ feed := &feeds.Feed{
Title: blog.Name, Title: blog.Name,
Link: &feeds.Link{Href: fmt.Sprintf("%s/%s", siteURL, blog.Name)}, Link: &feeds.Link{Href: fmt.Sprintf("%s/%s", siteURL, blog.Name)},
Description: blog.Name, Description: blog.Name, // Blog subtitle (Atom uses "subtitle" for description)
Author: &feeds.Author{Name: "Your Name", Email: "your-email@example.com"}, Author: &feeds.Author{Name: "Internet Addict", Email: "noone@none.no"},
Created: time.Now(), Created: time.Now(),
} }
for _, entry := range blog.Entries { for _, entry := range blog.Entries {
// Convert Markdown content to HTML
htmlContent := blackfriday.Run([]byte(entry.Content))
feed.Items = append(feed.Items, &feeds.Item{ feed.Items = append(feed.Items, &feeds.Item{
Title: fmt.Sprintf("Entry %d", entry.Number), // Use entry number as title Title: entry.Title,
Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number)}, Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number), Rel: "alternate"},
Description: entry.Content, Description: entry.Description, // This can be used as the summary
Created: entry.Date, Author: &feeds.Author{Name: entry.Author},
Id: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number),
Updated: entry.Date,
Content: string(htmlContent),
}) })
} }
rss, err := feed.ToRss() atom, err := feed.ToAtom()
if err != nil { if err != nil {
http.Error(w, "Error generating RSS feed", http.StatusInternalServerError) http.Error(w, "Error generating Atom feed", http.StatusInternalServerError)
return return
} }
w.Header().Set("Content-Type", "application/rss+xml") w.Header().Set("Content-Type", "application/atom+xml")
w.Write([]byte(rss)) w.Write([]byte(atom))
} }