mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-19 17:21:10 +01:00
Working on frontend of CMS
Starting to work on basic frontend layout. Added new /json route for fetching RSS as JSON file.
This commit is contained in:
parent
7c3cb34587
commit
0ffefbf55e
|
@ -2,11 +2,43 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>White Rabbit Podcasting CMS</title>
|
||||
<title>CMS Loading</title>
|
||||
<link rel="stylesheet" href="/assets/styles.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>White Rabbit Podcasting CMS</h1>
|
||||
<p>Git Galaxy Podcast</p>
|
||||
<h1 id="title" class="title">Loading</h1>
|
||||
|
||||
<div id="podcasts">
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
get("/json", function(data){
|
||||
json = JSON.parse(data);
|
||||
document.title = json.title;
|
||||
document.getElementById("title").innerHTML = json.title;
|
||||
|
||||
for (i=0;i<json.items.length; i++){
|
||||
var div = document.createElement('div');
|
||||
div.className = 'podcast';
|
||||
// Todo: Add audio element (must modify feeds fork first!)
|
||||
div.innerHTML = '<h3>'+json.items[i].title+'</h3><p>'+json.items[i].summary+'</p>';
|
||||
|
||||
var element = document.getElementById("podcasts");
|
||||
element.appendChild(div);
|
||||
}
|
||||
});
|
||||
|
||||
function get(url, callback) {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.onreadystatechange = function() {
|
||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
|
||||
callback(xmlHttp.responseText);
|
||||
}
|
||||
xmlHttp.open("GET", url, true);
|
||||
xmlHttp.send(null);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
|
@ -1,3 +1,4 @@
|
|||
body {
|
||||
background-color: blue;
|
||||
background-color: #f9f9f9;
|
||||
color: #5b9aff;
|
||||
}
|
21
feed.json
Normal file
21
feed.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"version": "https://jsonfeed.org/version/1",
|
||||
"title": "Git Galaxy Stargazers",
|
||||
"home_page_url": "https://gitgalaxy.com",
|
||||
"description": "discussion about open source projects",
|
||||
"author": {
|
||||
"name": "Gabriel Simmer"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"id": "",
|
||||
"url": "https://gitgalaxy.com/podcast",
|
||||
"title": "TESTING-WORLD",
|
||||
"summary": "Hello, World!",
|
||||
"date_published": "2017-07-12T00:00:00Z",
|
||||
"author": {
|
||||
"name": "Gabriel Simmer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
4
feed.rss
4
feed.rss
|
@ -4,9 +4,9 @@
|
|||
<link>https://gitgalaxy.com</link>
|
||||
<description>discussion about open source projects</description>
|
||||
<managingEditor>gabriel@gitgalaxy.com (Gabriel Simmer)</managingEditor>
|
||||
<pubDate>Tue, 13 Jun 2017 23:03:07 -0700</pubDate>
|
||||
<pubDate>Sun, 18 Jun 2017 13:35:51 -0700</pubDate>
|
||||
<image>
|
||||
<url>https://static.gitgalaxy.com/podcast_image.png</url>
|
||||
<url>https://podcast.gitgalaxy.com/assets/podcast_image.png</url>
|
||||
<title></title>
|
||||
<link></link>
|
||||
</image>
|
||||
|
|
160
generate_rss.go
160
generate_rss.go
|
@ -1,84 +1,92 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"time"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"github.com/gmemstr/feeds"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/gmemstr/feeds"
|
||||
)
|
||||
func watch(){
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
log.Println("event:", event)
|
||||
if event.Op&fsnotify.Write == fsnotify.Write {
|
||||
log.Println("modified file:", event.Name)
|
||||
generate_rss()
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
log.Println("error:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = watcher.Add("podcasts/")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<-done
|
||||
|
||||
func watch() {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
log.Println("event:", event)
|
||||
if event.Op&fsnotify.Write == fsnotify.Write {
|
||||
log.Println("modified file:", event.Name)
|
||||
generate_rss()
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
log.Println("error:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = watcher.Add("podcasts/")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<-done
|
||||
}
|
||||
|
||||
func generate_rss(){
|
||||
now := time.Now()
|
||||
files, err := ioutil.ReadDir("podcasts")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
func generate_rss() {
|
||||
now := time.Now()
|
||||
files, err := ioutil.ReadDir("podcasts")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
feed := &feeds.Feed{
|
||||
Title: "Git Galaxy Stargazers",
|
||||
Link: &feeds.Link{Href: "https://gitgalaxy.com"},
|
||||
Description: "discussion about open source projects",
|
||||
Author: &feeds.Author{Name:"Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
|
||||
Created: now,
|
||||
Image: &feeds.Image{Url: "https://static.gitgalaxy.com/podcast_image.png"},
|
||||
}
|
||||
feed := &feeds.Feed{
|
||||
Title: "Git Galaxy Stargazers",
|
||||
Link: &feeds.Link{Href: "https://gitgalaxy.com"},
|
||||
Description: "discussion about open source projects",
|
||||
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
|
||||
Created: now,
|
||||
Image: &feeds.Image{Url: "https://podcast.gitgalaxy.com/assets/podcast_image.png"},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
s := strings.Split(file.Name(), "_")
|
||||
t := strings.Split(s[1], ".")
|
||||
title := t[0]
|
||||
date, err := time.Parse("2006-01-02",s[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
feed.Items = []*feeds.Item{
|
||||
&feeds.Item{
|
||||
Title: title,
|
||||
Link: &feeds.Link{Href: "https://gitgalaxy.com/podcast"},
|
||||
Enclosure: &feeds.Enclosure{Url: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
|
||||
Description: "Hello, World!",
|
||||
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
|
||||
Created: date,
|
||||
},
|
||||
}
|
||||
}
|
||||
rss, err := feed.ToRss()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(rss)
|
||||
rss_byte := []byte(rss)
|
||||
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
||||
}
|
||||
for _, file := range files {
|
||||
s := strings.Split(file.Name(), "_")
|
||||
t := strings.Split(s[1], ".")
|
||||
title := t[0]
|
||||
date, err := time.Parse("2006-01-02", s[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
feed.Items = []*feeds.Item{
|
||||
&feeds.Item{
|
||||
Title: title,
|
||||
Link: &feeds.Link{Href: "https://gitgalaxy.com/podcast"},
|
||||
Enclosure: &feeds.Enclosure{Url: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
|
||||
Description: "Hello, World!",
|
||||
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
|
||||
Created: date,
|
||||
},
|
||||
}
|
||||
}
|
||||
rss, err := feed.ToRss()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
json, err := feed.ToJSON()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(rss)
|
||||
rss_byte := []byte(rss)
|
||||
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
||||
json_byte := []byte(json)
|
||||
ioutil.WriteFile("feed.json", json_byte, 0644)
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
hi
|
||||
hello
|
75
webserver.go
75
webserver.go
|
@ -1,46 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func RssHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/rss+xml")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
data, err := ioutil.ReadFile("feed.rss")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Header().Set("Content-Length", fmt.Sprint(len(data)))
|
||||
fmt.Fprint(w, string(data))
|
||||
w.Header().Set("Content-Type", "application/rss+xml")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
data, err := ioutil.ReadFile("feed.rss")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Header().Set("Content-Length", fmt.Sprint(len(data)))
|
||||
fmt.Fprint(w, string(data))
|
||||
}
|
||||
|
||||
func JsonHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
data, err := ioutil.ReadFile("feed.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Header().Set("Content-Length", fmt.Sprint(len(data)))
|
||||
fmt.Fprint(w, string(data))
|
||||
}
|
||||
|
||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := ioutil.ReadFile("assets/index.html")
|
||||
data, err := ioutil.ReadFile("assets/index.html")
|
||||
|
||||
if err == nil {
|
||||
w.Write(data)
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("404 Something went wrong - " + http.StatusText(404)))
|
||||
}
|
||||
}
|
||||
|
||||
func DownloadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Gorilla!\n"))
|
||||
if err == nil {
|
||||
w.Write(data)
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("404 Something went wrong - " + http.StatusText(404)))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
go watch()
|
||||
r := mux.NewRouter()
|
||||
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/static"))))
|
||||
r.HandleFunc("/", HomeHandler)
|
||||
r.HandleFunc("/download/{episode}", DownloadHandler)
|
||||
r.HandleFunc("/rss", RssHandler)
|
||||
http.Handle("/", r)
|
||||
log.Fatal(http.ListenAndServe(":8000", r))
|
||||
}
|
||||
go watch()
|
||||
r := mux.NewRouter()
|
||||
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/static"))))
|
||||
r.PathPrefix("/download/").Handler(http.StripPrefix("/download/", http.FileServer(http.Dir("podcasts"))))
|
||||
r.HandleFunc("/", HomeHandler)
|
||||
r.HandleFunc("/rss", RssHandler)
|
||||
r.HandleFunc("/json", JsonHandler)
|
||||
http.Handle("/", r)
|
||||
log.Fatal(http.ListenAndServe(":8000", r))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue