1
0
mirror of https://github.com/thebaer/tildes.git synced 2018-07-20 07:15:21 +00:00

Manual configuration for directory to scan

This commit is contained in:
Matt Baer 2015-01-26 00:03:27 -05:00
parent 93b265c2e1
commit f8558e3b30
2 changed files with 11 additions and 6 deletions

13
code.go
View File

@ -10,6 +10,10 @@ import (
"text/template" "text/template"
) )
const (
searchDir = "Code"
)
func main() { func main() {
fmt.Println("Starting...") fmt.Println("Starting...")
generate(findProjects()) generate(findProjects())
@ -26,7 +30,7 @@ type Project struct {
} }
func findProjects() map[string]User { func findProjects() map[string]User {
files, _ := filepath.Glob("/home/*/Code/*") files, _ := filepath.Glob("/home/*/" + searchDir + "/*")
users := make(map[string]User) users := make(map[string]User)
for _, path := range files { for _, path := range files {
@ -42,7 +46,7 @@ func findProjects() map[string]User {
proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1)} proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1)}
u, exists := users[uname] u, exists := users[uname]
if !exists { if !exists {
fmt.Printf("Found Code for ~%s.\n", uname) fmt.Printf("Found %s for ~%s.\n", searchDir, uname)
projs := []Project{*proj} projs := []Project{*proj}
u = User{Name: uname, Projects: projs} u = User{Name: uname, Projects: projs}
} else { } else {
@ -54,6 +58,7 @@ func findProjects() map[string]User {
} }
type Page struct { type Page struct {
FolderName string
Host string Host string
Users map[string]User Users map[string]User
Updated string Updated string
@ -68,7 +73,7 @@ func graphicalName(n string) string {
func generate(users map[string]User) { func generate(users map[string]User) {
fmt.Println("Generating page.") fmt.Println("Generating page.")
f, err := os.Create(os.Getenv("HOME") + "/public_html/code.html") f, err := os.Create(os.Getenv("HOME") + "/public_html/" + strings.ToLower(searchDir) + ".html")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -88,7 +93,7 @@ func generate(users map[string]User) {
updated := curTime.Format(time.RFC3339) updated := curTime.Format(time.RFC3339)
// Generate the page // Generate the page
page := &Page{Host: graphicalName(host), UpdatedForHumans: updatedReadable, Updated: updated, Users: users} page := &Page{FolderName: searchDir, Host: graphicalName(host), UpdatedForHumans: updatedReadable, Updated: updated, Users: users}
template.ExecuteTemplate(w, "code", page) template.ExecuteTemplate(w, "code", page)
w.Flush() w.Flush()

View File

@ -2,14 +2,14 @@
<html> <html>
<head> <head>
<title>Code on {{.Host}}</title> <title>{{.FolderName}} on {{.Host}}</title>
<link type="text/css" rel="stylesheet" href="tilde.css" /> <link type="text/css" rel="stylesheet" href="tilde.css" />
</head> </head>
<body id="hello"> <body id="hello">
<h1>Code on {{.Host}}</h1> <h1>{{.FolderName}} on {{.Host}}</h1>
<p>Last Updated: <time datetime="{{.Updated}}">{{.UpdatedForHumans}}</time></p> <p>Last Updated: <time datetime="{{.Updated}}">{{.UpdatedForHumans}}</time></p>
{{range .Users}} {{range .Users}}