extract page title

master
nate smith 2019-09-06 18:37:58 -05:00
parent 70ab5b10d9
commit 7678d529b4
1 changed files with 13 additions and 3 deletions

16
main.go
View File

@ -14,16 +14,18 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"time" "time"
) )
const default_html_filename = "/etc/skel/public_html/index.html" const defaultHTMLFilename = "/etc/skel/public_html/index.html"
const description = `an intentional digital community for creating and sharing const description = `an intentional digital community for creating and sharing
works of art, peer education, and technological anachronism. we are works of art, peer education, and technological anachronism. we are
non-commercial, donation supported, and committed to rejecting false non-commercial, donation supported, and committed to rejecting false
@ -77,8 +79,16 @@ func news() []NewsEntry {
} }
func pageTitleFor(username string) string { func pageTitleFor(username string) string {
// TODO pageTitleRe := regexp.MustCompile(`<title[^>]*>(.*)</title>`)
return "TODO" indexPath := path.Join(homesDir(), username, "public_html", "index.html")
content, err := ioutil.ReadFile(indexPath)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read %q: %v\n", indexPath, err)
return ""
}
title := pageTitleRe.FindString(string(content))
return title
} }
func systemUsers() map[string]bool { func systemUsers() map[string]bool {