diff --git a/.air.toml b/.air.toml index f2cb1f4..aacdfcd 100644 --- a/.air.toml +++ b/.air.toml @@ -9,6 +9,7 @@ cmd = "go build -o ./tmp/main.exe ." delay = 1000 exclude_dir = [ "assets", + "static", "tmp", "vendor", "testdata", diff --git a/.vscode/settings.json b/.vscode/settings.json index 9fe1c00..294c171 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,8 @@ "PGPORT", "PGUSER", "regexes", + "stylesheet", + "tmpl", "webmail" ] } diff --git a/main.go b/main.go index c110333..41c6b41 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "fmt" + "html/template" "log" "net/http" @@ -10,11 +12,78 @@ import ( func main() { r := chi.NewRouter() + r.Use(middleware.RealIP) r.Use(middleware.Logger) - r.Get("/", func(w http.ResponseWriter, _ *http.Request) { - w.Write([]byte("welcome")) - }) + r.Use(middleware.Recoverer) + r.Use(middleware.Compress(5)) + r.Use(middleware.Heartbeat("/ping")) - log.Println("listening on http://localhost:8000/") + r.Get("/", IndexHandler) + r.Get("/api", ApiHandler) + r.Get("/about", AboutHandler) + r.Get("/donate", DonateHandler) + r.Get("/feeds", FeedsHandler) + + r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + + log.Println("Listening on http://localhost:8000/ to stop") http.ListenAndServe("127.0.0.1:8000", r) } + +type Data struct { + Title string + Description string + Keywords string + Author string + CanonicalURL string + FeedCount int + DatabaseSize int +} + +func (d *Data) GetDatabaseSizeAndFeedCount() { + // Set the database size to 0 + d.DatabaseSize = 0 + + // Set the feed count to 0 + d.FeedCount = 0 +} + +func renderPage(w http.ResponseWriter, title, description, keywords, author, url, templateName string) { + data := Data{ + Title: title, + Description: description, + Keywords: keywords, + Author: author, + CanonicalURL: url, + FeedCount: 0, + DatabaseSize: 0, + } + data.GetDatabaseSizeAndFeedCount() + + t, err := template.ParseFiles("templates/base.tmpl", fmt.Sprintf("templates/%s.tmpl", templateName)) + if err != nil { + http.Error(w, fmt.Sprintf("Internal Server Error: %v", err), http.StatusInternalServerError) + return + } + t.ExecuteTemplate(w, "base", data) +} + +func IndexHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "FeedVault", "FeedVault - A feed archive", "RSS, Atom, Feed, Archive", "TheLovinator", "http://localhost:8000/", "index") + +} + +func ApiHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "API", "API Page", "api, page", "TheLovinator", "http://localhost:8000/api", "api") +} +func AboutHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "About", "About Page", "about, page", "TheLovinator", "http://localhost:8000/about", "about") +} + +func DonateHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "Donate", "Donate Page", "donate, page", "TheLovinator", "http://localhost:8000/donate", "donate") +} + +func FeedsHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "Feeds", "Feeds Page", "feeds, page", "TheLovinator", "http://localhost:8000/feeds", "feeds") +} diff --git a/templates/about.tmpl b/templates/about.tmpl new file mode 100644 index 0000000..47be9d1 --- /dev/null +++ b/templates/about.tmpl @@ -0,0 +1,16 @@ +{{ define "content" }} +

Feeds to archive

+

+ Input the URLs of the feeds you wish to archive below. You can add as many as needed, and access them through the website or API. Alternatively, include links to .opml files, and the feeds within will be archived. +

+
+ + +
+
+

You can also upload .opml files containing the feeds you wish to archive:

+
+ + +
+{{ end }} diff --git a/templates/api.html b/templates/api.html deleted file mode 100644 index a8159bd..0000000 --- a/templates/api.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base.html" %} -{% block title %}Feeds{% endblock %} -{% block description %}FeedVault - A feed archive{% endblock %} -{% block keywords %}RSS, Atom, Feed, Archive{% endblock %} -{% block content %} -

API documentation

-

Here be dragons.

-{% endblock %} diff --git a/templates/api.tmpl b/templates/api.tmpl new file mode 100644 index 0000000..f504e27 --- /dev/null +++ b/templates/api.tmpl @@ -0,0 +1,4 @@ +{{ define "content" }} +

API documentation

+

Here be dragons.

+{{ end }} diff --git a/templates/base.html b/templates/base.html deleted file mode 100644 index 74a03f7..0000000 --- a/templates/base.html +++ /dev/null @@ -1,75 +0,0 @@ -{% load static %} - - - - - - - - {% block title %}FeedVault{% endblock %} - - {% if canonical_url %}{% endif %} - - - {% if messages %} - -
- {% endif %} - -

- FeedVault -

-
-
-
- Archive of web feeds. {{ feed_count }} feeds. ~{{ database_size|floatformat:2 }} MB. -
-
- -
- - -
-
-
- -
- {% block content %}{% endblock %} -
- - - diff --git a/templates/base.tmpl b/templates/base.tmpl new file mode 100644 index 0000000..1b0bf29 --- /dev/null +++ b/templates/base.tmpl @@ -0,0 +1,70 @@ +{{ define "base" }} + + + + + + + {{ if .Description }}{{ end }} + {{ if .Keywords }}{{ end }} + {{ if .Author }}{{ end }} + {{ if .CanonicalURL }}{{ end }} + {{ .Title }} + + + + + + +

+ FeedVault +

+
+
+
+ Archive of web feeds. {{ .FeedCount }} feeds. ~{{ .DatabaseSize }} MB. +
+
+ +
+ + +
+
+
+ +
+ {{ block "content" . }}{{ end }} +
+ + + +{{ end }} diff --git a/templates/donate.html b/templates/donate.html deleted file mode 100644 index 2824830..0000000 --- a/templates/donate.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends "base.html" %} -{% block title %}Donate{% endblock %} -{% block description %}FeedVault - A feed archive{% endblock %} -{% block keywords %}RSS, Atom, Feed, Archive, Donate{% endblock %} -{% block content %} -

Donate

-

- tl;dr: GitHub Sponsors -

-

- FeedVault is a free service, and will always be free. However, if you wish to support the project, you can do so by donating to the developer. -

-

What will the money be used for?

-

- The money will be used to pay for the server costs, domain name, and other expenses related to running the service. -

-

How much does it cost to run FeedVault?

-

Domain name: 12 € / 13 $ / 10 £ per year

-

How can I donate?

-

- The preferred method of donating is through GitHub Sponsors due to no fees being taken. However, you can also donate through PayPal. -

-

Crypto

-

- You can also donate through cryptocurrency. The addresses are listed below. If you wish to donate through a cryptocurrency not listed below, please contact me. -

-

Bitcoin

-

- bc1qdgm09zzxllzh4m2edyyx7khwhw5mjrwe0d2dws -

-

Monero

-

- 83Hft9zJKPNgMrLAZQ7hhTBeJ6v9bJFJ7P7xfWLRDCiyg4QDwstnjc79Fdn5Y8uY5Hfddj52ok9JF8uisU9UXDJjT4Msevx -

-

Thank you!

-

Thank you for supporting FeedVault!

-{% endblock %} diff --git a/templates/donate.tmpl b/templates/donate.tmpl new file mode 100644 index 0000000..820d838 --- /dev/null +++ b/templates/donate.tmpl @@ -0,0 +1,33 @@ +{{ define "content" }} +

Donate

+

+ tl;dr: GitHub Sponsors +

+

+ FeedVault is a free service, and will always be free. However, if you wish to support the project, you can do so by donating to the developer. +

+

What will the money be used for?

+

+ The money will be used to pay for the server costs, domain name, and other expenses related to running the service. +

+

How much does it cost to run FeedVault?

+

Domain name: 12 € / 13 $ / 10 £ per year

+

How can I donate?

+

+ The preferred method of donating is through GitHub Sponsors due to no fees being taken. However, you can also donate through PayPal. +

+

Crypto

+

+ You can also donate through cryptocurrency. The addresses are listed below. If you wish to donate through a cryptocurrency not listed below, please contact me. +

+

Bitcoin

+

+ bc1qdgm09zzxllzh4m2edyyx7khwhw5mjrwe0d2dws +

+

Monero

+

+ 83Hft9zJKPNgMrLAZQ7hhTBeJ6v9bJFJ7P7xfWLRDCiyg4QDwstnjc79Fdn5Y8uY5Hfddj52ok9JF8uisU9UXDJjT4Msevx +

+

Thank you!

+

Thank you for supporting FeedVault!

+{{ end }} diff --git a/templates/feeds.html b/templates/feeds.html deleted file mode 100644 index ce0185a..0000000 --- a/templates/feeds.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "base.html" %} -{% block title %}Feeds{% endblock %} -{% block description %}FeedVault - A feed archive{% endblock %} -{% block keywords %}RSS, Atom, Feed, Archive{% endblock %} -{% block content %} - {% for feed in feeds %} -
-

- - {% if feed.title %} - {{ feed.title }} - {% else %} - {{ feed.url }} - {% endif %} - -

-

- {% if feed.created %}Added {{ feed.created|date:"F j, Y" }}{% endif %} - {% if feed.last_updated %} - {% if feed.created %}·{% endif %} - Last updated {{ feed.last_updated|date:"F j, Y" }} - {% endif %} -

-
- {% empty %} -

No feeds found.

- {% endfor %} -{% endblock %} diff --git a/templates/feeds.tmpl b/templates/feeds.tmpl new file mode 100644 index 0000000..5a4bd9d --- /dev/null +++ b/templates/feeds.tmpl @@ -0,0 +1,3 @@ +{{ define "content" }} + Feeds +{{ end }} diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 4e2625a..0000000 --- a/templates/index.html +++ /dev/null @@ -1,103 +0,0 @@ -{% extends "base.html" %} -{% block title %}FeedVault{% endblock %} -{% block description %}FeedVault{% endblock %} -{% block keywords %}RSS, Atom, Feed, Archive{% endblock %} -{% block content %} -

Feeds to archive

-

- Input the URLs of the feeds you wish to archive below. You can add as many as needed, and access them through the website or API. Alternatively, include links to .opml files, and the feeds within will be archived. -

-
- {% csrf_token %} - - -
-
-

You can also upload .opml files containing the feeds you wish to archive:

-
- {% csrf_token %} - - -
-
-
- What are web feeds? -

- Web feeds let you "subscribe" to website content, notifying you of new updates. Feeds are typically in RSS or Atom formats, recognizable by this icon: - Feed icon -
-
- Learn more about web feeds on Wikipedia. -

-
-
-
- What is FeedVault? -

- FeedVault is a platform crafted to gather, arrange, and preserve information sourced from RSS feeds. It utilizes the feedparser library by Kurt McKee to parse XML data, storing pertinent details in a Django-managed PostgreSQL database. -

-
-
-
- Why archive feeds? -

- The web is constantly changing. Websites are redesigned, content is removed, and links are broken. By archiving feeds, we can preserve the content that is published on the web. -

-
-
-
- How does it work? -

-

-

-
-
-
- How can I access the archived feeds? -

-

-

-
-
- How can I contribute? -

-

-

-
-{% endblock %} diff --git a/templates/index.tmpl b/templates/index.tmpl new file mode 100644 index 0000000..ba2317b --- /dev/null +++ b/templates/index.tmpl @@ -0,0 +1,18 @@ + +{{template "base"}} +{{ define "content" }} +

Feeds to archive

+

+ Input the URLs of the feeds you wish to archive below. You can add as many as needed, and access them through the website or API. Alternatively, include links to .opml files, and the feeds within will be archived. +

+
+ + +
+
+

You can also upload .opml files containing the feeds you wish to archive:

+
+ + +
+{{ end }}