diff --git a/main.go b/main.go index ccc6d8c..4271655 100644 --- a/main.go +++ b/main.go @@ -85,14 +85,26 @@ func main() { go watchForChanges(dataDir) + // Serve static files (CSS, JS, etc.) from the /assets directory http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))) + // Route Handlers http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { renderIndex(w) return } + if r.URL.Path == "/download" { + renderTemplate(w, "download.html", nil) + return + } + + if r.URL.Path == "/download-linux" { + renderTemplate(w, "download-linux.html", nil) + return + } + pathParts := strings.Split(r.URL.Path, "/") if len(pathParts) < 2 { http.NotFound(w, r) @@ -140,6 +152,116 @@ func main() { log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) } +func renderTemplate(w http.ResponseWriter, tmpl string, data interface{}) { + tmplPath := filepath.Join(templateDir, tmpl) + t, err := template.ParseFiles(tmplPath) + if err != nil { + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + log.Printf("Error parsing template %s: %v", tmpl, err) + return + } + + err = t.Execute(w, data) + if err != nil { + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + log.Printf("Error executing template %s: %v", tmpl, err) + } +} + +func renderIndex(w http.ResponseWriter) { + renderTemplate(w, "index.html", nil) +} + +func renderBlogEntry(w http.ResponseWriter, blogName string, entryNumber int) { + var blog Blog + for _, b := range blogs { + if b.Name == blogName { + blog = b + break + } + } + + var entry BlogEntry + var prevLink, nextLink string + for i, e := range blog.Entries { + if e.Number == entryNumber { + entry = e + if i > 0 { + prevLink = fmt.Sprintf("/%s/%d", blog.Name, blog.Entries[i-1].Number) + } + if i < len(blog.Entries)-1 { + nextLink = fmt.Sprintf("/%s/%d", blog.Name, blog.Entries[i+1].Number) + } + break + } + } + + htmlContent := blackfriday.Run([]byte(entry.Content)) + content := fmt.Sprintf("
%s
", htmlContent) + + pageData := PageData{ + Title: "", + Description: "", + BlogLinks: getBlogLinks(), + Content: template.HTML(content), + PrevLink: prevLink, + NextLink: nextLink, + } + + // Use the existing renderTemplate to render with a specific PageData type. + renderTemplate(w, "news.html", pageData) +} + +func renderAllBlogs(w http.ResponseWriter, r *http.Request, page int) { + var allEntries []BlogEntry + + for _, blog := range blogs { + allEntries = append(allEntries, blog.Entries...) + } + + sort.Slice(allEntries, func(i, j int) bool { + return allEntries[i].Date.After(allEntries[j].Date) + }) + + totalEntries := len(allEntries) + startIndex := (page - 1) * pageSize + endIndex := startIndex + pageSize + if startIndex >= totalEntries { + http.NotFound(w, r) + return + } + if endIndex > totalEntries { + endIndex = totalEntries + } + + pagedEntries := allEntries[startIndex:endIndex] + + var content strings.Builder + for _, entry := range pagedEntries { + htmlContent := blackfriday.Run([]byte(entry.Content)) + content.WriteString(fmt.Sprintf("
%s
", htmlContent)) + } + + var prevLink, nextLink string + if startIndex > 0 { + prevLink = fmt.Sprintf("/all?page=%d", page-1) + } + if endIndex < totalEntries { + nextLink = fmt.Sprintf("/all?page=%d", page+1) + } + + pageData := PageData{ + Title: "All Blogs", + Description: "Combined blog entries from all blogs.", + BlogLinks: getBlogLinks(), + Content: template.HTML(content.String()), + PrevLink: prevLink, + NextLink: nextLink, + } + + renderTemplate(w, "news.html", pageData) +} + func getBlogs(dir string) ([]Blog, error) { var blogs []Blog @@ -161,6 +283,14 @@ func getBlogs(dir string) ([]Blog, error) { return blogs, nil } +func getBlogLinks() []string { + var links []string + for _, blog := range blogs { + links = append(links, blog.Name) + } + return links +} + func getBlogEntries(dir string) (Blog, error) { var entries []BlogEntry @@ -344,132 +474,6 @@ func updateBlogEntries(blogName, path string) { log.Printf("Created new blog %s with entry %d", blogName, number) } -func renderBlogEntry(w http.ResponseWriter, blogName string, entryNumber int) { - var blog Blog - for _, b := range blogs { - if b.Name == blogName { - blog = b - break - } - } - - var entry BlogEntry - var prevLink, nextLink string - for i, e := range blog.Entries { - if e.Number == entryNumber { - entry = e - if i > 0 { - prevLink = fmt.Sprintf("/%s/%d", blog.Name, blog.Entries[i-1].Number) - } - if i < len(blog.Entries)-1 { - nextLink = fmt.Sprintf("/%s/%d", blog.Name, blog.Entries[i+1].Number) - } - break - } - } - - htmlContent := blackfriday.Run([]byte(entry.Content)) - content := fmt.Sprintf("
%s
", htmlContent) - - pageData := PageData{ - Title: "", - Description: "", - BlogLinks: getBlogLinks(), - Content: template.HTML(content), - PrevLink: prevLink, - NextLink: nextLink, - } - - renderTemplate(w, pageData) -} - -func getBlogLinks() []string { - var links []string - for _, blog := range blogs { - links = append(links, blog.Name) - } - return links -} - -func renderTemplate(w http.ResponseWriter, pageData PageData) { - tmpl, err := template.ParseFiles(filepath.Join(templateDir, "news.html")) - if err != nil { - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - log.Printf("Error parsing template: %v", err) - return - } - - err = tmpl.Execute(w, pageData) - if err != nil { - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - log.Printf("Error executing template: %v", err) - } -} - -func renderIndex(w http.ResponseWriter) { - tmpl, err := template.ParseFiles(filepath.Join(templateDir, "index.html")) - if err != nil { - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - log.Printf("Error parsing template: %v", err) - return - } - - err = tmpl.Execute(w, nil) - if err != nil { - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - log.Printf("Error executing template: %v", err) - - } -} - -func renderAllBlogs(w http.ResponseWriter, r *http.Request, page int) { - var allEntries []BlogEntry - - for _, blog := range blogs { - allEntries = append(allEntries, blog.Entries...) - } - - sort.Slice(allEntries, func(i, j int) bool { - return allEntries[i].Date.After(allEntries[j].Date) - }) - - totalEntries := len(allEntries) - startIndex := (page - 1) * pageSize - endIndex := startIndex + pageSize - if startIndex >= totalEntries { - http.NotFound(w, r) - return - } - if endIndex > totalEntries { - endIndex = totalEntries - } - - pagedEntries := allEntries[startIndex:endIndex] - - var content strings.Builder - for _, entry := range pagedEntries { - htmlContent := blackfriday.Run([]byte(entry.Content)) - content.WriteString(fmt.Sprintf("
%s
", htmlContent)) - } - - var prevLink, nextLink string - if startIndex > 0 { - prevLink = fmt.Sprintf("/all?page=%d", page-1) - } - if endIndex < totalEntries { - nextLink = fmt.Sprintf("/all?page=%d", page+1) - } - - renderTemplate(w, PageData{ - Title: "All Blogs", - Description: "Combined blog entries from all blogs.", - BlogLinks: getBlogLinks(), - Content: template.HTML(content.String()), - PrevLink: prevLink, - NextLink: nextLink, - }) -} - func getFileModTime(path string) (time.Time, error) { info, err := os.Stat(path) if err != nil { diff --git a/static/css/extras.css b/static/css/extras.css new file mode 100644 index 0000000..1c5b732 --- /dev/null +++ b/static/css/extras.css @@ -0,0 +1,26 @@ +#wrapper { + position: relative; + z-index: 1; +} + +.logo img { + width: 64px; + height: auto; +} + +.icon-security { + width: 48px; + height: 48px; + fill: white; + display: inline-block; + object-fit: contain; +} + +.icon-container { + display: flex; + align-items: center; + justify-content: center; + width: 48px; + height: 48px; + overflow: visible; +} \ No newline at end of file diff --git a/templates/download-linux.html b/templates/download-linux.html index 49093a0..4248763 100644 --- a/templates/download-linux.html +++ b/templates/download-linux.html @@ -16,16 +16,9 @@ - - - - + + + @@ -36,6 +29,10 @@
+ +
+ 🚧👷‍♂️ This site is under construction! Please check back later. 👷‍♀️🚧 +
@@ -126,13 +123,13 @@ sudo apk add --allow-untrusted spitfire-browser.apk
- - - - - - - + + + + + + + diff --git a/templates/download.html b/templates/download.html index 4b9b035..bcb1d80 100644 --- a/templates/download.html +++ b/templates/download.html @@ -16,9 +16,9 @@ - - - + + + @@ -72,6 +66,11 @@
+ +
+ 🚧👷‍♂️ This site is under construction! Please check back later. 👷‍♀️🚧 +
+
@@ -95,7 +94,7 @@ MacOS MacOS - + Linux Linux - - - - - - - + + + + + + + diff --git a/templates/index.html b/templates/index.html index e1361a5..8a1fa27 100644 --- a/templates/index.html +++ b/templates/index.html @@ -16,39 +16,11 @@ - - - - - + + + + + @@ -59,15 +31,20 @@
+ +
+ 🚧👷‍♂️ This site is under construction! Please check back later. 👷‍♀️🚧 +
+
@@ -91,8 +68,8 @@

Spitfire Browser is your gateway to a fast, secure, and elegant browsing experience. Built on Firefox, Spitfire includes essential features like ad blocking, enhanced security, and anonymous browsing with Warp search engine.

- - - - - - - + + + + + + + diff --git a/templates/news.html b/templates/news.html index 037d4c6..9e18cc3 100644 --- a/templates/news.html +++ b/templates/news.html @@ -16,16 +16,10 @@ - - - - + + + + @@ -36,30 +30,41 @@
+ +
+ 🚧👷‍♂️ This site is under construction! Please check back later. 👷‍♀️🚧 +
+
-