Skip to content

Commit ee657dc

Browse files
committed
Create Go server to render README.md on a website
1 parent bc110da commit ee657dc

File tree

7 files changed

+123
-1
lines changed

7 files changed

+123
-1
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Output from Awesome IBM Cloud
15+
public/index.html
16+
awesome-ibmcloud
17+
18+
# Vendor folder
19+
vendor/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div align="center">
2-
<img width="559" height="388" src="media/logo.png" alt="Awesome IBM Cloud">
2+
<img width="559" height="388" src="https://github.com/victorshinya/awesome-ibmcloud/blob/master/media/logo.png?raw=true" alt="Awesome IBM Cloud">
33
</div>
44

55
# Awesome IBM Cloud

glide.lock

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package: github.com/victorshinya/awesome-ibmcloud
2+
import:
3+
- package: github.com/gorilla/mux
4+
- package: github.com/shurcooL/github_flavored_markdown

main.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"os"
7+
"text/template"
8+
9+
"github.com/gorilla/mux"
10+
gfm "github.com/shurcooL/github_flavored_markdown"
11+
)
12+
13+
const (
14+
readmePath = "./README.md"
15+
tmplPath = "./public/tmpl.html"
16+
indexPath = "./public/index.html"
17+
)
18+
19+
type content struct {
20+
Body string
21+
}
22+
23+
func main() {
24+
r := mux.NewRouter()
25+
r.HandleFunc("/generate", func(w http.ResponseWriter, r *http.Request) {
26+
input, _ := ioutil.ReadFile(readmePath)
27+
body := string(gfm.Markdown(input))
28+
c := &content{Body: body}
29+
t := template.Must(template.ParseFiles(tmplPath))
30+
f, _ := os.Create(indexPath)
31+
t.Execute(f, c)
32+
w.Write([]byte("Page generated"))
33+
})
34+
fs := http.FileServer(http.Dir("public"))
35+
r.Handle("/", fs)
36+
37+
http.ListenAndServe(":8080", r)
38+
}

manifest.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
applications:
3+
- name: awesome-ibmcloud
4+
buildpack: https://github.com/cloudfoundry/go-buildpack
5+
path: .
6+
memory: 128M
7+
instances: 1
8+
command: awesome-ibmcloud
9+
env:
10+
GOVERSION: go1.10
11+
GOPACKAGENAME: github.com/victorshinya/awesome-ibmcloud

public/tmpl.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Awesome IBM Cloud</title>
8+
</head>
9+
<body>
10+
<div class="content">
11+
{{.Body}}
12+
</div>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)