diff --git a/README.md b/README.md index 954737a..eb642cd 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,9 @@ Spitfire Browser is a fast, secure, and elegant web browser built on Firefox. Th ## TO-DO: - [ ] Add screenshots - - [ ] Add search-engine test - - [ ] Add working downloads - -- [X] Add blog/updates - +- [X] Add blog/updates - [ ] Add config file ### 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. ``` +*default path:* + +``` +/data/news/1.md +/data/news/2.md +... +``` + ### Based on: Stellar by HTML5 UP @@ -38,4 +42,4 @@ html5up.net | @ajlkn ### Licence: -This project is licensed under the Creative Commons Attribution 3.0 License (CCA 3.0). For more details, see the LICENSE file. \ No newline at end of file +This project is licensed under the Creative Commons Attribution 3.0 License (CCA 3.0). For more details, see the LICENSE file. diff --git a/main.go b/main.go index aed5dde..d961f10 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,32 @@ func main() { 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 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { diff --git a/rss.go b/rss.go index 80c3665..4f5a74f 100644 --- a/rss.go +++ b/rss.go @@ -6,62 +6,75 @@ import ( "time" "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{ - Title: "My Blog", + Title: "Spitfire News", Link: &feeds.Link{Href: siteURL}, - Description: "A blog about various topics.", - Author: &feeds.Author{Name: "Your Name", Email: "your-email@example.com"}, + Description: "Blog about Spitfire browser news/updates.", // Blog subtitle (Atom uses "subtitle" for description) + Author: &feeds.Author{Name: "Internet Addict", Email: "noone@none.no"}, Created: time.Now(), } for _, blog := range blogs { for _, entry := range blog.Entries { + // Convert Markdown content to HTML + htmlContent := blackfriday.Run([]byte(entry.Content)) + feed.Items = append(feed.Items, &feeds.Item{ - Title: fmt.Sprintf("Entry %d", entry.Number), // Use entry number as title - Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number)}, - Description: entry.Content, - Created: entry.Date, + Title: entry.Title, + Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number), Rel: "alternate"}, + Description: entry.Description, // This can be used as the summary + 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 { - http.Error(w, "Error generating RSS feed", http.StatusInternalServerError) + http.Error(w, "Error generating Atom feed", http.StatusInternalServerError) return } - w.Header().Set("Content-Type", "application/rss+xml") - w.Write([]byte(rss)) + w.Header().Set("Content-Type", "application/atom+xml") + 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{ Title: blog.Name, Link: &feeds.Link{Href: fmt.Sprintf("%s/%s", siteURL, blog.Name)}, - Description: blog.Name, - Author: &feeds.Author{Name: "Your Name", Email: "your-email@example.com"}, + Description: blog.Name, // Blog subtitle (Atom uses "subtitle" for description) + Author: &feeds.Author{Name: "Internet Addict", Email: "noone@none.no"}, Created: time.Now(), } for _, entry := range blog.Entries { + // Convert Markdown content to HTML + htmlContent := blackfriday.Run([]byte(entry.Content)) + feed.Items = append(feed.Items, &feeds.Item{ - Title: fmt.Sprintf("Entry %d", entry.Number), // Use entry number as title - Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number)}, - Description: entry.Content, - Created: entry.Date, + Title: entry.Title, + Link: &feeds.Link{Href: fmt.Sprintf("%s/%s/%d", siteURL, blog.Name, entry.Number), Rel: "alternate"}, + Description: entry.Description, // This can be used as the summary + 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 { - http.Error(w, "Error generating RSS feed", http.StatusInternalServerError) + http.Error(w, "Error generating Atom feed", http.StatusInternalServerError) return } - w.Header().Set("Content-Type", "application/rss+xml") - w.Write([]byte(rss)) + w.Header().Set("Content-Type", "application/atom+xml") + w.Write([]byte(atom)) }