mirror of
https://github.com/thebaer/tildes.git
synced 2018-07-20 07:15:21 +00:00
Remove tildelog
This commit is contained in:
parent
3a12217262
commit
d81f6a1c13
29
README.md
29
README.md
@ -4,34 +4,7 @@
|
||||
Various scripts and programs for the tildeverse.
|
||||
|
||||
## tildelog
|
||||
Use **tildelog** to easily create a simple log for your tilde. [Create new posts](https://github.com/thebaer/tildes/tree/master/tildelog/entries#tildelog-entries) in the `tildelog/entries/` folder, then run this:
|
||||
|
||||
```bash
|
||||
cd tildelog
|
||||
go build tildelog.go
|
||||
./tildelog -template mytildelog
|
||||
```
|
||||
|
||||
This will use any template in `tildelog/templates/` defined with _mytildelog_ (see below) to generate your full tildelog page.
|
||||
|
||||
#### templates
|
||||
|
||||
Your template should look like this.
|
||||
|
||||
```html
|
||||
{{define "mytildelog"}}
|
||||
<html>
|
||||
<head>
|
||||
<title>My ~log!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>~log</h1>
|
||||
<p>Welcome to my ~log.</p>
|
||||
{{template "log" .}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
```
|
||||
tildelog has moved to **[squigglelog](https://github.com/thebaer/squigglelog)**.
|
||||
|
||||
## code
|
||||
Use **code** to generate a list of files contained within a given directory under their home folder. This was originally made to see who had a **Code** directory (this is the default), but you can specify whatever common directory you'd like to find. Do this:
|
||||
|
@ -1,4 +0,0 @@
|
||||
tildelog entries
|
||||
================
|
||||
|
||||
Create each entry as a new file here. Naming scheme: **YYYYMMDD**. Add formatting with HTML.
|
@ -1,4 +0,0 @@
|
||||
tildelog output
|
||||
===============
|
||||
|
||||
Generated HTML will end up in this folder.
|
@ -1,9 +0,0 @@
|
||||
{{define "log"}}
|
||||
<div id="tildelog">
|
||||
{{range .}}
|
||||
<hr />
|
||||
<h3>{{.Date}}</h3>
|
||||
<p>{{printf "%s" .Body}}</p>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
@ -1,111 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
"strconv"
|
||||
"text/template"
|
||||
"os"
|
||||
"bufio"
|
||||
"regexp"
|
||||
"flag"
|
||||
)
|
||||
|
||||
const entriesPath = "./entries/"
|
||||
const templatesPath = "./templates/"
|
||||
const outputPath = "./html/"
|
||||
|
||||
type Entry struct {
|
||||
Date string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func loadEntry(rawDate string) (*Entry, error) {
|
||||
filename := entriesPath + rawDate
|
||||
body, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get raw date parts for formatting
|
||||
year := rawDate[:4]
|
||||
month, moErr := strconv.Atoi(rawDate[4:6])
|
||||
if moErr != nil {
|
||||
return nil, moErr
|
||||
}
|
||||
date, dateErr := strconv.Atoi(rawDate[6:8])
|
||||
if dateErr != nil {
|
||||
return nil, dateErr
|
||||
}
|
||||
|
||||
formattedDate := fmt.Sprintf("%d %s %s", date, time.Month(month).String(), year)
|
||||
|
||||
return &Entry{Date: formattedDate, Body: body}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println()
|
||||
fmt.Println(" ~log generator v1.0")
|
||||
fmt.Println()
|
||||
|
||||
// Get any arguments
|
||||
templateFilePtr := flag.String("template", "log", "Tildelog template file (defined name).")
|
||||
flag.Parse()
|
||||
|
||||
entryFiles := getEntries()
|
||||
entries := make([]Entry, len(*entryFiles))
|
||||
i := 0
|
||||
for _, file := range *entryFiles {
|
||||
entry, err := loadEntry(file)
|
||||
if err != nil {
|
||||
fmt.Printf("Error, skipping entry %s: %s\n", file, err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Adding entry %s...\n", file)
|
||||
entries[i] = *entry
|
||||
i++
|
||||
}
|
||||
|
||||
fmt.Printf("Using template %s...\n", *templateFilePtr)
|
||||
|
||||
generateLog(entries, *templateFilePtr)
|
||||
|
||||
fmt.Printf("Finished! Saved to %slog.html\n", outputPath)
|
||||
}
|
||||
|
||||
var validFileFormat = regexp.MustCompile("^[0-9]{8}$")
|
||||
|
||||
func getEntries() *[]string {
|
||||
files, _ := ioutil.ReadDir(entriesPath)
|
||||
fileList := make([]string, len(files))
|
||||
fileCount := 0
|
||||
// Traverse file list in reverse, i.e. newest to oldest
|
||||
for i := len(files)-1; i >= 0; i-- {
|
||||
file := files[i]
|
||||
if validFileFormat.Match([]byte(file.Name())) {
|
||||
fileList[fileCount] = file.Name()
|
||||
fileCount++
|
||||
}
|
||||
}
|
||||
fileList = fileList[:fileCount]
|
||||
return &fileList
|
||||
}
|
||||
|
||||
func generateLog(entries []Entry, templateFile string) {
|
||||
file, err := os.Create(outputPath + "log.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
writer := bufio.NewWriter(file)
|
||||
template, err := template.ParseGlob(templatesPath + "*.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
template.ExecuteTemplate(writer, templateFile, entries)
|
||||
writer.Flush()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user