aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Fries <github-feldkueche@xenoworld.de>2017-01-25 18:34:35 +0100
committerClemens Fries <github-feldkueche@xenoworld.de>2017-01-25 18:34:35 +0100
commitbc3c0a434cc337f4106c05c1af8b5be15df2cfe1 (patch)
tree70579f6774ed67db312763ea46ef72555fa99aab
parentb121453110c9bda1e34bde1df3119ec85a68c423 (diff)
Le Code DumpHEADmaster
-rw-r--r--feldküche.go101
-rw-r--r--html/feldküche.html26
-rw-r--r--html/feldküche_posts.html13
3 files changed, 140 insertions, 0 deletions
diff --git a/feldküche.go b/feldküche.go
new file mode 100644
index 0000000..ea2a005
--- /dev/null
+++ b/feldküche.go
@@ -0,0 +1,101 @@
+package main
+
+import (
+ "encoding/xml"
+ "net/http"
+ "os"
+ "strconv"
+ "text/template"
+ "strings"
+ "path/filepath"
+ img "image"
+)
+
+type Enclosure struct {
+ Url string `xml:"url,attr"`
+}
+
+func (e *Enclosure) BaseName() string {
+ index := strings.LastIndex(e.Url, "/")
+
+ if index == -1 {
+ return ""
+ }
+
+ return e.Url[index+1:]
+}
+
+func (e *Enclosure) ImageSize() (img.Point) {
+ filename := "./enclosures" + e.BaseName()
+
+ f, err := os.Open(filename)
+
+ if err != nil {
+ return img.Point{}
+ }
+
+ i, _, err := img.Decode(f)
+
+ if err != nil {
+ return img.Point{}
+ }
+
+ return i.Bounds().Max
+}
+
+type Item struct {
+ XMLName xml.Name `xml:"item"`
+ Enclosure Enclosure `xml:"enclosure"`
+ Title string `xml:"title"`
+ Description string `xml:"description"`
+ PubDate string `xml:"pubDate"`
+ Link string `xml:"link"`
+}
+
+type Channel struct {
+ Items []Item `xml:"item"`
+}
+
+type Rss struct {
+ XMLName xml.Name `xml:"rss"`
+ Channel Channel `xml:"channel"`
+}
+
+var rss Rss
+
+func index(w http.ResponseWriter, r *http.Request) {
+ t, _ := template.ParseFiles("./html/feldküche.html")
+ t.Execute(w, nil)
+}
+
+func posts(w http.ResponseWriter, r *http.Request) {
+ offset, _ := strconv.Atoi(r.URL.Path[len("/posts/"):])
+ t, _ := template.ParseFiles("./html/feldküche_posts.html")
+ p := rss.Channel.Items[offset*10 : offset*10+10]
+ t.Execute(w, p)
+}
+
+func image(w http.ResponseWriter, r *http.Request) {
+ // TODO: Is this secure?
+ filename := r.URL.Path[len("/image/"):]
+ basename := filepath.Base(filepath.Clean(filename));
+
+ if basename == "." {
+ return
+ }
+
+ http.ServeFile(w, r, "./enclosures/" + basename)
+}
+
+func main() {
+ file, _ := os.Open("backup.rss")
+
+ decoder := xml.NewDecoder(file)
+
+ decoder.Decode(&rss)
+
+ http.HandleFunc("/posts/", posts)
+ http.HandleFunc("/image/", image)
+ http.HandleFunc("/", index)
+ http.ListenAndServe(":8080", nil)
+}
diff --git a/html/feldküche.html b/html/feldküche.html
new file mode 100644
index 0000000..f64ed88
--- /dev/null
+++ b/html/feldküche.html
@@ -0,0 +1,26 @@
+<html>
+<head>
+ <title></title>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
+
+ <script>
+ var offset = 0;
+
+ function moar(p) {
+ $.ajax({url: "/posts/" + offset, success: function(data) {
+ $("#content").append("<hr/>" + data);
+ }
+ });
+ offset += 1;
+ }
+
+ $(moar);
+
+ $(window).click(moar);
+ </script>
+
+</head>
+<body>
+ <div id="content"></div>
+</body>
+</html>
diff --git a/html/feldküche_posts.html b/html/feldküche_posts.html
new file mode 100644
index 0000000..c0ad322
--- /dev/null
+++ b/html/feldküche_posts.html
@@ -0,0 +1,13 @@
+{{range .}}
+ <div class="post">
+ <div class="title">{{.Enclosure.ImageSize}}</div>
+ <div class="title">{{.Enclosure.BaseName}}</div>
+ <div class="title">{{.Title}}</div>
+ <div class="pubDate">{{.PubDate}}</div>
+ <div class="description">
+ <!-- <img src="{{.Enclosure.Url}}" /> -->
+ <img src="/image/{{.Enclosure.BaseName}}" />
+ </div>
+ <a class="link" href="{{.Link}}">link</a>
+ </div>
+{{end}}